Skip to content

Commit

Permalink
[TT-9060] Improvement: Restructure dockerfile to take advantage of ca…
Browse files Browse the repository at this point in the history
…ching (TykTechnologies#5060)

Change removes the `--no-cache` option for docker build. The Dockerfile
is modified so that `go mod download` gets cached in it's own layer.
Only if the contents of go.sum or go.mod are modified, that layer will
be rebuilt.

Co-authored-by: Tit Petric <[email protected]>
  • Loading branch information
titpetric and Tit Petric authored Jun 1, 2023
1 parent 37f5354 commit 76a0061
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ RUN apt install python3 -y
RUN find /tmp -type f -delete

# Build gateway

RUN mkdir /opt/tyk-gateway
WORKDIR /opt/tyk-gateway
ADD go.mod go.sum /opt/tyk-gateway
RUN go mod download
ADD . /opt/tyk-gateway

RUN go mod download && make build && go clean -modcache
RUN make build

COPY tyk.conf.example tyk.conf

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mongo-shell:
.PHONY: docker docker-std

docker:
docker build --platform ${BUILD_PLATFORM} --no-cache --rm -t internal/tyk-gateway --squash .
docker build --platform ${BUILD_PLATFORM} --rm -t internal/tyk-gateway --squash .

docker-std: build
docker build --platform ${BUILD_PLATFORM} --no-cache -t internal/tyk-gateway:std -f ci/Dockerfile.std .
Expand Down

0 comments on commit 76a0061

Please sign in to comment.