Skip to content

Docker Image CI

Docker Image CI #12

Workflow file for this run

name: Docker Image CI
on:
workflow_dispatch:
push:
branches: [main]
paths:
- 'src/**'
pull_request:
branches: [main]
paths:
- 'src/**'
jobs:
build:
runs-on: ubuntu-latest
env:
REPO: 'sampleapi'
TAG: ${{ github.sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_LOGIN_SERVER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build Docker Image
uses: docker/build-push-action@v5
with:
context: src/SampleApi
load: true
push: false
tags: ${{ env.REPO }}:${{ env.TAG }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'docker.io/library/${{ env.REPO }}:${{ env.TAG }}'
format: 'github'
github-token: ${{ github.token }}
env:
TRIVY_USERNAME: Username
TRIVY_PASSWORD: Password
- name: Push image to ACR
uses: docker/build-push-action@v5
with:
context: src/SampleApi
push: true
tags: |
${{ vars.DOCKER_LOGIN_SERVER }}/${{ env.REPO }}:latest
${{ vars.DOCKER_LOGIN_SERVER }}/${{ env.REPO }}:${{ env.TAG }}