create image with root user & recognizable tag #4
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: Docker | |
on: | |
push: | |
branches: ["master"] | |
jobs: | |
build: | |
name: Build & puch docker image | |
runs-on: ubuntu-latest | |
env: | |
IMG_NAME: ${{ github.repository }} | |
IMG_VERSION: 0.0.3 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- 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 Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build docker image | |
run: docker build -t docker.io/${{ github.repository }}:${{ env.IMG_VERSION }} . -f Dockerfile | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/[email protected] | |
with: | |
image-ref: 'docker.io/${{ github.repository }}:${{ env.IMG_VERSION }}' | |
format: 'table' | |
env: | |
TRIVY_DB_REPOSITORY: 'public.ecr.aws/aquasecurity/trivy-db,aquasec/trivy-db,ghcr.io/aquasecurity/trivy-db' | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64, linux/arm64 | |
push: true | |
tags: '${{ github.repository }}:${{ env.IMG_VERSION }}' | |
- name: Build and push image with root | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: DockerfileRoot | |
platform: linux/amd64, linux/arm64 | |
push: true | |
tags: '${{ github.repository }}:${{ env.IMG_VERSION }}-root' |