Skip to content

Commit dd8b650

Browse files
authored
Merge pull request #1235 from akselleirv/tilt-local-binary-build
tilt: speed up compiling of binaries
2 parents 38229c8 + a65ce6d commit dd8b650

5 files changed

Lines changed: 151 additions & 16 deletions

File tree

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
# Ignore build and test binaries.
33
bin/
44
testbin/
5+
!bin/tf-runner
6+
!bin/tofu-controller
7+
!bin/branch-planner

Dockerfile.dev

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM alpine:3.19
2+
3+
LABEL org.opencontainers.image.source="https://github.com/flux-iac/tofu-controller"
4+
5+
ARG LIBCRYPTO_VERSION
6+
7+
RUN apk update && \
8+
apk add --no-cache \
9+
libcrypto3=${LIBCRYPTO_VERSION} \
10+
libssl3=${LIBCRYPTO_VERSION} \
11+
ca-certificates tini git openssh-client gnupg \
12+
libretls \
13+
busybox
14+
15+
COPY bin/tofu-controller /usr/local/bin/
16+
17+
RUN addgroup --gid 65532 -S controller && adduser --uid 65532 -S controller -G controller
18+
19+
USER 65532:65532
20+
21+
ENV GNUPGHOME=/tmp
22+
23+
ENTRYPOINT [ "/sbin/tini", "--", "tofu-controller" ]

Tiltfile

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,86 @@ k8s_yaml(namespace_inject(secret_from_dict("bbp-token", inputs = {
5858
# Add configMap
5959
k8s_yaml(namespace_inject("./config/tilt/configMap.yaml", namespace))
6060

61+
local_resource(
62+
'manager-compile',
63+
'CGO_ENABLED=0 GOOS=linux GOARCH=$(go env GOARCH) go build -o bin/tofu-controller ./cmd/manager',
64+
deps=[
65+
'api/',
66+
'tfctl/',
67+
'cmd/manager/',
68+
'controllers/',
69+
'mtls/',
70+
'runner/',
71+
'internal/',
72+
'utils/',
73+
'go.mod',
74+
'go.sum'
75+
],
76+
labels = ['native-processes'],
77+
)
78+
6179
# Images
6280
docker_build(
6381
"ghcr.io/flux-iac/tofu-controller",
6482
"",
65-
dockerfile="Dockerfile",
83+
dockerfile="Dockerfile.dev",
6684
build_args={
6785
'BUILD_SHA': buildSHA,
6886
'BUILD_VERSION': buildVersion,
6987
'LIBCRYPTO_VERSION': LIBCRYPTO_VERSION,
70-
})
88+
}
89+
)
90+
91+
local_resource(
92+
'branch-planner-compile',
93+
'CGO_ENABLED=0 GOOS=linux GOARCH=$(go env GOARCH) go build -o bin/branch-planner ./cmd/branch-planner',
94+
deps=[
95+
'api/',
96+
'tfctl/',
97+
'cmd/branch-planner/',
98+
'internal/',
99+
'utils/',
100+
'go.mod',
101+
'go.sum'
102+
],
103+
labels = ['native-processes'],
104+
)
71105

72106
docker_build(
73107
"ghcr.io/flux-iac/branch-planner",
74108
"",
75-
dockerfile="planner.Dockerfile",
109+
dockerfile="planner.Dockerfile.dev",
76110
build_args={
77111
'BUILD_SHA': buildSHA,
78112
'BUILD_VERSION': buildVersion,
79113
'LIBCRYPTO_VERSION': LIBCRYPTO_VERSION,
80-
})
114+
}
115+
)
81116

82117

