Skip to content

Commit 7bf10f9

Browse files
authored
Merge branch 'awslabs:main' into fix-awslabs#31
2 parents 056abbb + 2b07c2d commit 7bf10f9

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

buildspecs/buildspec.canary.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ phases:
1717
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
1818
build:
1919
commands:
20-
# install the latest patch version of 3.1
21-
- curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 3.1
22-
- dotnet --version
23-
- dotnet nuget --version
20+
- ./scripts/install-dotnet.sh
2421
- ./scripts/deploy-canary.sh

buildspecs/buildspec.release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ env:
44
variables:
55
AWS_REGION: us-west-2
66
parameter-store:
7-
NUGET_API_KEY: NuGetAPIKey
7+
ROLE_ARN: NugetCrossAccountArn
8+
SECRET_ARN: SecretArnNuget
89
phases:
910
install:
1011
runtime-versions:
1112
dotnet: 3.1
1213
build:
1314
commands:
14-
# install the latest patch version of 3.1
15-
- curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 3.1
16-
- dotnet --version
17-
- dotnet nuget --version
15+
- ./scripts/install-dotnet.sh
1816
- dotnet restore
1917
- ./scripts/publish-package.sh

buildspecs/buildspec.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ phases:
1717
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
1818
build:
1919
commands:
20-
# install the latest patch version of 3.1
21-
- curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 3.1
22-
- dotnet --version
23-
- dotnet nuget --version
20+
- ./scripts/install-dotnet.sh
2421
- pwd && ./scripts/start-agent.sh
2522
- dotnet restore
2623
- dotnet build

scripts/install-dotnet.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# print command before they are executed without expanding variables
3+
set -v
4+
5+
# install the latest patch version of 3.1
6+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -c 3.1
7+
dotnet --version
8+
dotnet nuget --version

scripts/publish-package.sh

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
#!/usr/bin/env bash
2-
#
3-
# Run integration tests against a CW Agent.
4-
#
5-
# usage:
6-
# export AWS_ACCESS_KEY_ID=
7-
# export AWS_SECRET_ACCESS_KEY=
8-
# export AWS_REGION=us-west-2
9-
# ./start-agent.sh
102

11-
source ./utils.sh
3+
scripts_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
4+
source "$scripts_dir"/utils.sh
5+
6+
NUGET_API_KEY=""
7+
8+
function assume_role_and_get_key() {
9+
ROLE_ARN=$1
10+
OUTPUT_PROFILE="publishing-profile"
11+
echo "Assuming role $ROLE_ARN"
12+
sts=$(aws sts assume-role \
13+
--role-arn "$ROLE_ARN" \
14+
--role-session-name "$OUTPUT_PROFILE" \
15+
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \
16+
--output text)
17+
check_exit
18+
sts=($sts)
19+
aws configure set aws_access_key_id "${sts[0]}" --profile "$OUTPUT_PROFILE"
20+
aws configure set aws_secret_access_key "${sts[1]}" --profile "$OUTPUT_PROFILE"
21+
aws configure set aws_session_token "${sts[2]}" --profile "$OUTPUT_PROFILE"
22+
echo "Credentials stored in the profile named $OUTPUT_PROFILE"
23+
24+
NUGET_API_KEY=$(aws secretsmanager \
25+
--profile "$OUTPUT_PROFILE" \
26+
get-secret-value \
27+
--secret-id "$SECRET_ARN" \
28+
| jq '.SecretString | fromjson.Key' | tr -d '"')
29+
check_exit
30+
}
1231

1332
# publish <package-name>
1433
function publish() {
@@ -26,6 +45,8 @@ function publish() {
2645
popd
2746
}
2847

48+
assume_role_and_get_key "$ROLE_ARN"
49+
2950
validate "$NUGET_API_KEY" "NUGET_API_KEY"
3051
validate "$CODEBUILD_BUILD_NUMBER" "CODEBUILD_BUILD_NUMBER"
3152

scripts/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env zsh
1+
#!/usr/bin/env bash
22

33
function check_exit() {
44
last_exit_code=$?

0 commit comments

Comments
 (0)