summarylogtreecommitdiffstats
path: root/0004-Dockerfile.dapper-sanitize-cache-configuration.patch
blob: 1126a2b780402f94cdab5a64df31e3b9a8da9d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From f21e7ea98b46a6088811f25ea59aa2b30846ed56 Mon Sep 17 00:00:00 2001
From: Ivan Shapovalov <intelfx@intelfx.name>
Date: Sat, 23 Dec 2023 01:08:37 +0100
Subject: [PATCH 4/6] Dockerfile.dapper: sanitize cache configuration

- set $HOME to /root because there is no good reason to keep it in $PWD
- mount volumes to /go/pkg to cache downloaded Go sources (we'd set it
  to /go, but that would mask the k3s source tree at /go/src) and
  /root/.cache to cache Go object files ($GOCACHE, ~/.cache/go-build)
---
 .dockerignore     | 1 +
 Dockerfile.dapper | 9 +++++++--
 Makefile          | 1 +
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/.dockerignore b/.dockerignore
index 36131d3744..c7418f3674 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -5,3 +5,4 @@
 ./.cache
 ./.dapper
 ./.trash-cache
+./.dapper-cache
diff --git a/Dockerfile.dapper b/Dockerfile.dapper
index 028d792f2b..1368c18390 100644
--- a/Dockerfile.dapper
+++ b/Dockerfile.dapper
@@ -42,8 +42,13 @@ RUN if [ "$(go env GOARCH)" = "amd64" ]; then \
 ARG SELINUX=true
 ENV SELINUX=${SELINUX}
 
+# Set to someone's $HOME to persist Go pkg cache ($GOPATH/pkg) Hand Go object cache ($GOCACHE)
+ARG DAPPER_CACHE_HOME=./.dapper-cache
+ARG DAPPER_CACHE_GOPATH=${DAPPER_CACHE_HOME}/go
+ARG DAPPER_CACHE_DOTCACHE=${DAPPER_CACHE_HOME}/cache
+
 # Set Dapper configuration variables
-ENV DAPPER_RUN_ARGS="--privileged -v k3s-cache:/go/src/github.com/k3s-io/k3s/.cache -v trivy-cache:/root/.cache/trivy" \
+ENV DAPPER_RUN_ARGS="--privileged -v ${DAPPER_CACHE_GOPATH}/pkg:/go/pkg -v ${DAPPER_CACHE_DOTCACHE}:/root/.cache" \
     DAPPER_ENV="REPO TAG DRONE_TAG IMAGE_NAME SKIP_VALIDATE SKIP_IMAGE SKIP_AIRGAP AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID GITHUB_TOKEN GOLANG GOCOVER GOOS DEBUG" \
     DAPPER_SOURCE="/go/src/github.com/k3s-io/k3s/" \
     DAPPER_OUTPUT="./dist" \
@@ -51,7 +56,7 @@ ENV DAPPER_RUN_ARGS="--privileged -v k3s-cache:/go/src/github.com/k3s-io/k3s/.ca
     CROSS=true \
     STATIC_BUILD=true
 # Set $HOME separately because it refers to $DAPPER_SOURCE, set above
-ENV HOME=${DAPPER_SOURCE}
+ENV HOME=/root
 
 WORKDIR ${DAPPER_SOURCE}
 
diff --git a/Makefile b/Makefile
index 0f19de68c9..8242383736 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ docker.sock:
 	while ! docker version 1>/dev/null; do sleep 1; done
 
 $(TARGETS): .dapper docker.sock
+	@mkdir -p .dapper-cache/{go/pkg,cache}
 	./.dapper $@
 
 .PHONY: deps
-- 
2.49.0.5.g15b5d850cb1