Skip to content

Build Kolla container images #406

Build Kolla container images

Build Kolla container images #406

---
name: Build Kolla container images
on:
workflow_dispatch:
inputs:
regexes:
description: Space-separated list of regular expressions matching overcloud images to build
type: string
required: false
default: ""
overcloud:
description: Build overcloud images?
type: boolean
required: false
default: true
seed:
description: Build seed images?
type: boolean
required: false
default: false
centos-stream-8:
description: Build CentOS Stream 8 images?
type: boolean
required: false
default: true
rocky-linux-9:
description: Build Rocky Linux 9 images?
type: boolean
required: false
default: true
ubuntu-focal:
description: Build Ubuntu Focal 20.04 images?
type: boolean
required: false
default: true
push:
description: Whether to push images
type: boolean
required: false
default: true
env:
ANSIBLE_FORCE_COLOR: True
jobs:
generate-tag:
name: Generate container image tag
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
permissions: {}
outputs:
kolla_tag: ${{ steps.kolla_tag.outputs.kolla_tag }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Determine OpenStack release
id: openstack_release
run: |
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' .gitreview)
echo "openstack_release=${BRANCH}" | sed "s|stable/||" >> $GITHUB_OUTPUT
# Generate a tag to apply to all built container images.
# Without this, each kayobe * container image build command would use a different tag.
- name: Generate container image tag
id: kolla_tag
run: |
echo "kolla_tag=$(date +${{ steps.openstack_release.outputs.openstack_release }}-%Y%m%dT%H%M%S)" >> $GITHUB_OUTPUT
# Dynamically define job matrix.
# We need a separate matrix entry for each distribution, when the relevant input is true.
# https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
- name: Generate build matrix
id: set-matrix
run: |
comma=""
echo -n "matrix={\"distro\": [" >> $GITHUB_OUTPUT
if [[ ${{ inputs.centos-stream-8 }} == 'true' ]]; then
echo -n "$comma\"centos\"" >> $GITHUB_OUTPUT
comma=", "
fi
if [[ ${{ inputs.rocky-linux-9 }} == 'true' ]]; then
echo -n "$comma\"rocky\"" >> $GITHUB_OUTPUT
comma=", "
fi
if [[ ${{ inputs.ubuntu-focal }} == 'true' ]]; then
echo -n "$comma\"ubuntu\"" >> $GITHUB_OUTPUT
comma=", "
fi
echo "]}" >> $GITHUB_OUTPUT
- name: Display container image tag
run: |
echo "${{ steps.kolla_tag.outputs.kolla_tag }}"
container-image-build:
name: Build Kolla container images
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
timeout-minutes: 720
permissions: {}
strategy:
matrix: ${{ fromJson(needs.generate-tag.outputs.matrix) }}
needs:
- generate-tag
steps:
- uses: actions/checkout@v3
with:
path: src/kayobe-config
- name: Clone StackHPC Kayobe repository
uses: actions/checkout@v3
with:
repository: stackhpc/kayobe
ref: refs/heads/stackhpc/${{ needs.generate-tag.outputs.openstack_release }}
path: src/kayobe
# FIXME: Failed in kolla-ansible : Ensure the latest version of pip is installed
- name: Install dependencies
run: |
sudo dnf -y install python3-virtualenv
- name: Setup networking
run: |
if ! ip l show breth1 >/dev/null 2>&1; then
sudo ip l add breth1 type bridge
fi
sudo ip l set breth1 up
if ! ip a show breth1 | grep 192.168.33.3/24; then
sudo ip a add 192.168.33.3/24 dev breth1
fi
if ! ip l show dummy1 >/dev/null 2>&1; then
sudo ip l add dummy1 type dummy
fi
sudo ip l set dummy1 up
sudo ip l set dummy1 master breth1
# FIXME: Without this workaround we see the following issue after the runner is power cycled:
# TASK [MichaelRigart.interfaces : RedHat | ensure network service is started and enabled] ***
# Unable to start service network: Job for network.service failed because the control process exited with error code.
# See \"systemctl status network.service\" and \"journalctl -xe\" for details.
- name: Kill dhclient (workaround)
run: |
(sudo killall dhclient || true) && sudo systemctl restart network
- name: Install Kayobe
run: |
mkdir -p venvs &&
pushd venvs &&
python3 -m venv kayobe &&
source kayobe/bin/activate &&
pip install -U pip &&
pip install ../src/kayobe
- name: Bootstrap the control host
run: |
source venvs/kayobe/bin/activate &&
source src/kayobe-config/kayobe-env --environment ci-builder &&
kayobe control host bootstrap
- name: Configure the seed host
run: |
source venvs/kayobe/bin/activate &&
source src/kayobe-config/kayobe-env --environment ci-builder &&
kayobe seed host configure
env:
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
- name: Build and push kolla overcloud images
run: |
args="${{ github.event.inputs.regexes }}"
args="$args -e kolla_base_distro=${{ matrix.distro }}"
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
if ${{ inputs.push }} == 'true'; then
args="$args --push"
fi
source venvs/kayobe/bin/activate &&
source src/kayobe-config/kayobe-env --environment ci-builder &&
kayobe overcloud container image build $args
env:
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
if: github.event.inputs.overcloud == 'true'
- name: Build and push kolla seed images
run: |
args="-e kolla_base_distro=${{ matrix.distro }}"
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
if ${{ inputs.push }} == 'true'; then
args="$args --push"
fi
source venvs/kayobe/bin/activate &&
source src/kayobe-config/kayobe-env --environment ci-builder &&
kayobe seed container image build $args
env:
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
if: github.event.inputs.seed == 'true'
- name: Get built container images
run: |
sudo docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/${{ matrix.distro }}-*:${{ needs.generate-tag.outputs.kolla_tag }}" > ${{ matrix.distro }}-container-images
- name: Upload container images artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.distro }} container images
path: ${{ matrix.distro }}-container-images
retention-days: 7
- name: Prune local Kolla container images over 1 week old
run: |
sudo docker image prune --all --force --filter until=168h --filter="label=kolla_version"
sync-container-repositories:
name: Trigger container image repository sync
needs:
- container-image-build
if: github.repository == 'stackhpc/stackhpc-kayobe-config' && inputs.push
runs-on: ubuntu-latest
permissions: {}
steps:
# NOTE(mgoddard): Trigger another CI workflow in the
# stackhpc-release-train repository.
- name: Trigger container image repository sync
run: |
filter='${{ inputs.regexes }}'
if [[ -n $filter ]] && [[ ${{ github.event.inputs.seed }} == 'true' ]]; then
filter="$filter bifrost"
fi
gh workflow run \
container-sync.yml \
--repo stackhpc/stackhpc-release-train \
--ref main \
-f filter="$filter" \
-f sync-new-images=false
env:
GITHUB_TOKEN: ${{ secrets.STACKHPC_RELEASE_TRAIN_TOKEN }}
- name: Display link to container image repository sync workflows
run: |
echo "::notice Container image repository sync workflows: https://github.com/stackhpc/stackhpc-release-train/actions/workflows/container-sync.yml"