Docker Build and Publish #469
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
# This is a basic workflow to help you get started with Actions | |
name: Docker Build and Publish | |
# Controls when the action will run. Triggers the workflow on push or pull request | |
# events but only for the main branch | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Nightly build | |
pull_request: | |
branches: [ master ] | |
push: | |
branches: [ master ] | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
build_and_push: | |
name: Build, tag, and push images | |
env: | |
default_python: "3.12" | |
strategy: | |
fail-fast: true | |
matrix: | |
python_images: ["3.8","3.9","3.10","3.11","3.12"] | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
- | |
name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
install: true | |
- | |
name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: Generate versions | |
uses: HardNorth/github-version-generate@v1.4.0 | |
with: | |
version-source: file | |
version-file: Dockerfile | |
version-file-extraction-pattern: '(?<=SOPEL_BRANCH=v).+' | |
- name: Inspect Version | |
id: tags | |
env: | |
PYTHON_TAG: ${{ matrix.python_images }} | |
IMAGE: ${{ secrets.DOCKER_SOPEL_IMAGE_NAME }} | |
version: ${{ env.RELEASE_VERSION }} | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then IMAGE="sopel"; fi | |
TAGS="${IMAGE}:${version}-py${PYTHON_TAG},${IMAGE}:${version%.*}-py${PYTHON_TAG},${IMAGE}:${version%.*.*}-py${PYTHON_TAG}" | |
if [[ "x${{ matrix.python_images }}" == "x${{ env.default_python }}" ]] && [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
TAGS="${TAGS},${IMAGE}:${version},${IMAGE}:${version%.*},${IMAGE}:${version%.*.*},${IMAGE}:latest" | |
elif [[ "${{ github.event_name }}" == "schedule" ]]; then | |
TAGS="${IMAGE}:nightly" | |
fi | |
echo ::set-output name=tags::${TAGS} | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- | |
name: Build SOPEL for ${{ matrix.python_images }} | |
uses: docker/build-push-action@v6 | |
if: github.event_name != 'schedule' | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: ./Dockerfile | |
build-args: PYTHON_TAG=${{ matrix.python_images }}-alpine | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.tags.outputs.tags }} | |
- | |
name: Build Nightly SOPEL for ${{ matrix.python_images }} | |
uses: docker/build-push-action@v6 | |
if: github.event_name == 'schedule' && matrix.python_images == env.default_python | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: ./Dockerfile | |
build-args: | | |
PYTHON_TAG=${{ matrix.python_images }}-alpine | |
SOPEL_BRANCH=master | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.tags.outputs.tags }} |