Skip to content

Commit

Permalink
Build once upfront in Lambda templates (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c authored Jul 13, 2021
1 parent df2d5d3 commit 5b09594
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .changeset/tricky-badgers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skuba': patch
---

**template/lambda-sqs-worker-\*:** Build once upfront

This employs Buildkite [artifacts](https://buildkite.com/docs/pipelines/artifacts) to share compiled code with each subsequent deployment step.
38 changes: 19 additions & 19 deletions template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ configs:
- &dev
agents:
queue: <%- devBuildkiteQueueName %>
env:
ENVIRONMENT: dev

- &prod
agents:
queue: <%- prodBuildkiteQueueName %>
env:
ENVIRONMENT: prod

plugins:
- &aws-sm
seek-oss/aws-sm#v2.3.1:
env:
NPM_READ_TOKEN: arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token

- &docker
docker#v3.8.0:
volumes:
- /workdir/lib
- /workdir/node_modules

- &docker-ecr-cache
seek-oss/docker-ecr-cache#v1.11.0:
cache-on:
Expand All @@ -33,12 +31,20 @@ configs:

base-steps:
- &deploy
commands:
- echo '+++ yarn deploy'
- yarn deploy
concurrency: 1
plugins:
- artifacts#v1.3.0:
build: ${BUILDKITE_BUILD_ID}
download: lib/*
- *aws-sm
- *private-npm
- *docker-ecr-cache
- *docker
- docker-compose#v3.7.0:
dependencies: false
run: app
retry:
manual:
# Only use this if you need to roll back a deployment ASAP.
Expand All @@ -47,17 +53,21 @@ configs:

steps:
- <<: *dev
label: 🧪 Test & Lint
label: 🧪 Test, Lint & Build
artifact_paths: lib/**/*
commands:
- echo '+++ yarn test:ci'
- yarn test
- echo '--- yarn lint'
- yarn lint
- echo '--- yarn build'
- yarn build
plugins:
- *aws-sm
- *private-npm
- *docker-ecr-cache
- *docker
- docker-compose#v3.7.0:
run: app

- wait
- block: 🙋🏻‍♀️ Deploy Dev
Expand All @@ -66,22 +76,12 @@ steps:
- <<: *dev
<<: *deploy
label: 🤞 Deploy Dev
commands:
- echo '--- yarn build'
- yarn build
- echo '+++ yarn deploy:dev'
- yarn deploy:dev
concurrency_group: '<%- repoName %>/deploy/dev'
key: deploy-dev

- <<: *prod
<<: *deploy
label: 🚀 Deploy Prod
branches: ${BUILDKITE_PIPELINE_DEFAULT_BRANCH}
commands:
- echo '--- yarn build'
- yarn build
- echo '+++ yarn deploy:prod'
- yarn deploy:prod
concurrency_group: '<%- repoName %>/deploy/prod'
depends_on: deploy-dev
14 changes: 14 additions & 0 deletions template/lambda-sqs-worker-cdk/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:
app:
environment:
- BUILDKITE_COMMIT
- ENVIRONMENT
- VERSION
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
- ./:/workdir
- /workdir/lib/node_modules
- /workdir/node_modules
7 changes: 3 additions & 4 deletions template/lambda-sqs-worker-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
},
"scripts": {
"build": "skuba build",
"deploy": "cdk deploy appStack --require-approval never --context stage=${ENVIRONMENT}",
"format": "skuba format",
"lint": "skuba lint",
"package": "yarn install --ignore-optional --ignore-scripts --modules-folder ./lib/node_modules --non-interactive --offline --production",
"test": "skuba test",
"test:ci": "skuba test --coverage",
"test:watch": "skuba test --watch",
"package": "yarn install --ignore-optional --ignore-scripts --modules-folder ./lib/node_modules --non-interactive --offline --production",
"deploy:dev": "cdk deploy appStack --require-approval never --context stage=dev",
"deploy:prod": "cdk deploy appStack --require-approval never --context stage=prod"
"test:watch": "skuba test --watch"
}
}
13 changes: 10 additions & 3 deletions template/lambda-sqs-worker/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ configs:

base-steps:
- &deploy
commands:
- echo '+++ yarn deploy'
- yarn deploy
concurrency: 1
plugins:
- artifacts#v1.3.0:
build: ${BUILDKITE_BUILD_ID}
download: lib/*
- *aws-sm
- *private-npm
- *docker-ecr-cache
Expand All @@ -50,12 +56,15 @@ configs:

steps:
- <<: *prod
label: 🧪 Test & Lint
label: 🧪 Test, Lint & Build
artifact_paths: lib/**/*
commands:
- echo '+++ yarn test:ci'
- yarn test:ci
- echo '--- yarn lint'
- yarn lint
- echo '--- yarn build'
- yarn build
plugins:
- *aws-sm
- *private-npm
Expand All @@ -69,7 +78,6 @@ steps:

- <<: *dev
<<: *deploy
command: yarn deploy
concurrency_group: <%- repoName %>/deploy/dev
label: 🤞 Deploy Dev

Expand All @@ -78,6 +86,5 @@ steps:
- <<: *prod
<<: *deploy
branches: ${BUILDKITE_PIPELINE_DEFAULT_BRANCH}
command: yarn deploy
concurrency_group: <%- repoName %>/deploy/prod
label: 🚀 Deploy Prod
2 changes: 1 addition & 1 deletion template/lambda-sqs-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"build": "skuba build",
"deploy": "yarn build && serverless deploy --force --verbose",
"deploy": "serverless deploy --force --verbose",
"format": "skuba format",
"lint": "skuba lint",
"smoke": "serverless invoke --data '{}' --function Worker",
Expand Down

0 comments on commit 5b09594

Please sign in to comment.