Skip to content

Commit c8bebd9

Browse files
committed
workflows:
1 parent a8553b1 commit c8bebd9

2 files changed

Lines changed: 81 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,10 @@ jobs:
3535
# Stage 2 : Build image Docker
3636
build:
3737
needs: test
38-
runs-on: ubuntu-latest
39-
steps:
40-
- uses: actions/checkout@v4
41-
- uses: docker/setup-buildx-action@v3
42-
- uses: docker/build-push-action@v5
43-
with:
44-
context: ./app
45-
push: false
46-
tags: devops-app:${{ github.sha }}
47-
cache-from: type=gha
48-
cache-to: type=gha,mode=max
38+
uses: ./.github/workflows/reusable-docker.yml
39+
with:
40+
image-name: devops-app
41+
context: ./app
4942

5043
# Stage 3 : Scan de sécurité
5144
security:
@@ -69,4 +62,25 @@ jobs:
6962
runs-on: ubuntu-latest
7063
environment: production
7164
steps:
72-
- run: echo "Deploying version ${{ github.sha }}..."
65+
- run: echo "Deploying version ${{ github.sha }}..."
66+
67+
deploy-staging:
68+
needs: build
69+
runs-on: ubuntu-latest
70+
environment: staging
71+
steps:
72+
- run: echo "Deploying to staging..."
73+
- name: Use secrets
74+
env:
75+
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
76+
API_KEY: ${{ secrets.API_KEY }}
77+
run: |
78+
echo "Secrets are masked in logs"
79+
echo "DB_PASSWORD length: ${#DB_PASSWORD}"
80+
81+
deploy-production:
82+
needs: deploy-staging
83+
runs-on: ubuntu-latest
84+
environment: production
85+
steps:
86+
- run: echo "Deploying to production..."
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Reusable Docker Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image-name:
7+
required: true
8+
type: string
9+
context:
10+
required: false
11+
type: string
12+
default: '.'
13+
dockerfile:
14+
required: false
15+
type: string
16+
default: 'Dockerfile'
17+
secrets:
18+
registry-username:
19+
required: false
20+
registry-password:
21+
required: false
22+
outputs:
23+
image-tag:
24+
description: "Tag de l'image construite"
25+
value: ${{ jobs.build.outputs.tag }}
26+
27+
jobs:
28+
build:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
tag: ${{ steps.meta.outputs.tags }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Docker meta
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ inputs.image-name }}
40+
tags: |
41+
type=sha,prefix=
42+
type=ref,event=branch
43+
type=semver,pattern={{version}}
44+
45+
- uses: docker/setup-buildx-action@v3
46+
47+
- uses: docker/build-push-action@v5
48+
with:
49+
context: ${{ inputs.context }}
50+
file: ${{ inputs.context }}/${{ inputs.dockerfile }}
51+
push: false
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)