Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amazon: Enhance AMI name and tags #405

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/build.yaml.gomplate
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,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 }}}
{{{ end }}}
Expand Down Expand Up @@ -528,6 +529,6 @@ jobs:
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Upload and publish vanilla image
run: |
export github_sha="${GITHUB_SHA}"
export git_sha="${GITHUB_SHA}"
make aws_vanilla_ami
{{{ end }}}
3 changes: 2 additions & 1 deletion .github/workflows/build-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,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 @@ -1082,6 +1083,6 @@ jobs:
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Upload and publish vanilla image
run: |
export github_sha="${GITHUB_SHA}"
export git_sha="${GITHUB_SHA}"
make aws_vanilla_ami

6 changes: 3 additions & 3 deletions images/aws_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ disk="$1"
s3_bucket="cos-images"
disk_name="cOS-Vanilla"
disk_desc="cOS Vanilla Image"
: "${github_sha:=none}"
: "${git_sha:=none}"

[ -f "${disk}" ] || exit 1

Expand Down Expand Up @@ -40,7 +40,7 @@ snap_id=$(aws ec2 describe-import-snapshot-tasks \

echo "Tagging Snapshot"
aws ec2 create-tags --resources "${snap_id}" \
--tags Key=Name,Value=${disk_name} Key=Project,Value=cOS Key=GITHUB_SHA,Value=$github_sha
--tags Key=Name,Value=${disk_name} Key=Project,Value=cOS Key=Git_SHA,Value=$git_sha Key=Flavor,Value=cos-vanilla

echo "Register AMI from snapshot"
ami_id=$(aws ec2 register-image \
Expand All @@ -56,6 +56,6 @@ ami_id=$(aws ec2 register-image \

echo "Tagging AMI"
aws ec2 create-tags --resources "${ami_id}" --tags \
--tags Key=Name,Value=${disk_name} Key=Project,Value=cOS Key=GITHUB_SHA,Value=$github_sha
--tags Key=Name,Value=${disk_name} Key=Project,Value=cOS Key=Git_SHA,Value=$git_sha Key=Flavor,Value=cos-vanilla

echo "AMI Created: ${ami_id}"
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 @@ -147,3 +147,9 @@ variable "name" {
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."
}