Skip to content

Update Packer action, release #27

Update Packer action, release

Update Packer action, release #27

Workflow file for this run

name: Build and Push Images
on:
pull_request:
branches:
- main
env:
PACKER_VERSION: "latest"
QCOW2_IMG: quay.io/platform9/vjailbreak
UI_IMG: quay.io/platform9/vjailbreak-ui
V2V_IMG: quay.io/platform9/vjailbreak-v2v-helper
CONTROLLER_IMG: quay.io/platform9/vjailbreak-controller
jobs:
build-containers:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Bump version
id: bump_version
uses: phips28/gh-action-bump-version@master
with:
minor-wording: 'add,Adds,new'
major-wording: 'MAJOR,cut-major'
patch-wording: 'patch,fixes' # Providing patch-wording will override commits
# defaulting to a patch bump.
rc-wording: 'RELEASE,alpha'
skip-commit: 'true'
skip-tag: 'true'
skip-push: 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set environment variables for images
run: |
# Get the branch name, remove 'refs/heads/' from github.ref
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
# If the branch is 'main', don't append the branch name to the tag
if [ "$BRANCH_NAME" == "main" ]; then
TAG=${{ steps.bump_version.outputs.newTag }}
else
TAG=${{ steps.bump_version.outputs.newTag }}-$BRANCH_NAME
fi
echo "TAG=$TAG" >> $GITHUB_ENV
echo "UI_IMG=${{ env.UI_IMG }}:$TAG" >> $GITHUB_ENV
echo "V2V_IMG=${{ env.V2V_IMG }}:$TAG" >> $GITHUB_ENV
echo "CONTROLLER_IMG=${{ env.CONTROLLER_IMG }}:$TAG" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_ROBOT_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_PASSWORD }}
- name: Build and push UI image
run: make ui
- name: Build and push helper image
run: make v2v-helper
- name: Build and push controller image
run: make -o v2v-helper vjail-controller
- name: Create deploy folder
run: mkdir -p image_builder/deploy
- name: Substitue image tags in manifests
uses: danielr1996/envsubst-action@1.0.0
with:
input: ./ui/deploy/ui.yaml
output: ./image_builder/deploy/01ui.yaml
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.22.5'
- name: Generate Controller Manifests
run: |
make -C ./k8s/migration/ build-installer
cp ./k8s/migration/dist/install.yaml image_builder/deploy/00controller.yaml
cp -r ./k8s/kube-prometheus image_builder/deploy/
- name: Check PR Title
id: check_pr
run: |
echo "PR message: ${{ github.event.pull_request.title }}"
if [[ "${{ github.event.pull_request.title }}" == *"release"* ]]; then
echo "Release keyword found."
echo "release_found=true" >> $GITHUB_ENV
else
echo "Release keyword not found."
echo "release_found=false" >> $GITHUB_ENV
fi
- name: Enable KVM group perms
if: env.release_found == 'true'
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Set up QEMU
if: env.release_found == 'true'
run: sudo apt-get update && sudo apt-get install qemu-system qemu-utils -y
- name: Setup `packer`
if: env.release_found == 'true'
uses: hashicorp/setup-packer@main
id: setup
with:
version: ${{ env.PACKER_VERSION }}
- name: Run `packer init`
if: env.release_found == 'true'
id: init
run: "packer init ./image_builder/vjailbreak-image.pkr.hcl"
- name: Run `packer validate`
if: env.release_found == 'true'
id: validate
run: "packer validate ./image_builder/vjailbreak-image.pkr.hcl"
- name: Run `packer build`
if: env.release_found == 'true'
id: build
run: "PACKER_LOG=1 packer build ./image_builder/vjailbreak-image.pkr.hcl"
- name: Upload vjailbreak qcow2 to quay
uses: docker/build-push-action@v4
with:
context: ./image_builder
file: .Dockerfile
push: true
tags: ${{ env.QCOW2_IMG }}:${{ env.TAG }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: vjailbreak-yamls
path: |
image_builder/deploy/00controller.yaml
image_builder/deploy/01ui.yaml