Skip to content

Linuxfabrik: Build Execution Environment #5

Linuxfabrik: Build Execution Environment

Linuxfabrik: Build Execution Environment #5

name: 'Linuxfabrik: Build Execution Environment'
on:
push:
# run for main if execution-environment.yml or requirements.yml changes
branches:
- 'main'
paths:
- 'execution-environment.yml'
- 'requirements.yml'
# or when a version tag is pushed
tags:
- 'v*.*.*' # any vX.Y.Z tag
workflow_dispatch: # yamllint disable-line rule:empty-values
# modify the default permissions granted to the GITHUB_TOKEN
permissions:
contents: 'read' # to checkout the code
packages: 'write' # to push to GitHub Container Registry
jobs:
build-ee:
runs-on:
- 'ubuntu-latest'
steps:
- name: 'git clone https://github.com/Linuxfabrik/THIS-REPO'
uses: 'actions/checkout@v4'
- name: 'Log in to GitHub Container Registry'
uses: 'redhat-actions/podman-login@v1'
with:
registry: 'ghcr.io'
username: '${{ github.actor }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Install Ansible Builder'
run: |
python3 -m pip install --upgrade pip
pip install ansible-builder
- name: 'Store the lowercase repository name'
run: |
echo "GITHUB_REPOSITORY_OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
- name: 'Determine image tags'
id: 'determine-tags'
run: |
# tag event?
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
# strip "refs/tags/"
FULL_TAG="${GITHUB_REF#refs/tags/}"
# strip leading "v" if present
SEMVER="${FULL_TAG#v}"
echo "TAG1=${SEMVER}" >> $GITHUB_ENV
echo "TAG2=latest" >> $GITHUB_ENV
else
# non-tag (push/main or manual)
echo "TAG1=${GITHUB_SHA}" >> $GITHUB_ENV
echo "TAG2=dev" >> $GITHUB_ENV
fi
- name: 'Build Collection'
run: |
sed --in-place --regexp-extended "s/version: '[^']*'/version: '$TAG1'/" galaxy.yml
ansible-galaxy collection build
cp linuxfabrik-lfops-${TAG1}.tar.gz linuxfabrik-lfops.tar.gz
- name: 'Build Execution Environment'
run: |
ansible-builder build \
--tag 'ghcr.io/${{ env.GITHUB_REPOSITORY_OWNER_LOWERCASE }}/lfops_ee:${{ env.TAG1 }}' \
-vvv
- name: 'Re-tag the image'
run: |
podman tag \
'ghcr.io/${{ env.GITHUB_REPOSITORY_OWNER_LOWERCASE }}/lfops_ee:${{ env.TAG1 }}' \
'ghcr.io/${{ env.GITHUB_REPOSITORY_OWNER_LOWERCASE }}/lfops_ee:${{ env.TAG2 }}'
- name: 'Push to GitHub Container Registry'
id: 'push-to-ghcr'
uses: 'redhat-actions/push-to-registry@v2'
with:
registry: 'ghcr.io'
image: '${{ env.GITHUB_REPOSITORY_OWNER_LOWERCASE }}/lfops_ee'
tags: '${{ env.TAG1 }} ${{ env.TAG2 }}'
- name: 'Show pushed image path'
run: 'echo "LFOps Execution Environment published to ${{ steps.push-to-ghcr.outputs.registry-path }}"'