Skip to content

Commit de88b59

Browse files
committed
CI: inline AWS image taging script
The pipeline had been using a single script from https://github.com/cloudfoundry/bosh-stemcells-ci/, namely `tasks/light-aws/tag-aws-ami-light.{sh,yml}` to apply tags to AWS images in order to mark them as published. This commit inlines the files `tasks/light-aws/tag-aws-ami-light.{sh,yml}` as `ci/tasks/aws-tag-image/{run.sh,task.sh}` with some small cleanups.
1 parent 4d737bd commit de88b59

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

ci/pipelines/stemcells-windows.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ resources:
139139
- ci/docker/Dockerfile
140140
username: bosh-admin-bot
141141
password: ((github_public_repo_token))
142-
- name: bosh-stemcells-ci
143-
type: git
144-
source:
145-
branch: master
146-
uri: https://github.com/cloudfoundry/bosh-stemcells-ci
147142
- name: golang-release
148143
type: git
149144
source:
@@ -2188,7 +2183,6 @@ jobs:
21882183
passed: [promote]
21892184
- get: aws-govcloud-tested
21902185
passed: [promote]
2191-
- get: bosh-stemcells-ci
21922186
- get: stemcell-builder
21932187
passed: [promote]
21942188
- get: version
@@ -2249,7 +2243,7 @@ jobs:
22492243
file: bosh-windows-stemcell-builder-ci/ci/tasks/set-stemcell-version/task.yml
22502244
image: bosh-windows-stemcell-builder-ci-image
22512245
- task: tag-published-aws-ami-light-stemcells
2252-
file: bosh-stemcells-ci/tasks/light-aws/tag-aws-ami-light.yml
2246+
file: bosh-windows-stemcell-builder-ci/ci/tasks/aws-tag-image/task.yml
22532247
image: bosh-windows-stemcell-builder-ci-image
22542248
input_mapping:
22552249
candidate-aws-light-stemcell: final-stemcell
@@ -2259,7 +2253,7 @@ jobs:
22592253
AWS_SECRET_ACCESS_KEY: ((aws-stemcells_aws_access_key.password))
22602254
GREP_PATTERN: grep -v 'gov-\|cn-'
22612255
- task: tag-gov-published-aws-ami-light-stemcells
2262-
file: bosh-stemcells-ci/tasks/light-aws/tag-aws-ami-light.yml
2256+
file: bosh-windows-stemcell-builder-ci/ci/tasks/aws-tag-image/task.yml
22632257
image: bosh-windows-stemcell-builder-ci-image
22642258
input_mapping:
22652259
candidate-aws-light-stemcell: final-stemcell

ci/tasks/aws-tag-image/run.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
if [ -n "${AWS_ROLE_ARN}" ]; then
5+
aws configure --profile creds_account set aws_access_key_id "${AWS_ACCESS_KEY_ID}"
6+
aws configure --profile creds_account set aws_secret_access_key "${AWS_SECRET_ACCESS_KEY}"
7+
aws configure --profile resource_account set source_profile "creds_account"
8+
aws configure --profile resource_account set role_arn "${AWS_ROLE_ARN}"
9+
unset AWS_ACCESS_KEY_ID
10+
unset AWS_SECRET_ACCESS_KEY
11+
export AWS_PROFILE=resource_account
12+
fi
13+
14+
set -x
15+
16+
cd candidate-aws-light-stemcell
17+
18+
tar -xzf ./*.tgz stemcell.MF
19+
AMI_LIST=$(grep ami- stemcell.MF | tr -d ' ')
20+
if [ -n "${GREP_PATTERN}" ]; then
21+
AMI_LIST=$(echo "${AMI_LIST}" | eval "${GREP_PATTERN}")
22+
fi
23+
OS=$(grep "operating_system" stemcell.MF | cut -f2 -d: | tr -d ' ')
24+
VERSION=$(grep "^version" stemcell.MF | cut -f2 -d: | tr -d ' ' | tr -d "'")
25+
26+
for AMI_LINE in ${AMI_LIST}; do
27+
AMI_REGION=$(echo "${AMI_LINE}" | cut -f1 -d:)
28+
AMI_ID=$(echo "${AMI_LINE}" | cut -f2 -d:)
29+
30+
TAGS="[
31+
{ \"Key\": \"published\", \"Value\": \"true\" },
32+
{ \"Key\": \"name\" , \"Value\": \"${OS}-${VERSION}\" },
33+
{ \"Key\": \"distro\" , \"Value\": \"${OS}\" },
34+
{ \"Key\": \"version\" , \"Value\": \"${VERSION}\" }
35+
]"
36+
37+
aws ec2 create-tags --resources "${AMI_ID}" --region "${AMI_REGION}" --tags "${TAGS}"
38+
done

ci/tasks/aws-tag-image/task.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
platform: linux
3+
4+
inputs:
5+
- name: bosh-windows-stemcell-builder-ci
6+
- name: candidate-aws-light-stemcell
7+
8+
run:
9+
path: bosh-windows-stemcell-builder-ci/ci/tasks/aws-tag-image/run.sh
10+
11+
params:
12+
AWS_ROLE_ARN:
13+
AWS_ACCESS_KEY_ID:
14+
AWS_SECRET_ACCESS_KEY:
15+
GREP_PATTERN:

0 commit comments

Comments
 (0)