Skip to content

Commit

Permalink
deploy infrastructure: name PR releases using a timestamp
Browse files Browse the repository at this point in the history
To make it clear to users when the PR contents has changed
  • Loading branch information
chrisandreae committed Dec 9, 2023
1 parent b96441a commit 1488522
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ jobs:
shell: bash
run: |
if [ "$GITHUB_HEAD_REF" ]; then
type="pr"
tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}"
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
type="tag"
tag="${GITHUB_REF#refs/tags/}"
else
echo "Not a pull request or release tag" >&2
exit 1
fi
# Replace / with . in container tag names
tag="${tag//\//.}"
echo "CONTAINER_NAME=${tag}" >> $GITHUB_ENV
echo "VERSION_TYPE=${type}" >> $GITHUB_ENV
echo "VERSION_NAME=${tag}" >> $GITHUB_ENV
id: extract_name
- name: Login to Amazon ECR
id: login-ecr
Expand Down Expand Up @@ -77,15 +80,25 @@ jobs:
digest="$(docker inspect --format='{{index .RepoDigests 0}}' $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG)"
digest="${digest##*@}"
api_version="$(cat lambda/api_version.txt)"
timestamp="$(date -u +"%Y%m%d.%H%M%S")"
if [ "$VERSION_TYPE" = "pr" ]; then
release_name="$VERSION_NAME.$timestamp"
else
release_name="$VERSION_NAME"
fi
jq -n '$ARGS.named' \
--arg name "$CONTAINER_NAME" \
--arg revision "$REVISION_TAG" \
--arg branch "$GITHUB_REF" \
--arg digest "$digest" \
--arg api_version "$api_version" \
> "/tmp/$CONTAINER_NAME.json"
--arg name "$release_name" \
--arg version_name "$VERSION_NAME" \
--arg revision "$REVISION_TAG" \
--arg release_time "$timestamp" \
--arg branch "$GITHUB_REF" \
--arg digest "$digest" \
--arg api_version "$api_version" \
> "/tmp/$VERSION_NAME.json"
- name: Upload image metadata file to versions bucket
run: aws s3 cp "/tmp/$CONTAINER_NAME.json" "s3://$VERSIONS_BUCKET/images/$CONTAINER_NAME.json"
run: aws s3 cp "/tmp/$VERSION_NAME.json" "s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json"
- name: Notify the build pipeline that the compile containers have updated
run: >-
aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cleanup-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}"
# Replace / with . in container tag names
tag="${tag//\//.}"
echo "CONTAINER_NAME=${tag}" >> $GITHUB_ENV
echo "VERSION_NAME=${tag}" >> $GITHUB_ENV
id: extract_name
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder
aws-region: us-east-1
- name: Delete the image metadata file from the versions s3 bucket
run: aws s3 rm s3://$VERSIONS_BUCKET/images/$CONTAINER_NAME.json
run: aws s3 rm s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json
- name: Notify the build pipeline that the compile containers have updated
run: >-
aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION
Expand Down

0 comments on commit 1488522

Please sign in to comment.