Skip to content

Commit

Permalink
feat(CI aws): make aws-packer-build.sh standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Jul 15, 2024
1 parent 18a0927 commit d52e5a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
5 changes: 3 additions & 2 deletions .github/scripts/aws-new-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ set -x
# Assign default values if parameters are not provided
TECHNO="${1:-sev}"
DISTRIB="${2:-ubuntu}"
PREFIX="${3:-$(whoami)}"
PREFIX=$(echo "$PREFIX" | sed 's/\./-/g; s/_/-/g; s/+/-/g')

WHO="$(whoami)"
NAME="$WHO-$TECHNO-$DISTRIB"
NAME="$PREFIX-$TECHNO-$DISTRIB"

CI_INSTANCES=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${NAME}" --query 'Reservations[].Instances[].[InstanceId]' --output text)
for instance in $CI_INSTANCES; do
Expand Down
33 changes: 29 additions & 4 deletions .github/scripts/aws-packer-build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
#!/bin/sh
#!/bin/bash

# Only for testing, DO NOT UNCOMMENT
# DISTRIBUTION=rhel
# PRODUCT=cosmian-vm
# VERSION=0.1.5 # Optional
# KMS_VERSION=4.17.0 # Provided by Github workflow
# AI_RUNNER_VERSION=0.3.0 # Provided by Github workflow
# GITHUB_REF=refs/tags/1.2.5 # Provided by Github Actions
# GITHUB_REF_NAME=1.2.5 # Provided by Github Actions
# IMAGE_NAME="cosmian-vm-${GITHUB_REF_NAME}-sev-${DISTRIBUTION}" # Only for testing

set -ex

PRODUCT=$1
DISTRIBUTION=$2
SOURCE_AMI=$3
if [[ ${GITHUB_REF} = *'refs/tags/'* ]]; then
export COSMIAN_VM_VERSION="$GITHUB_REF_NAME"
else
export COSMIAN_VM_VERSION="last_build/${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
fi

if [ -n "${VERSION+x}" ]; then
BASE_VERSION=$(echo "$VERSION" | sed 's/\./-/g; s/_/-/g; s/+/-/g')
BASE_IMAGE_NAME="base-image-${BASE_VERSION}-${DISTRIBUTION}-sev"
else
if [ "$DISTRIBUTION" = "ubuntu" ]; then
BASE_IMAGE_NAME="ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20240523.1"
else
BASE_IMAGE_NAME="RHEL-9.3.0_HVM-20240117-x86_64-49-Hourly2-GP3"
fi
fi

SOURCE_AMI=$(aws ec2 describe-images --filters "Name=name,Values=${BASE_IMAGE_NAME}" --query "Images[*].{ID:ImageId}" --output text)

VOLUME_SIZE=20

Expand Down
17 changes: 3 additions & 14 deletions .github/workflows/aws_base_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,7 @@ jobs:
env:
PACKER_GITHUB_API_TOKEN: ${{ secrets.PACKER_GITHUB_TOKEN }}
IMAGE_NAME: ${{ steps.env.outputs.IMAGE_NAME }}
PRODUCT: ${{ inputs.product }}
DISTRIBUTION: ${{ inputs.distrib }}
run: |
set -ex
if [[ ${GITHUB_REF} = *'refs/tags/'* ]]; then
export COSMIAN_VM_VERSION="${{ github.ref_name }}"
else
export COSMIAN_VM_VERSION="last_build/${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
fi
if [ "${{ inputs.distrib }}" = "ubuntu" ]; then
export AMI=$(aws ec2 describe-images --filters "Name=name,Values=ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20240523.1" --query "Images[*].{ID:ImageId}" --output text)
else
export AMI=$(aws ec2 describe-images --filters "Name=name,Values=RHEL-9.3.0_HVM-20240117-x86_64-49-Hourly2-GP3" --query "Images[*].{ID:ImageId}" --output text)
fi
bash ../.github/scripts/aws-packer-build.sh "${{ inputs.product }}" "${{ inputs.distrib }}" "$AMI"
bash ../.github/scripts/aws-packer-build.sh
19 changes: 3 additions & 16 deletions .github/workflows/aws_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,10 @@ jobs:
KMS_VERSION: ${{ inputs.kms-version }}
AI_RUNNER_VERSION: ${{ inputs.ai-runner-version }}
VERSION: ${{ inputs.base-version }}
PRODUCT: ${{ inputs.product }}
DISTRIBUTION: ${{ inputs.distrib }}
run: |
set -ex
BASE_VERSION=$(echo $VERSION | sed 's/\./-/g; s/_/-/g; s/+/-/g')
if [[ ${GITHUB_REF} = *'refs/tags/'* ]]; then
export COSMIAN_VM_VERSION="${{ github.ref_name }}"
else
export COSMIAN_VM_VERSION="last_build/${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
fi
if [ "${{ inputs.distrib }}" = "ubuntu" ]; then
export AMI=$(aws ec2 describe-images --filters "Name=name,Values=base-image-${BASE_VERSION}-ubuntu-sev" --query "Images[*].{ID:ImageId}" --output text)
else
export AMI=$(aws ec2 describe-images --filters "Name=name,Values=base-image-${BASE_VERSION}-rhel-sev" --query "Images[*].{ID:ImageId}" --output text)
fi
bash ../.github/scripts/aws-packer-build.sh "${{ inputs.product }}" "${{ inputs.distrib }}" "$AMI"
bash ../.github/scripts/aws-packer-build.sh
test-image:
name: Test image - ${{ inputs.distrib }} - ${{ inputs.techno }} - ${{ inputs.product }}
Expand Down

0 comments on commit d52e5a5

Please sign in to comment.