Skip to content

Commit

Permalink
Abstract regions, account numbers and tags from buildspec (#365)
Browse files Browse the repository at this point in the history
* Abstract regions, account numbers and tags from buildspec

* Add comment on defaults
  • Loading branch information
Adam-C-Mitchell authored Oct 9, 2024
1 parent a861e46 commit 6f36a24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
20 changes: 15 additions & 5 deletions .codepipeline/buildspec-govuk-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ version: 0.2
phases:
pre_build:
commands:
- echo Checking out to govuk_${ENVIRONMENT}_latest tag...
- git checkout tags/govuk_${ENVIRONMENT}_latest
- |
if [ -n "$COMMIT_ID" ]; then
echo Checking out to govuk_${ENVIRONMENT}_latest tag...
git checkout tags/govuk_${ENVIRONMENT}_latest
fi
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS
--password-stdin $ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com
build:
commands:
- COMMIT_ID=$(echo $COMMIT_ID | cut -c 1-7)
- |
TAGS="-t $REPOSITORY_URI:latest -t $REPOSITORY_URI:pipeline_$EXECUTION_ID"
if [ -n "$COMMIT_ID" ]; then
COMMIT_ID=$(echo $COMMIT_ID | cut -c 1-7)
TAGS="$TAGS -t $REPOSITORY_URI:commit_$COMMIT_ID"
fi
- echo Build started on `date`
- echo Building Docker image...
- docker build -t $REPOSITORY_URI:latest -t $REPOSITORY_URI:pipeline_$EXECUTION_ID -t $REPOSITORY_URI:commit_$COMMIT_ID
-f Dockerfile.eas-govuk-alerts --build-arg ECS_ACCOUNT_NUMBER=$ACCOUNT_NUMBER --build-arg RESOURCE_PREFIX=${RESOURCE_PREFIX:-eas-app} --no-cache .
- docker build $TAGS -f Dockerfile.eas-govuk-alerts
--build-arg ECS_ACCOUNT_NUMBER=$ACCOUNT_NUMBER
--build-arg AWS_REGION=${AWS_REGION:-eu-west-2}
--build-arg RESOURCE_PREFIX=${RESOURCE_PREFIX:-eas-app} --no-cache .
post_build:
commands:
- echo Building complete on `date`
Expand Down
7 changes: 5 additions & 2 deletions .codepipeline/buildspec-govuk-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ version: 0.2
phases:
pre_build:
commands:
- echo Checking out to govuk_${ENVIRONMENT}_latest tag...
- git checkout tags/govuk_${ENVIRONMENT}_latest
- |
if [ -n "$COMMIT_ID" ]; then
echo Checking out to govuk_${ENVIRONMENT}_latest tag...
git checkout tags/govuk_${ENVIRONMENT}_latest
fi
build:
commands:
- echo Deployment started on `date`
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.eas-govuk-alerts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Sensible defaults, but they will be explicitly overridden in the context of a buildspec anyway.
# The only one that needs to be passed in however is the ECS_ACCOUNT_NUMBER, as this changes per environment.
ARG ECS_ACCOUNT_NUMBER
ARG RESOURCE_PREFIX=eas-app
ARG AWS_REGION=eu-west-2
ARG BASE_VERSION=latest
FROM ${ECS_ACCOUNT_NUMBER}.dkr.ecr.eu-west-2.amazonaws.com/${RESOURCE_PREFIX}-base:${BASE_VERSION}
FROM ${ECS_ACCOUNT_NUMBER}.dkr.ecr.${AWS_REGION}.amazonaws.com/${RESOURCE_PREFIX}-base:${BASE_VERSION}

ENV SERVICE=govuk-alerts
ENV FLASK_APP=app.py
Expand Down

0 comments on commit 6f36a24

Please sign in to comment.