v3.28.4 #99
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Deploy docker images' | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
env: | |
tag: ${{ github.ref_type == 'tag' && github.ref_name || github.sha }} | |
jobs: | |
build: | |
name: Build ${{ matrix.image_name }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
image: | |
- { name: 'api', dockerfile: './docker/api/prod/Dockerfile' } | |
- { name: 'data', dockerfile: './docker/python/Dockerfile' } | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Build ${{ matrix.image.name }} image for test | |
id: docker_test | |
uses: docker/build-push-action@v4 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: ./ | |
file: ${{ matrix.image.dockerfile }} | |
load: true | |
push: false | |
tags: betagouvpdc/${{ matrix.image.name }}:${{ env.tag }} | |
labels: | | |
org.opencontainers.image.title=${{ matrix.image.name }} Image | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.created=${{ steps.buildx.outputs.start }} | |
org.opencontainers.image.version=${{ env.tag }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: betagouvpdc/${{ matrix.image.name }}:${{ env.tag }} | |
format: 'template' | |
template: '@/contrib/sarif.tpl' | |
output: 'trivy-results.sarif' | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v2 | |
continue-on-error: true | |
with: | |
sarif_file: 'trivy-results.sarif' | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push ${{ matrix.image.name }} | |
id: docker_build | |
uses: docker/build-push-action@v4 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: ${{ matrix.image.dockerfile }} | |
push: true | |
tags: betagouvpdc/${{ matrix.image.name }}:${{ env.tag }} | |
labels: | | |
org.opencontainers.image.title=${{ matrix.image.name }} Image | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.created=${{ steps.buildx.outputs.start }} | |
org.opencontainers.image.version=${{ env.tag }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
- run: echo ${{ steps.docker_build.outputs.digest }} | |
deploy: | |
name: Deploy | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger Workflow | |
uses: actions/github-script@v6 | |
env: | |
TARGET_VERSION: ${{ env.tag }} | |
with: | |
github-token: ${{ secrets.GA_PDC_TOKEN }} | |
script: | | |
github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: 'preuve-covoiturage-infra', | |
workflow_id: 'deploy.yml', | |
ref: 'main', | |
inputs: { | |
version: process.env.TARGET_VERSION, | |
}, | |
}) |