diff --git a/.changeset/tricky-badgers-tell.md b/.changeset/tricky-badgers-tell.md new file mode 100644 index 000000000..b95923e97 --- /dev/null +++ b/.changeset/tricky-badgers-tell.md @@ -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. diff --git a/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml b/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml index 321af124b..b584ba2b3 100644 --- a/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +++ b/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml @@ -3,10 +3,14 @@ configs: - &dev agents: queue: <%- devBuildkiteQueueName %> + env: + ENVIRONMENT: dev - &prod agents: queue: <%- prodBuildkiteQueueName %> + env: + ENVIRONMENT: prod plugins: - &aws-sm @@ -14,12 +18,6 @@ configs: 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: @@ -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. @@ -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 @@ -66,11 +76,6 @@ 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 @@ -78,10 +83,5 @@ steps: <<: *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 diff --git a/template/lambda-sqs-worker-cdk/docker-compose.yml b/template/lambda-sqs-worker-cdk/docker-compose.yml new file mode 100644 index 000000000..46bfc4b61 --- /dev/null +++ b/template/lambda-sqs-worker-cdk/docker-compose.yml @@ -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 diff --git a/template/lambda-sqs-worker-cdk/package.json b/template/lambda-sqs-worker-cdk/package.json index 1bbe2f5fa..62a889642 100644 --- a/template/lambda-sqs-worker-cdk/package.json +++ b/template/lambda-sqs-worker-cdk/package.json @@ -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" } } diff --git a/template/lambda-sqs-worker/.buildkite/pipeline.yml b/template/lambda-sqs-worker/.buildkite/pipeline.yml index 2087cbed0..e00543dc3 100644 --- a/template/lambda-sqs-worker/.buildkite/pipeline.yml +++ b/template/lambda-sqs-worker/.buildkite/pipeline.yml @@ -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 @@ -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 @@ -69,7 +78,6 @@ steps: - <<: *dev <<: *deploy - command: yarn deploy concurrency_group: <%- repoName %>/deploy/dev label: ๐Ÿคž Deploy Dev @@ -78,6 +86,5 @@ steps: - <<: *prod <<: *deploy branches: ${BUILDKITE_PIPELINE_DEFAULT_BRANCH} - command: yarn deploy concurrency_group: <%- repoName %>/deploy/prod label: ๐Ÿš€ Deploy Prod diff --git a/template/lambda-sqs-worker/package.json b/template/lambda-sqs-worker/package.json index de38ae836..7bdcc12ff 100644 --- a/template/lambda-sqs-worker/package.json +++ b/template/lambda-sqs-worker/package.json @@ -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",