diff --git a/templates/packer/variables.pkr.hcl b/templates/packer/variables.pkr.hcl index 9e381ad33..034c55675 100644 --- a/templates/packer/variables.pkr.hcl +++ b/templates/packer/variables.pkr.hcl @@ -18,6 +18,12 @@ variable "region" { # Automatically set by environment variables variable "composer_commit" { type = string } +# Controls whether AMIs should be created. If you just need to test whether the image can be built, leave it as true +variable "skip_create_ami" { + type = bool + default = true +} + # The name of the resulting AMI and the underlying EBS snapshot variable "image_name" { type = string } # A list of users to share the AMI with diff --git a/templates/packer/worker.pkr.hcl b/templates/packer/worker.pkr.hcl index b3372b3ea..5524fd312 100644 --- a/templates/packer/worker.pkr.hcl +++ b/templates/packer/worker.pkr.hcl @@ -20,6 +20,8 @@ source "amazon-ebs" "image_builder" { # Network configuration for the instance building our image. associate_public_ip_address = true ssh_interface = "public_ip" + + skip_create_ami=var.skip_create_ami } build { diff --git a/tools/appsre-build-worker-packer.sh b/tools/appsre-build-worker-packer.sh index 6c1008e21..41192384b 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 +SKIP_CREATE_AMI=false # Use gitlab CI variables if available if [ -n "$CI_COMMIT_SHA" ]; then @@ -23,6 +24,11 @@ if [ "$ON_JENKINS" = false ]; then sudo dnf install -y podman jq fi +# skip creating AMIs on PRs to save a ton of resources +if [[ $COMMIT_BRANCH == PR-* ]]; then + SKIP_CREATE_AMI=true +fi + # decide whether podman or docker should be used if which podman 2>/dev/null >&2; then CONTAINER_RUNTIME=podman @@ -202,4 +208,5 @@ $CONTAINER_RUNTIME run --rm \ -e PKR_VAR_image_name="osbuild-composer-worker-$COMMIT_BRANCH-$COMMIT_SHA" \ -e PKR_VAR_composer_commit="$COMMIT_SHA" \ -e PKR_VAR_ansible_skip_tags="$SKIP_TAGS" \ + -e PKR_VAR_skip_create_ami="$SKIP_CREATE_AMI" \ "packer:$COMMIT_SHA" /osbuild-composer/worker-packer.sh