-
Notifications
You must be signed in to change notification settings - Fork 1
74 lines (65 loc) · 2.96 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: CI devops 2024
on:
push:
branches:
- main
- develop
pull_request:
jobs:
test-backend:
runs-on: ubuntu-22.04
steps:
#checkout your github code using actions/[email protected]
- name: Checkout code
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@v3
with:
java-version: '17'
distribution: 'temurin'
architecture: 'x64'
#finally build your app with the latest command
- name: Build and test simple-api-student with Maven
run: mvn -B verify sonar:sonar -Dsonar.projectKey=cpe-lyon-12345_ci-cd -Dsonar.organization=cpe-lyon-12345 -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} --file ./TP01/simple-api-student-main/pom.xml
# - name: Build and test simple-api with Maven
# run: mvn -B verify sonar:sonar -Dsonar.projectKey=cpe-lyon-12345_ci-cd -Dsonar.organization=cpe-lyon-12345 -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} --file ./TP01/simpleapi/pom.xml
# define job to build and publish docker image
build-and-push-docker-image:
needs: test-backend
# run only when code is compiling and tests are passing
runs-on: ubuntu-22.04
# steps to perform in job
steps:
- name: Login to DockerHub
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_AUTH }}
#checkout your github code using actions/[email protected]
- name: Checkout code
uses: actions/[email protected]
- 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
context: TP01/simple-api-student-main
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-api:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- 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
context: TP01/db
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-postgres:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
- name: Build image and push http
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: TP01/web
# Note: tags has to be all lower-case
tags: ${{secrets.DOCKERHUB_USERNAME}}/tp01-web:latest
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}