diff --git a/templates/packer/composer.pkr.hcl b/templates/packer/composer.pkr.hcl index 9233008e1..a37af61e6 100644 --- a/templates/packer/composer.pkr.hcl +++ b/templates/packer/composer.pkr.hcl @@ -6,7 +6,7 @@ source "amazon-ebs" "image_builder" { region = var.region # Use a static RHEL 8.5 Cloud Access Image. - source_ami = "ami-06f1e6f8b3457ae7c" + source_ami = "${var.ami_id}" # Remove previous image before making the new one. force_deregister = true diff --git a/templates/packer/variables.pkr.hcl b/templates/packer/variables.pkr.hcl index 4e01a2580..01195e75e 100644 --- a/templates/packer/variables.pkr.hcl +++ b/templates/packer/variables.pkr.hcl @@ -9,6 +9,9 @@ variable "region" { default = "us-east-1" } +# Base image +variable "ami_id" { type = string } + # Automatically set by environment variables in GitHub Actions. variable "composer_commit" { type = string } variable "osbuild_commit" { type = string } diff --git a/tools/appsre-ansible/rpmbuild.yml b/tools/appsre-ansible/rpmbuild.yml index cf22b2ac7..bca0821ec 100644 --- a/tools/appsre-ansible/rpmbuild.yml +++ b/tools/appsre-ansible/rpmbuild.yml @@ -19,6 +19,11 @@ retries: 5 until: result is success + - name: Subscribe + community.general.redhat_subscription: + activationkey: "{{ RH_ACTIVATION_KEY }}" + org_id: "{{ RH_ORG_ID }}" + - name: Create rpmbuild directory file: path: "{{ item }}" diff --git a/tools/appsre-build-worker-packer.sh b/tools/appsre-build-worker-packer.sh index ce773a382..d3cf5d34a 100755 --- a/tools/appsre-build-worker-packer.sh +++ b/tools/appsre-build-worker-packer.sh @@ -6,6 +6,7 @@ set -exv COMMIT_SHA=$(git rev-parse HEAD) COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) ON_JENKINS=true +AMI_ID=ami-06f1e6f8b3457ae7c # Use gitlab CI variables if available if [ -n "$CI_COMMIT_SHA" ]; then @@ -71,7 +72,7 @@ mkdir -p "$RPMBUILD_DIR" aws ec2 create-key-pair --key-name "$KEY_NAME" --query 'KeyMaterial' --output text > /osbuild-composer/keypair.pem chmod 600 /osbuild-composer/keypair.pem -aws ec2 run-instances --image-id ami-0b0af3577fe5e3532 --instance-type c5.large --key-name "$KEY_NAME" \ +aws ec2 run-instances --image-id "$PKR_VAR_ami_id" --instance-type c5.large --key-name "$KEY_NAME" \ --tag-specifications "ResourceType=instance,Tags=[{Key=commit,Value=$COMMIT_SHA},{Key=name,Value=rpm-builder-$COMMIT_SHA}]" \ > ./rpminstance.json AWS_INSTANCE_ID=$(jq -r '.Instances[].InstanceId' "rpminstance.json") @@ -96,7 +97,9 @@ ansible-playbook \ -i /osbuild-composer/tools/appsre-ansible/inventory \ /osbuild-composer/tools/appsre-ansible/rpmbuild.yml \ -e "COMPOSER_COMMIT=$COMMIT_SHA" \ - -e "OSBUILD_COMMIT=$(jq -r '.["rhel-8.4"].dependencies.osbuild.commit' /osbuild-composer/Schutzfile)" + -e "OSBUILD_COMMIT=$(jq -r '.["rhel-8.5"].dependencies.osbuild.commit' /osbuild-composer/Schutzfile)" \ + -e "RH_ACTIVATION_KEY=$RH_ACTIVATION_KEY" \ + -e "RH_ORG_ID=$RH_ORG_ID" EOF } @@ -138,7 +141,10 @@ $CONTAINER_RUNTIME run --rm \ -e COMMIT_SHA="$COMMIT_SHA" \ -e ON_JENKINS="$ON_JENKINS" \ -e PACKER_IMAGE_USERS="$PACKER_IMAGE_USERS" \ + -e RH_ACTIVATION_KEY="$RH_ACTIVATION_KEY" \ + -e RH_ORG_ID="$RH_ORG_ID" \ -e PKR_VAR_aws_access_key="$PACKER_AWS_ACCESS_KEY_ID" \ + -e PKR_VAR_ami_id="$AMI_ID" \ -e PKR_VAR_aws_secret_key="$PACKER_AWS_SECRET_ACCESS_KEY" \ -e PKR_VAR_image_name="osbuild-composer-worker-$COMMIT_BRANCH-$COMMIT_SHA" \ -e PKR_VAR_composer_commit="$COMMIT_SHA" \