Skip to content

Commit

Permalink
replace CACHE_BUST with DEXBUILD_NOCACHE
Browse files Browse the repository at this point in the history
  • Loading branch information
briceburg committed Nov 19, 2016
1 parent 3a78aa5 commit b5772cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions docs/HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,29 @@ dex run --pull local/my-app
```


#### busting cache
#### busting cache ( DEXBUILD_NOCACHE )

Often, images will use a git repository to install an application. E.g.
Sometimes images will use a git repository to install an application. E.g.

```
# ...
RUN git clone my-repo/my-app.git /app
# ...
```

Docker will cache this, and use it's cache for subsequent builds -- no matter
if the git repository and application code has been changed upstream. To get
around this, dex builds images with a CACHE_BUST argument. Use this to introduce
randomness and force the git clone command. E.g.
The command is fingerprinted and its results cached in Docker's build-cache.
On subsequent builds the command fingerprint maintains the same, so Docker
returns the results from the build-cache. Your application code WILL NOT CHANGE
no matter if changes have been made upstream.

Dex provides a convenient way around this cache. Invoke the `DEXBUILD_NOCACHE`
build argument and _all_ subsequent commands will have a changed fingerprint --
and thus execute.

```
# ...
ARG CACHE_BUST
# bust the cache so git clone (and ALL subsequent commands) runs
ARG DEXBUILD_NOCACHE
RUN git clone my-repo/my-app.git /app
# ...
```
Expand Down
4 changes: 2 additions & 2 deletions lib.d/dex-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ dex-image-build(){
cd $image_dir

# add cachebusting argument if requested/used in Dockerfile
grep -q "^ARG CACHE_BUST" $dockerfile && \
cachebust="--build-arg CACHE_BUST=$random"
grep -q "^ARG DEXBUILD_NOCACHE" $dockerfile && \
cachebust="--build-arg DEXBUILD_NOCACHE=$random"

$__pull_flag && \
pull="--pull"
Expand Down
2 changes: 1 addition & 1 deletion tests/bats/05-image.bats
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ setup(){
[ "$first_sha" = "$second_sha" ]
}

@test "image build uses CACHE_BUST argument to circumvent docker build cache" {
@test "image build uses DEXBUILD_NOCACHE argument to circumvent docker build cache" {
run $DEX image build imgtest/cachebust:nocache
[ $status -eq 0 ]
first_sha=$(docker inspect -f '{{ .Id }}' $DEX_NAMESPACE/cachebust:nocache)
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/dex-images/cachebust/Dockerfile-nocache
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ LABEL org.dockerland.dex.api="v1"
CMD echo "ALPINE_RELEASE=$(cat /etc/alpine-release)" ; printenv

# bust some cache
ARG CACHE_BUST
ARG DEXBUILD_NOCACHE
RUN echo "I always execute"

0 comments on commit b5772cf

Please sign in to comment.