Build Container Images #26
This file contains hidden or 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 Container Images | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| service_config: | |
| description: 'Service configuration' | |
| required: true | |
| default: 'api' | |
| type: choice | |
| options: | |
| - api | |
| - cranker | |
| - writer-service | |
| - steward-writer-service | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-container: | |
| runs-on: big-runner-1 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Determine Docker target and image name | |
| id: config | |
| run: | | |
| case "${{ github.event.inputs.service_config }}" in | |
| "api") | |
| echo "target=api" >> $GITHUB_OUTPUT | |
| echo "service=api" >> $GITHUB_OUTPUT | |
| echo "image_name=${{ github.repository }}/kobe-api" >> $GITHUB_OUTPUT | |
| ;; | |
| "cranker") | |
| echo "target=cranker" >> $GITHUB_OUTPUT | |
| echo "service=cranker" >> $GITHUB_OUTPUT | |
| echo "image_name=${{ github.repository }}/kobe-cranker" >> $GITHUB_OUTPUT | |
| ;; | |
| "writer-service") | |
| echo "target=writer-service" >> $GITHUB_OUTPUT | |
| echo "service=writer-service" >> $GITHUB_OUTPUT | |
| echo "image_name=${{ github.repository }}/kobe-writer-service" >> $GITHUB_OUTPUT | |
| ;; | |
| "steward-writer-service") | |
| echo "target=steward-writer-service" >> $GITHUB_OUTPUT | |
| echo "service=steward-writer-service" >> $GITHUB_OUTPUT | |
| echo "image_name=${{ github.repository }}/kobe-steward-writer-service" >> $GITHUB_OUTPUT | |
| ;; | |
| esac | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ steps.config.outputs.image_name }} | |
| tags: | | |
| type=raw,value=${{ github.ref_name }}-${{ github.event.inputs.service_config }}-{{sha}} | |
| type=raw,value=${{ github.ref_name }}-${{ github.event.inputs.service_config }}-latest | |
| - name: Build and push container | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| target: ${{ steps.config.outputs.target }} | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |