Skip to content

Commit

Permalink
amazon: Enhance AMI name and tags
Browse files Browse the repository at this point in the history
This patch adds the github.sha to the build name of the AMI so we can
easily identify where the image came from if pushed from CI and to be
able to upload more than one image per day on CI as well.

Also adds it to the tags, and add a new Flavor tag, so we can use data
lifecycle policies to auto remove images and search for an X flavor by
using those tags.

The default value for no git_sha is none.

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Jul 13, 2021
1 parent ad90b97 commit 4a8af67
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/build.yaml.gomplate
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ jobs:
export PKR_VAR_cos_version="${COS_VERSION}"
export PKR_VAR_aws_cos_install_args="cos-deploy {{{ if (ne $flavor "opensuse") }}}--no-verify {{{ end }}}--docker-image quay.io/costoolkit/{{{$config.repository}}}-{{{ $flavor }}}:cos-system-${COS_VERSION}"
export PKR_VAR_flavor={{{ $flavor }}}
export PKR_VAR_git_sha="${GITHUB_SHA}"
make packer-aws

{{{ end }}}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ jobs:
export PKR_VAR_cos_version="${COS_VERSION}"
export PKR_VAR_aws_cos_install_args="cos-deploy --docker-image quay.io/costoolkit/releases-opensuse:cos-system-${COS_VERSION}"
export PKR_VAR_flavor=opensuse
export PKR_VAR_git_sha="${GITHUB_SHA}"
make packer-aws
Expand Down Expand Up @@ -857,6 +858,7 @@ jobs:
export PKR_VAR_cos_version="${COS_VERSION}"
export PKR_VAR_aws_cos_install_args="cos-deploy --no-verify --docker-image quay.io/costoolkit/releases-fedora:cos-system-${COS_VERSION}"
export PKR_VAR_flavor=fedora
export PKR_VAR_git_sha="${GITHUB_SHA}"
make packer-aws
Expand Down Expand Up @@ -1095,6 +1097,7 @@ jobs:
export PKR_VAR_cos_version="${COS_VERSION}"
export PKR_VAR_aws_cos_install_args="cos-deploy --no-verify --docker-image quay.io/costoolkit/releases-ubuntu:cos-system-${COS_VERSION}"
export PKR_VAR_flavor=ubuntu
export PKR_VAR_git_sha="${GITHUB_SHA}"
make packer-aws
Expand Down
6 changes: 4 additions & 2 deletions packer/images.json.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "amazon-ebs" "cos" {
access_key = var.aws_access_key
ami_name = "${var.name}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${var.flavor}"
ami_description = "${var.name}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${var.flavor}"
ami_name = "${var.name}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${substr(var.git_sha, 0, 7)}-${var.flavor}"
ami_description = "${var.name}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${substr(var.git_sha, 0, 7)}-${var.flavor}"
ami_groups = var.aws_ami_groups
instance_type = var.aws_instance_type
region = var.aws_region
Expand All @@ -25,6 +25,8 @@ source "amazon-ebs" "cos" {
tags = {
Name = var.name
Version = var.cos_version
Flavor = var.flavor
Git_SHA = var.git_sha # use full sha here
Base_AMI_ID = "{{ .SourceAMI }}" # This info comes from the build process directly
Base_AMI_Name = "{{ .SourceAMIName }}" # This info comes from the build process directly
}
Expand Down
6 changes: 6 additions & 0 deletions packer/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ variable "name" {
type = string
default = "cOS"
description = "Name of the product being built. Only used for naming artifacts."
}

variable "git_sha" {
type = string
default ="none"
description = "Git sha of the current build, defaults to none."
}

0 comments on commit 4a8af67

Please sign in to comment.