83-
k8s_kind('Terraform', image_json_path='{.spec.runnerPodTemplate.spec.image}')
84-
docker_build(
85-
'ghcr.io/flux-iac/tf-runner-base',
86-
'',
87-
dockerfile='runner-base.Dockerfile',
88-
build_args={
89-
'BUILD_SHA': buildSHA,
90-
'BUILD_VERSION': buildVersion,
91-
'LIBCRYPTO_VERSION': LIBCRYPTO_VERSION,
92-
}
118+
local_resource(
119+
'runner-compile',
120+
'CGO_ENABLED=0 GOOS=linux GOARCH=$(go env GOARCH) go build -o bin/tf-runner ./cmd/runner/main.go',
121+
deps=[
122+
'api/',
123+
'tfctl/',
124+
'cmd/runner',
125+
'controllers/',
126+
'mtls/',
127+
'runner/',
128+
'internal/',
129+
'utils/',
130+
'go.mod',
131+
'go.sum'
132+
],
133+
labels = ['native-processes'],
93134
)
135+
k8s_kind('Terraform', image_json_path='{.spec.runnerPodTemplate.spec.image}')
94136
docker_build(
95137
'ghcr.io/flux-iac/tf-runner',
96138
'',
97-
dockerfile='runner.Dockerfile',
139+
dockerfile='runner.Dockerfile.dev',
98140
build_args={
99-
'BASE_IMAGE': 'ghcr.io/flux-iac/tf-runner-base',
141+
'LIBCRYPTO_VERSION': LIBCRYPTO_VERSION,
100142
}
101143
)

planner.Dockerfile.dev

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM alpine:3.19
2+
3+
LABEL org.opencontainers.image.source="https://github.com/flux-iac/tofu-controller"
4+
5+
ARG LIBCRYPTO_VERSION
6+
7+
RUN apk update && \
8+
apk add --no-cache \
9+
libcrypto3=${LIBCRYPTO_VERSION} \
10+
libssl3=${LIBCRYPTO_VERSION} \
11+
ca-certificates tini git openssh-client gnupg \
12+
libretls \
13+
busybox
14+
15+
COPY bin/branch-planner /usr/local/bin/
16+
17+
RUN addgroup --gid 65532 -S controller && adduser --uid 65532 -S controller -G controller
18+
19+
USER 65532:65532
20+
21+
ENV GNUPGHOME=/tmp
22+
23+
ENTRYPOINT [ "/sbin/tini", "--", "branch-planner" ]

runner.Dockerfile.dev

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM alpine:3.19 as base
2+
3+
LABEL org.opencontainers.image.source="https://github.com/flux-iac/tofu-controller"
4+
5+
ARG LIBCRYPTO_VERSION
6+
7+
RUN apk update && \
8+
apk add --no-cache \
9+
busybox \
10+
ca-certificates \
11+
git \
12+
gnupg \
13+
libcrypto3=${LIBCRYPTO_VERSION} \
14+
libssl3=${LIBCRYPTO_VERSION} \
15+
libretls \
16+
openssh-client \
17+
tini
18+
19+
RUN addgroup --gid 65532 -S runner && adduser --uid 65532 -S runner -G runner
20+
21+
USER 65532:65532
22+
23+
ENV GNUPGHOME=/tmp
24+
25+
ENTRYPOINT [ "/sbin/tini", "--", "tf-runner" ]
26+
27+
FROM base
28+
29+
ARG TARGETARCH
30+
ARG TF_VERSION=1.5.7
31+
32+
# Switch to root to have permissions for operations
33+
USER root
34+
35+
ADD https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_${TARGETARCH}.zip /terraform_${TF_VERSION}_linux_${TARGETARCH}.zip
36+
RUN unzip -q /terraform_${TF_VERSION}_linux_${TARGETARCH}.zip -d /usr/local/bin/ && \
37+
rm /terraform_${TF_VERSION}_linux_${TARGETARCH}.zip && \
38+
chmod +x /usr/local/bin/terraform
39+
40+
# Switch back to the non-root user after operations
41+
USER 65532:65532
42+
43+
COPY bin/tf-runner /usr/local/bin/
44+

0 commit comments

Comments
 (0)