Skip to content

Build & Release

Build & Release #217

Workflow file for this run

---
# This workflow builds an AWX EE image and optionally pushes it to a container registry.
#
# Jobs:
# ci: Runs on all triggers. Builds the image with Podman to validate the build.
# release: Pushes the image to the registry. Only runs on:
# - release: when a GitHub release is created
# - schedule: weekly nightly builds
# - workflow_dispatch: when manually triggered with push_image=true
#
# To push an image for a specific branch:
# 1. Go to Actions > "Build & Release" workflow
# 2. Click "Run workflow"
# 3. Select the target branch
# 4. Check "Push image to registry after build"
# 5. Click "Run workflow"
#
# Image tags:
# - release event: <tag_name> (e.g., v1.0.0)
# - schedule event: nightly
# - workflow_dispatch:
# - main branch: latest
# - devel branch: devel
# - branches with open PR: DEV-PR-<number>
# - other branches: DEV-<short-sha>
# - pull_request event: DEV-PR-<number>
#
# Variables:
# IMAGE_REGISTRY_URL: The container registry to push the image to (default: ghcr.io)
# IMAGE_REPOSITORY: The repository to push the image to (default: github.repository)
# IMAGE_REGISTRY_USER: The username to authenticate with the container registry (default: github.actor)
# ALWAYS_PUSH_GHCR: Set to 'true' to also push images to ghcr.io (default: false)
#
# Secrets:
# IMAGE_REGISTRY_TOKEN: The token to authenticate with the container registry (default: secrets.GITHUB_TOKEN)
#
name: Build & Release
on:
push:
# run CI build when commits are merged to specified branches
branches:
- main
- devel
paths:
- "**"
- '!**/*.md'
pull_request:
# run CI build when a pull request is opened or synchronized
branches:
- main
- devel
paths:
- "**"
- '!**/*.md'
release:
# build and push when a release is created
types:
- created
schedule:
# build and push nightly image weekly
- cron: "13 4 * * 1"
workflow_dispatch:
inputs:
push_image:
description: 'Push image to registry after build'
type: boolean
required: false
default: false
jobs:
ci:
runs-on: ubuntu-latest
name: CI Build (Podman)
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install -r requirements.txt
- name: Build EE with Podman
run: |
ansible-builder build -v3 -t ${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}/${{ vars.IMAGE_REPOSITORY || github.repository }} --container-runtime=podman
release:
runs-on: ubuntu-latest
name: Release
# Only push images for releases, scheduled builds, or manual workflow_dispatch with push_image=true
if: ${{ github.event_name == 'release' || github.event_name == 'schedule' || github.event.inputs.push_image == 'true' }}
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install -r requirements.txt
- name: Login to Docker Container Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}
username: ${{ vars.IMAGE_REGISTRY_USER || github.actor }}
password: ${{ secrets.IMAGE_REGISTRY_TOKEN || secrets.GITHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: ${{ vars.ALWAYS_PUSH_GHCR == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image tag
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
IMAGE_TAG="${{ github.event.release.tag_name }}"
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
IMAGE_TAG="nightly"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
IMAGE_TAG="DEV-PR-${{ github.event.pull_request.number }}"
elif [[ "${{ github.ref_name }}" == "main" ]]; then
IMAGE_TAG="latest"
elif [[ "${{ github.ref_name }}" == "devel" ]]; then
IMAGE_TAG="devel"
else
# For workflow_dispatch on feature branches, try to find associated PR
PR_NUMBER=$(gh pr list --head "${{ github.ref_name }}" --state open --json number --jq '.[0].number' 2>/dev/null || true)
if [[ -n "$PR_NUMBER" ]]; then
IMAGE_TAG="DEV-PR-${PR_NUMBER}"
else
# Fallback: use short commit hash (first 7 chars)
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
IMAGE_TAG="DEV-${SHORT_SHA}"
fi
fi
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
echo "::notice::Image tag: ${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}/${{ vars.IMAGE_REPOSITORY || github.repository }}:${IMAGE_TAG}"
# Add ghcr.io tag if dual-push is enabled
if [[ "${{ vars.ALWAYS_PUSH_GHCR }}" == "true" ]]; then
echo "GHCR_TAG_ARG=--tag=ghcr.io/${{ github.repository }}:${IMAGE_TAG}" >> $GITHUB_ENV
echo "::notice::Also pushing to ghcr.io/${{ github.repository }}:${IMAGE_TAG}"
else
echo "GHCR_TAG_ARG=" >> $GITHUB_ENV
fi
- name: Build and push image
run: |
docker buildx create --name awx-ee-buildx
docker buildx use awx-ee-buildx
ansible-builder create -v3 --output-file=Dockerfile
docker buildx build \
--push \
--platform=linux/amd64,linux/arm64 \
--tag=${{ vars.IMAGE_REGISTRY_URL || 'ghcr.io' }}/${{ vars.IMAGE_REPOSITORY || github.repository }}:${{ env.IMAGE_TAG }} ${{ env.GHCR_TAG_ARG }} \
context