Skip to content

Commit

Permalink
add workflow to test doca build
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpb committed Dec 10, 2024
1 parent 6e650af commit 505d5f4
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 42 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/doca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Test DOCA extra build
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**'
- '!dev/**'
- 'dev/setup-env.sh'
- '!docs/**'
- '!README.md'
- '!.gitignore'
- '!.github/workflows/'
- '.github/workflows/doca'
pull_request:
paths:
- '**'
- '!dev/**'
- 'dev/setup-env.sh'
- '!docs/**'
- '!README.md'
- '!.gitignore'
- '!.github/workflows/'
- '.github/workflows/doca'

jobs:
openstack:
name: openstack-docabuild
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.build.label }} # to branch/PR + OS
cancel-in-progress: true
runs-on: ubuntu-22.04
strategy:
fail-fast: false # allow other matrix jobs to continue even if one fails
matrix: # build RL8, RL9
build:
- label: RL8
source_image_name: rocky-latest-RL8
- label: RL9
source_image_name: rocky-latest-RL9
env:
ANSIBLE_FORCE_COLOR: True
OS_CLOUD: openstack
CI_CLOUD: ${{ vars.CI_CLOUD }} # default from repo settings
ARK_PASSWORD: ${{ secrets.ARK_PASSWORD }}

steps:
- uses: actions/checkout@v2

- name: Record settings for CI cloud
run: |
echo CI_CLOUD: ${{ env.CI_CLOUD }}
- name: Setup ssh
run: |
set -x
mkdir ~/.ssh
echo "${{ secrets[format('{0}_SSH_KEY', env.CI_CLOUD)] }}" > ~/.ssh/id_rsa
chmod 0600 ~/.ssh/id_rsa
shell: bash

- name: Add bastion's ssh key to known_hosts
run: cat environments/.stackhpc/bastion_fingerprints >> ~/.ssh/known_hosts
shell: bash

- name: Install ansible etc
run: dev/setup-env.sh

- name: Write clouds.yaml
run: |
mkdir -p ~/.config/openstack/
echo "${{ secrets[format('{0}_CLOUDS_YAML', env.CI_CLOUD)] }}" > ~/.config/openstack/clouds.yaml
shell: bash

- name: Setup environment
run: |
. venv/bin/activate
. environments/.stackhpc/activate
- name: Build fat image with packer
id: packer_build
run: |
set -x
. venv/bin/activate
. environments/.stackhpc/activate
cd packer/
packer init .
PACKER_LOG=1 packer build \
-on-error=${{ vars.PACKER_ON_ERROR }} \
-var-file=$PKR_VAR_environment_root/${{ env.CI_CLOUD }}.pkrvars.hcl \
-var "source_image_name=${{ matrix.build.source_image_name }}" \
-var "image_name=openhpc-doca" \
-var "groups=doca" \
openstack.pkr.hcl
- name: Get created image names from manifest
id: manifest
run: |
. venv/bin/activate
IMAGE_ID=$(jq --raw-output '.builds[-1].artifact_id' packer/packer-manifest.json)
while ! openstack image show -f value -c name $IMAGE_ID; do
sleep 5
done
IMAGE_NAME=$(openstack image show -f value -c name $IMAGE_ID)
echo $IMAGE_ID > image-id.txt
echo $IMAGE_NAME > image-name.txt
- name: Upload manifest artifact
uses: actions/upload-artifact@v4
with:
name: image-details-openhpc-${{ matrix.label }}
path: |
./image-id.txt
./image-name.txt
overwrite: true
70 changes: 28 additions & 42 deletions packer/openstack.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data "git-commit" "cwd-head" { }
locals {
git_commit = data.git-commit.cwd-head.hash
timestamp = formatdate("YYMMDD-hhmm", timestamp())
image_name_version = var.image_name_version == "auto" ? "-${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_name_version
}

# Path pointing to root of repository - automatically set by environment variable PKR_VAR_repo_root
Expand All @@ -39,12 +40,6 @@ variable "networks" {
type = list(string)
}

variable "os_version" {
type = string
description = "'RL8' or 'RL9' with default source_image_* mappings"
default = "RL9"
}

# Must supply either source_image_name or source_image_id
variable "source_image_name" {
type = string
Expand Down Expand Up @@ -123,15 +118,6 @@ variable "volume_type" {
}

variable "volume_size" {
type = map(number)
default = {
# fat image builds, GB:
rocky-latest = 15
openhpc = 15
}
}

variable "extra_build_volume_size" {
type = number
default = 15
}
Expand All @@ -147,34 +133,35 @@ variable "metadata" {
}

variable "groups" {
type = map(list(string))
description = "Additional inventory groups (other than 'builder') to add build VM to, keyed by source name"
default = {
# fat image builds:
rocky-latest = ["update"]
openhpc = ["control", "compute", "login"]
}
type = string
description = "Comma-separated list of additional inventory groups (other than 'builder') to add build VM to"
default = "" # this is
# rocky-latest = ["update"]
# openhpc = ["control", "compute", "login"]
}

variable "extra_build_groups" {
type = list(string)
default = []
variable "image_name" {
type = string
description = "Name of image"
default = "openhpc"
}

variable "extra_build_image_name" {
variable "image_name_version" {
type = string
description = "Infix for 'extra' build image name"
default = "extra"
description = "Suffix for image name giving version. Default of 'auto' appends timestamp + short commit"
default = "auto"
}

source "openstack" "openhpc" {
# Build VM:
flavor = var.flavor
use_blockstorage_volume = var.use_blockstorage_volume
volume_type = var.volume_type
volume_size = lookup(var.volume_size, source.name, var.extra_build_volume_size)
volume_size = var.volume_size
metadata = var.metadata
instance_metadata = {ansible_init_disable = "true"}
instance_metadata = {
ansible_init_disable = "true"
}
networks = var.networks
floating_ip_network = var.floating_ip_network
security_groups = var.security_groups
Expand All @@ -201,26 +188,25 @@ source "openstack" "openhpc" {
build {

# latest nightly image:
source "source.openstack.openhpc" {
name = "rocky-latest"
image_name = "${source.name}-${var.os_version}"
}
# source "source.openstack.openhpc" {
# name = "rocky-latest"
# image_name = "${source.name}-${var.os_version}"
# }

# fat image:
source "source.openstack.openhpc" {
name = "openhpc"
image_name = "${source.name}-${var.os_version}-${local.timestamp}-${substr(local.git_commit, 0, 8)}"
image_name = "${var.image_name}${local.image_name_version}"
}

# Extended site-specific image, built on fat image:
source "source.openstack.openhpc" {
name = "openhpc-extra"
image_name = "openhpc-${var.extra_build_image_name}-${var.os_version}-${local.timestamp}-${substr(local.git_commit, 0, 8)}"
}
# # Extended site-specific image, built on fat image:
# source "source.openstack.openhpc" {
# name = "openhpc-extra"
# image_name = "openhpc-${var.extra_build_image_name}-${var.os_version}-${local.timestamp}-${substr(local.git_commit, 0, 8)}"
# }

provisioner "ansible" {
playbook_file = "${var.repo_root}/ansible/fatimage.yml"
groups = concat(["builder"], lookup(var.groups, source.name, var.extra_build_groups))
groups = concat(["builder"], split(",", var.groups))
keep_inventory_file = true # for debugging
use_proxy = false # see https://www.packer.io/docs/provisioners/ansible#troubleshooting
extra_arguments = [
Expand Down

0 comments on commit 505d5f4

Please sign in to comment.