Skip to content

docker

docker #1361

Workflow file for this run

name: "docker"
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
release:
types:
# "released" excludes pre-releases
# "published" is either a release or a pre-release
- published
schedule:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# Build nightly at 11pm UTC. Coordinate to build before test-harness.
- cron: '0 23 * * *'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: "Checkout source code at current commit"
uses: actions/checkout@v3
- name: Prepare tags for Docker image
if: (github.event_name == 'release' && github.event.action == 'published') || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
id: prepare
run: |
COMMIT_SHA="${GITHUB_SHA}"
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.pull_request.number }}-merge
COMMIT_SHA=${{ github.event.pull_request.head.sha }}
fi
printf "Version resolved to %s\n" "${VERSION}"
TAGS=${{ github.repository }}:sha-${COMMIT_SHA:0:7}
SLIM_TAGS=${{ github.repository }}:slim-sha-${COMMIT_SHA:0:7}
if [[ -n $VERSION ]]; then
TAGS="$TAGS,${{ github.repository }}:${VERSION}"
SLIM_TAGS="$SLIM_TAGS,${{ github.repository }}:slim-${VERSION}"
fi
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${{ github.repository }}:latest"
SLIM_TAGS="$SLIM_TAGS,${{ github.repository }}:slim-latest"
fi
if [[ ${{ github.event_name }} == 'schedule' ]]; then
TAGS="$TAGS,${{ github.repository }}:latest,${{ github.repository }}:nightly"
SLIM_TAGS="$SLIM_TAGS,${{ github.repository }}:slim-latest,${{ github.repository }}:slim-nightly"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
printf "TAGS are %s\n" "${TAGS}"
echo "slim-tags=${SLIM_TAGS}" >> "$GITHUB_OUTPUT"
printf "SLIM_TAGS are %s\n" "${SLIM_TAGS}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: (github.event_name == 'release' && github.event.action == 'published') || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: "Build and push full docker image to DockerHub"
id: docker_full_build
uses: docker/build-push-action@v3
with:
push: ${{ (github.event_name == 'release' && github.event.action == 'published') || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.prepare.outputs.tags }}
- name: "Build and push slim docker image to DockerHub"
id: docker_slim_build
uses: docker/build-push-action@v3
with:
file: ./Dockerfile.slim
push: ${{ (github.event_name == 'release' && github.event.action == 'published') || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.prepare.outputs.slim-tags }}