Skip to content

Commit

Permalink
Improve ECR caching in templates (#453)
Browse files Browse the repository at this point in the history
Editorialised context from an internal PR I forgot to upstream:

Our previous attempt at `COMPOSE_DOCKER_CLI_BUILD` works locally for
`docker build` and `docker-compose build` interop. The issue in
Buildkite is that we use multi-stage builds which means that the cached
ECR image only contains layers from the final stage, so Compose will
always try to rebuild the earlier stages like `yarn install`.

This switches our Compose file over to directly reference the cached ECR
image.

1. Upside: we never wastefully rebuild base images through Compose,
   saving ~2 minutes per step.
2. Downside: Compose file is not usable for local debugging. A
   workaround is to define separate Compose services for CI and local
   use, but that isn't implemented in this PR.
  • Loading branch information
72636c authored Jun 10, 2021
1 parent 21bf2b9 commit 3042866
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-feet-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**template/greeter:** Use `seek-oss/docker-ecr-cache` Buildkite plugin
5 changes: 5 additions & 0 deletions .changeset/hungry-parents-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**template/koa-rest-api:** Use `seek-oss/docker-ecr-cache` Buildkite plugin
5 changes: 5 additions & 0 deletions .changeset/late-owls-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**template/express-rest-api:** Use `seek-oss/docker-ecr-cache` Buildkite plugin
5 changes: 5 additions & 0 deletions .changeset/olive-chicken-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**template:** Reuse ECR cache in Docker Compose
12 changes: 10 additions & 2 deletions template/express-rest-api/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ configs:
env:
NPM_READ_TOKEN: arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token

- &docker-ecr-cache
seek-oss/docker-ecr-cache#v1.9.0:
build-args:
- NPM_READ_TOKEN
cache-on:
- package.json
- yarn.lock
target: dev-deps

- &deploy
concurrency: 1
retry:
Expand All @@ -30,8 +39,7 @@ steps:
- yarn lint
plugins:
- *aws-sm
- ecr#v2.3.0:
login: true
- *docker-ecr-cache
- docker-compose#v3.7.0:
run: app

Expand Down
6 changes: 1 addition & 5 deletions template/express-rest-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ version: '3.7'

services:
app:
build:
args:
- NPM_READ_TOKEN
context: .
target: dev-deps
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE}
init: true
volumes:
- ./:/workdir
Expand Down
12 changes: 10 additions & 2 deletions template/greeter/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ configs:
env:
NPM_READ_TOKEN: arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token

- &docker-ecr-cache
seek-oss/docker-ecr-cache#v1.5.0:
build-args:
- NPM_READ_TOKEN
cache-on:
- package.json
- yarn.lock
target: dev-deps

- &prod
agents:
queue: <%- prodBuildkiteQueueName %>
Expand All @@ -18,7 +27,6 @@ steps:
- yarn lint
plugins:
- *aws-sm
- ecr#v2.3.0:
login: true
- *docker-ecr-cache
- docker-compose#v3.7.0:
run: app
6 changes: 1 addition & 5 deletions template/greeter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ version: '3.7'

services:
app:
build:
args:
- NPM_READ_TOKEN
context: .
target: dev-deps
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE}
init: true
volumes:
- ./:/workdir
Expand Down
12 changes: 10 additions & 2 deletions template/koa-rest-api/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ configs:
env:
NPM_READ_TOKEN: arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token

- &docker-ecr-cache
seek-oss/docker-ecr-cache#v1.9.0:
build-args:
- NPM_READ_TOKEN
cache-on:
- package.json
- yarn.lock
target: dev-deps

- &deploy
concurrency: 1
retry:
Expand All @@ -30,8 +39,7 @@ steps:
- yarn lint
plugins:
- *aws-sm
- ecr#v2.3.0:
login: true
- *docker-ecr-cache
- docker-compose#v3.7.0:
run: app

Expand Down
6 changes: 1 addition & 5 deletions template/koa-rest-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ version: '3.7'

services:
app:
build:
args:
- NPM_READ_TOKEN
context: .
target: dev-deps
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE}
init: true
volumes:
- ./:/workdir
Expand Down
1 change: 0 additions & 1 deletion template/lambda-sqs-worker/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
env:
COMPOSE_DOCKER_CLI_BUILD: 1
VERSION: ${BUILDKITE_COMMIT:0:7}.${BUILDKITE_BUILD_NUMBER}

configs:
Expand Down
6 changes: 1 addition & 5 deletions template/lambda-sqs-worker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ version: '3.7'

services:
app:
build:
args:
- NPM_READ_TOKEN
context: .
target: dev-deps
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE}
environment:
- BUILDKITE_COMMIT
- ENVIRONMENT
Expand Down

0 comments on commit 3042866

Please sign in to comment.