Skip to content

Merge branch 'main' into issue-7436 #25064

Merge branch 'main' into issue-7436

Merge branch 'main' into issue-7436 #25064

Workflow file for this run

name: Dockerize
on:
push:
pull_request:
env:
REGISTRY_IMAGE: specifyconsortium/specify7-service
jobs:
prep:
name: prepare tag names
runs-on: ubuntu-latest
# "push" event is not triggered for forks, so need to listen for
# pull_requests, but only for external ones, so as not to run the action
# twice
if: github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.fork == true
outputs:
tags: ${{ steps.prep.outputs.tags }}
version: ${{ steps.prep.outputs.version }}
steps:
- name: Prepare tags and version for manifest
id: prep
run: |
DOCKER_IMAGE=${{ env.REGISTRY_IMAGE }}
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
# Docker does not like / in tag names, so replace them with -
# See https://github.com/specify/specify7-test-panel/issues/110#issuecomment-1943045253
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=main
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
HOTFIX=${VERSION%.*}
MINOR=${HOTFIX%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${HOTFIX},${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS"
fi
echo "Tags: ${TAGS}"
echo "Version: ${VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
build:
name: build & push
needs: prep
strategy:
fail-fast: false
matrix:
include:
- name: amd64
platform: linux/amd64
runner: ubuntu-latest
- name: arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- 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 and push by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
build-args: |
BUILD_VERSION=${{ needs.prep.outputs.version }}
GIT_SHA=${{ github.sha }}
tags: ${{ needs.prep.outputs.tags }}
push: true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.name }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: create & push manifest
needs:
- prep
- build
runs-on: ubuntu-latest
steps:
- name: Download all digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- 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: Create manifest list and push
working-directory: /tmp/digests
env:
TAGS: ${{ needs.prep.outputs.tags }}
run: |
echo "Pushing manifests on tags: ${TAGS}"
TAG_ARGS=$(echo "$TAGS" | tr ',' '\n' | sed 's/^/-t /' | xargs)
docker buildx imagetools create $TAG_ARGS \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ needs.prep.outputs.version }}