build ansible-runner via branch #8
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 workflow will build and push an AWX EE image to a container registry based upon the provided configuration | |
# | |
# Image tags will be generated based upon the event that triggered the workflow: | |
# - push event: | |
# - main branch: latest | |
# - devel branch: devel | |
# - all other branches: <branch name>-latest | |
# Branches must be added to the on.push.branches array above to trigger | |
# - pull_request event: DEV-PR-<pull_request_number> | |
# Branches must be added to the on.pull_request.branches array above to trigger | |
# - release event: <tag_name> | |
# - schedule event: nightly | |
# This will be the same configuration as the 'latest' tag, but may contain updated packages, etc. from upstream | |
# - all other events: <first 7 chars of commit sha> | |
# | |
# 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) | |
# | |
# Secrets: | |
# IMAGE_REGISTRY_TOKEN: The token to authenticate with the container registry (default: secrets.GITHUB_TOKEN) | |
# | |
name: Build & Release | |
on: | |
push: | |
# build and push anytime commits are merged to specified branches | |
branches: | |
- main | |
- devel | |
paths: | |
- ".github/workflows/release.yml" | |
- "./**" | |
- '!**/*.md' | |
pull_request: | |
# build and push anytime a pull request is opened or synchronized | |
branches: | |
- main | |
- devel | |
- build-runner # Remove this line before merging to 'main' or 'devel' | |
paths: | |
- ".github/workflows/release.yml" | |
- "./**" | |
- '!**/*.md' | |
release: | |
# build and push anytime a release is created | |
types: | |
- created | |
schedule: | |
# build and push nightly | |
- cron: "13 4 * * *" | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
name: CI Build (Podman) | |
strategy: | |
fail-fast: true | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
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 | |
strategy: | |
fail-fast: true | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
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: Generate image tag | |
run: | | |
if [[ "${{ github.event_name }}" == "push" ]]; then | |
if [[ "${{ github.ref_name }}" == "main" ]]; then | |
echo "IMAGE_TAG=latest" >> $GITHUB_ENV | |
elif [[ "${{ github.ref_name }}" == "devel" ]]; then | |
echo "IMAGE_TAG=devel" >> $GITHUB_ENV | |
else | |
echo "IMAGE_TAG=${{ github.ref_name }}-latest" >> $GITHUB_ENV | |
fi | |
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo "IMAGE_TAG=DEV-PR-${{ github.event.pull_request.number }}" >> $GITHUB_ENV | |
elif [[ "${{ github.event_name }}" == "release" ]]; then | |
echo "IMAGE_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
elif [[ "${{ github.event_name }}" == "schedule" ]]; then | |
echo "IMAGE_TAG=nightly" >> $GITHUB_ENV | |
else | |
echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $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 }} \ | |
context | |