Docker Build (Alpine) #186
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 Build (Alpine) | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "Dockerfile.alpine" | |
- ".github/workflows/docker_build_alpine.yml" | |
schedule: | |
- cron: "0 0 * * 6" | |
workflow_dispatch: | |
env: | |
DOCKER_REPOSITORY: abcfy2/zhparser | |
GHCR_REPOSITORY: ghcr.io/${{ github.repository_owner }}/zhparser | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
strategy: | |
fail-fast: false | |
matrix: | |
pg_tag: | |
- alpine | |
- 12-alpine | |
- 13-alpine | |
- 14-alpine | |
- 15-alpine | |
- 16-alpine | |
- 17-alpine | |
steps: | |
- name: Determine if push is needed | |
run: | | |
echo "GITHUB_EVENT_NAME = ${GITHUB_EVENT_NAME}" | |
PUSH=true | |
if [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then | |
UPSTREAM_VER="$(docker run --rm --pull always postgres:${{ matrix.pg_tag }} sh -c 'echo ${PG_VERSION}' 2>/dev/null)" | |
DOWNSTREAM_VER="$(docker run --rm --pull always ${DOCKER_REPOSITORY}:${{ matrix.pg_tag }} sh -c 'echo ${PG_VERSION}' 2>/dev/null)" | |
echo "upstream verion: ${UPSTREAM_VER}" | |
echo "downstream version: ${DOWNSTREAM_VER}" | |
if [ "${UPSTREAM_VER}" = "${DOWNSTREAM_VER}" ]; then | |
PUSH=false | |
fi | |
fi | |
echo "PUSH = ${PUSH}" | |
echo "PUSH=${PUSH}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GHCR_REPOSITORY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Determine supported platforms | |
run: | | |
PLATFORMS="$(docker buildx imagetools inspect postgres:${PG_TAG} --raw | jq -r '[.manifests[].platform | {os,architecture,variant} | del(.[] | nulls, select( . == "unknown" or . == "riscv64")) | select(length > 0) | join("/")] | join(",")')" | |
echo "postgres:${PG_TAG} support platforms: ${PLATFORMS}" | |
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_ENV | |
env: | |
PG_TAG: ${{ matrix.pg_tag }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v6 | |
with: | |
push: ${{ env.PUSH }} | |
pull: true | |
file: Dockerfile.alpine | |
build-args: | | |
PG_TAG=${{ matrix.pg_tag }} | |
platforms: ${{ env.PLATFORMS }} | |
tags: ${{ env.DOCKER_REPOSITORY }}:${{ matrix.pg_tag }},${{ env.GHCR_REPOSITORY }}:${{ matrix.pg_tag }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |