Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include --additional-build-args in checksum #54

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN echo 'my expensive build step'
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0
- seek-oss/docker-ecr-cache#v2.2.1
- docker#v5.10.0
```

Expand All @@ -52,7 +52,7 @@ RUN pnpm install
steps:
- command: pnpm test
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
cache-on:
- package.json # avoid cache hits on stale lockfiles
- pnpm-lock.yaml
Expand All @@ -67,7 +67,7 @@ The `cache-on` property also supports Bash globbing with `globstar`:
steps:
- command: pnpm test
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
cache-on:
- '**/package.json' # monorepo with multiple manifest files
- pnpm-lock.yaml
Expand All @@ -84,7 +84,7 @@ A given entry cannot contain both bash globbing and a jq path.
steps:
- command: pnpm test
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
cache-on:
- .npmrc
- package.json#.dependencies
Expand All @@ -105,7 +105,7 @@ It's possible to specify the Dockerfile to use by:
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
dockerfile: my-dockerfile
- docker#v5.10.0
```
Expand All @@ -116,7 +116,7 @@ Alternatively, Dockerfile can be embedded inline:
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
dockerfile-inline: |
FROM node:20-alpine
WORKDIR /workdir
Expand Down Expand Up @@ -145,7 +145,7 @@ steps:
--build-arg BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG
--file Dockerfile.secondary
plugins:
- seek-oss/docker-ecr-cache#v2.2.0
- seek-oss/docker-ecr-cache#v2.2.1
```

Your `Dockerfile.secondary` can then [dynamically use these args](https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact):
Expand Down Expand Up @@ -173,7 +173,7 @@ stage to run commands against:
steps:
- command: cargo test
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
target: build-deps
- docker#v5.10.0
```
Expand All @@ -188,7 +188,7 @@ The `context` property can be used to specify a different path.
steps:
- command: cargo test
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
dockerfile: dockerfiles/test/Dockerfile
context: '.'
- docker#v5.10.0
Expand Down Expand Up @@ -217,7 +217,7 @@ steps:
env:
ARG_1: wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
build-args:
- ARG_1
- ARG_2=such
Expand All @@ -232,7 +232,7 @@ steps:
env:
ARG_1: wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
additional-build-args: '--ssh= default=\$SSH_AUTH_SOCK'
- docker#v5.10.0
```
Expand Down Expand Up @@ -260,7 +260,7 @@ steps:
env:
SECRET: wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
secrets:
- SECRET
- docker#v5.10.0
Expand All @@ -276,7 +276,7 @@ steps:
plugins:
- seek-oss/private-npm#v1.2.0:
env: SECRET
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
secrets:
- id=npmrc,src=.npmrc
- docker#v5.10.0
Expand All @@ -294,7 +294,7 @@ By default images are kept in ECR for up to 30 days. This can be changed by spec
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
max-age-days: 7
- docker#v5.10.0
```
Expand All @@ -307,7 +307,7 @@ By default, image name and computed tag are exported to the Docker buildkite plu
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
export-env-variable: BUILDKITE_PLUGIN_MY_CUSTOM_PLUGIN_CACHE_IMAGE
- my-custom-plugin#v1.0.0:
```
Expand All @@ -321,7 +321,7 @@ steps:
- label: Build Cache
command: ':'
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
skip-pull-from-cache: true
```

Expand All @@ -337,7 +337,7 @@ optionally use a custom repository name:
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
ecr-name: my-unique-repository-name
ecr-tags:
Key: Value
Expand All @@ -353,7 +353,7 @@ By default, the plugin uses the region specified in the `AWS_DEFAULT_REGION` env
steps:
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
region: ap-southeast-2
- docker#v5.10.0
```
Expand Down Expand Up @@ -395,7 +395,7 @@ Example:
```yaml
- command: echo wow
plugins:
- seek-oss/docker-ecr-cache#v2.2.0:
- seek-oss/docker-ecr-cache#v2.2.1:
registry-provider: gcr
gcp-project: foo-bar-123456
```
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
version: '3.4'
services:
tests:
image: buildkite/plugin-tester:v4.1.0
volumes:
- '.:/plugin:ro'
environment:
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ECR_TAGS_SEEK:OWNER:TEAM=Candidate
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ECR_TAGS_MYKEY2=mykeyvalue2
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ECR_TAGS_MYKEY=mykeyvalue
lint:
image: buildkite/plugin-linter
command: ['--name', 'seek-oss/docker-ecr-cache']
Expand Down
5 changes: 5 additions & 0 deletions hooks/lib/stdlib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ compute_tag() {

sums+="$(echo "${arg}" | sha1sum)"
done

if [[ -n "${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS:-}" ]]; then
echoerr 'ADDITIONAL_BUILD_ARGS'
sums+="$(echo "${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS}" | sha1sum)"
fi

# expand ** in cache-on properties
shopt -s globstar
Expand Down
36 changes: 36 additions & 0 deletions tests/stdlib.bats
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pre_command_hook="$PWD/hooks/pre-command"
assert_line "ARCHITECTURE"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
refute_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
Expand Down Expand Up @@ -91,6 +92,7 @@ pre_command_hook="$PWD/hooks/pre-command"
assert_line "ARCHITECTURE"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
refute_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
Expand Down Expand Up @@ -122,6 +124,7 @@ pre_command_hook="$PWD/hooks/pre-command"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
assert_line "+ foo=1"
refute_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
Expand Down Expand Up @@ -155,6 +158,7 @@ pre_command_hook="$PWD/hooks/pre-command"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
assert_line "+ foo=1"
refute_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
Expand Down Expand Up @@ -187,9 +191,41 @@ pre_command_hook="$PWD/hooks/pre-command"
assert_line "ARCHITECTURE"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
refute_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
unstub jq
unstub sha1sum
}

@test "Can compute image tag with additional-build-args" {
# this var leaks in via pre-command
target="my-multi-stage-container"
export BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS='--platform=linux/amd64,linux/arm64'

stub uname \
"-m : echo my-architecture" \
"-m : echo my-architecture"
stub sha1sum \
"pretend-dockerfile : echo sha1sum(pretend-dockerfile)" \
": echo sha1sum(target: my-multi-stage-container)" \
": echo sha1sum(uname: my-architecture)" \
": echo sha1sum(--platform=linux/amd64,linux/arm64)" \
": echo sha1sum(hashes so far)"

run compute_tag "pretend-dockerfile"

assert_success
assert_line "--- Computing tag"
assert_line "DOCKERFILE"
assert_line "+ pretend-dockerfile:my-multi-stage-container"
assert_line "ARCHITECTURE"
assert_line "+ my-architecture"
assert_line "BUILD_ARGS"
assert_line "ADDITIONAL_BUILD_ARGS"
assert_line "CACHE_ON"

unstub uname
unstub sha1sum
}
Loading