Skip to content

Commit

Permalink
ci: ajout pipeline sur tag
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerPixel committed Feb 6, 2024
1 parent 5e1c2dc commit f7e89a5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 8 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: CI devops 2023
name: Main pipeline

on:
#to begin you want to launch this job in main and develop
push:
branches: #TODO
branches:
- main
pull_request:

jobs:
Expand All @@ -28,11 +30,12 @@ jobs:
run: mvn -B verify sonar:sonar -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}

# define job to build and publish docker image
build-and-push-docker-image:
build-and-push-docker-image-nightly:
needs: test-backend
# run only when code is compiling and tests are passing
runs-on: ubuntu-22.04

env:
DOCKERHUB_TAG: ${{ github.ref_name }}
# steps to perform in job
steps:
- name: Checkout code
Expand All @@ -50,15 +53,15 @@ jobs:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.api
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/api:latest
tags: ${{secrets.DOCKERHUB_USERNAME}}/api:$DOCKERHUB_TAG

- name: Build image and push database
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.db
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/database:latest
tags: ${{secrets.DOCKERHUB_USERNAME}}/database:$DOCKERHUB_TAG


- name: Build image and push httpd
Expand All @@ -67,4 +70,4 @@ jobs:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.http
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/httpd:latest
tags: ${{secrets.DOCKERHUB_USERNAME}}/httpd:$DOCKERHUB_TAG
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

name: Release pipeline
jobs:
test-backend:
runs-on: ubuntu-22.04
steps:
#checkout your github code using actions/[email protected]
- uses: actions/[email protected]

#do the same with another action (actions/setup-java@v3) that enable to setup jdk 17
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: "temurin" # See 'Supported distributions' for available options
java-version: "21"
#finally build your app with the latest command
- name: Build and test with Maven
working-directory: backend-api
run: mvn clean verify

- name: Send to sonarcloud for static analysis
working-directory: backend-api
run: mvn -B verify sonar:sonar -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}

# define job to build and publish docker image
build-and-push-docker-image-release:
needs: test-backend
# run only when code is compiling and tests are passing
runs-on: ubuntu-22.04
env:
DOCKERHUB_TAG: ${{ github.ref_name }}
# steps to perform in job
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build image and push backend
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.api
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/api:$DOCKERHUB_TAG

- name: Build image and push database
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.db
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/database:$DOCKERHUB_TAG


- name: Build image and push httpd
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
file: ./Dockerfile.http
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{secrets.DOCKERHUB_USERNAME}}/httpd:$DOCKERHUB_TAG
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,19 @@ services:
# We declare our app-network here
networks:
app-network:
```
```
## Day 2 - Github Actions
## Setup GitHub Actions
### Unit tests? Component tests?
Unit tests are meant to test small parts of a class logic, such as a function, or a constructor.
Component tests (or integrations test), are for testing the logic of the application itself, so it can test more functions and multiple classes and how they interact with each others.
### What are testcontainers ?
Testcontainers is a library that leverages the docker software to spawn databases/external services dynamically, for testing purposes. This way, we can test our code without mocking these external srevices, allowing us to test integration in a real life scenario.

0 comments on commit f7e89a5

Please sign in to comment.