feat(ci): enhance docker build and push workflow to support multiple … #7
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: Build and Push Docker Images | |
on: | |
push: | |
paths: | |
- "build-base/**" | |
- "api/**" | |
- "solver/**" | |
workflow_dispatch: | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build-and-push-base: | |
if: github.event_name == 'workflow_dispatch' || contains(github.event.push.paths, 'build-base/') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set lowercase repository name | |
run: echo "REPO_LOWERCASE=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push base image | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./build-base | |
file: ./build-base/Dockerfile | |
push: true | |
tags: ghcr.io/${{ env.REPO_LOWERCASE }}/base:latest | |
platforms: linux/amd64,linux/arm64 | |
build-and-push-grpc-server: | |
needs: build-and-push-base | |
if: | | |
always() && | |
(needs.build-and-push-base.result == 'success' || needs.build-and-push-base.result == 'skipped') && | |
(github.event_name == 'workflow_dispatch' || contains(github.event.push.paths, 'build-base/') || contains(github.event.push.paths, 'api/') || contains(github.event.push.paths, 'solver/')) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set lowercase repository name | |
run: echo "REPO_LOWERCASE=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push grpc-server image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./api/Dockerfile | |
push: true | |
tags: ghcr.io/${{ env.REPO_LOWERCASE }}/grpc-server:latest | |
platforms: linux/amd64,linux/arm64 |