Skip to content

Build and Push Docker Images on Tag #8

Build and Push Docker Images on Tag

Build and Push Docker Images on Tag #8

name: Build and Push Docker Images on Tag
on:
push:
# branches:
# - master
tags:
- 'web@*'
- 'server@*'
workflow_dispatch: {}
jobs:
check-env:
permissions:
contents: none
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
check-docker: ${{ steps.check-docker.outputs.defined }}
steps:
- id: check-docker
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
if: ${{ env.DOCKER_USERNAME != '' }}
run: echo "defined=true" >> $GITHUB_OUTPUT
release:
needs: check-env
if: needs.check-env.outputs.check-docker == 'true'
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata for server
id: meta-server
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_USERNAME }}/gpt-subtitle-api
ghcr.io/${{ github.repository }}/api
tags: |
type=raw,value=latest,enable=true
type=raw,value={{date 'YYYY-MM-DD'}},enable=true
type=sha,format=long,prefix=sha-,enable=true
flavor: latest=false
- name: Build and push API image
id: build-and-push-server
uses: docker/build-push-action@v2
with:
context: .
file: ./apps/server/Dockerfile
push: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha,scope=docker-release
cache-to: type=gha,mode=max,scope=docker-release
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: 'true'
run: echo "${{ steps.meta-server.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push-server.outputs.digest }}
description:
runs-on: ubuntu-latest
needs: check-env
if: needs.check-env.outputs.check-docker == 'true'
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/gpt-subtitle-api