Skip to content

CD - Build Docker Image #2

CD - Build Docker Image

CD - Build Docker Image #2

Workflow file for this run

name: CD - Build Docker Image
on:
release:
types: [published]
workflow_dispatch:
inputs:
rebuild:
description: "Rebuild tag?"
required: true
default: "no"
type: choice
options:
- "no"
- "yes"
concurrency:
group: docker-${{ github.event.workflow_run.head_branch || github.ref }}
cancel-in-progress: true
permissions:
packages: write
env:
DEFAULT_PYTHON: "3.12"
jobs:
docker:
name: Build Docker Image
runs-on: ubuntu-latest
environment:
name: release
steps:
- name: Check repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "${{ env.DEFAULT_PYTHON }}"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r dev-requirements.txt
pip install -e ".[dev]"
- name: Get current version (rebuild)
if: ${{ inputs.rebuild == 'yes' }}
run: |
UIPROTECT_VERSION=$(git describe --tags --abbrev=0)
echo "UIPROTECT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "DOCKER_TAGS=ghcr.io/uilibs/uiprotect:dev,ghcr.io/uilibs/uiprotect:$UIPROTECT_VERSION" >> $GITHUB_ENV
- name: Get current version (no rebuild)
if: ${{ inputs.rebuild != 'yes' }}
run: |
UIPROTECT_VERSION=v$(python -c 'from importlib.metadata import version; print(version("uiprotect"))')
echo "UIPROTECT_VERSION=$UIPROTECT_VERSION" >> $GITHUB_ENV
echo "DOCKER_TAGS=ghcr.io/uilibs/uiprotect:dev,ghcr.io/uilibs/uiprotect:$(echo $UIPROTECT_VERSION | tr "+" -)" >> $GITHUB_ENV
- name: Add Latest Docker Tag
run: |
if [[ ! "$UIPROTECT_VERSION" == *"dev"* ]]; then
echo "DOCKER_TAGS=ghcr.io/uilibs/uiprotect:latest,$DOCKER_TAGS" >> $GITHUB_ENV
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
target: prod
push: true
build-args: |
UIPROTECT_VERSION=${{ env.UIPROTECT_VERSION }}
cache-from: ghcr.io/uilibs/uiprotect:buildcache
cache-to: type=registry,ref=ghcr.io/uilibs/uiprotect:buildcache,mode=max
tags: ${{ env.DOCKER_TAGS }}