Skip to content

Commit 7644cf6

Browse files
committed
🐛 Update Dockerignore and Dockerfile templates to exclude unnecessary files and improve CRD install/uninstall logic in Makefiles
1 parent 1065a6d commit 7644cf6

File tree

21 files changed

+218
-70
lines changed

21 files changed

+218
-70
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
2+
# VCS & tooling
3+
.git
4+
.github
5+
.DS_Store
6+
7+
# Build artifacts
38
bin/
9+
dist/
10+
11+
# Utilities
12+
hack/
13+
14+
# Go junk you don't want in the image
15+
**/*_test.go
16+
coverage.*
17+
*.log
18+
19+
# If you use vendor, remove this ignore or whitelist it instead
20+
vendor/

docs/book/src/cronjob-tutorial/testdata/project/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has not a default value to allow the binary be built according to the host where the command

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ ifndef ignore-not-found
157157
endif
158158

159159
.PHONY: install
160-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
161-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
162-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
160+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
162+
$(KUBECTL) apply -k config/crd; \
163+
else \
164+
echo "No CRDs to install; skipping."; \
165+
fi
163166

164167
.PHONY: uninstall
165-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
166-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
167-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
168+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
169+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
170+
$(KUBECTL) delete -k config/crd --ignore-not-found=$(ignore-not-found); \
171+
else \
172+
echo "No CRDs to delete; skipping."; \
173+
fi
168174

169175
.PHONY: deploy
170176
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
2+
# VCS & tooling
3+
.git
4+
.github
5+
.DS_Store
6+
7+
# Build artifacts
38
bin/
9+
dist/
10+
11+
# Utilities
12+
hack/
13+
14+
# Go junk you don't want in the image
15+
**/*_test.go
16+
coverage.*
17+
*.log
18+
19+
# If you use vendor, remove this ignore or whitelist it instead
20+
vendor/

docs/book/src/getting-started/testdata/project/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has not a default value to allow the binary be built according to the host where the command

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,20 @@ ifndef ignore-not-found
153153
endif
154154

155155
.PHONY: install
156-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
157-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
158-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
156+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
157+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
158+
$(KUBECTL) apply -k config/crd; \
159+
else \
160+
echo "No CRDs to install; skipping."; \
161+
fi
159162

160163
.PHONY: uninstall
161-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
162-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
163-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
164+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
165+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
166+
$(KUBECTL) delete -k config/crd --ignore-not-found=$(ignore-not-found); \
167+
else \
168+
echo "No CRDs to delete; skipping."; \
169+
fi
164170

165171
.PHONY: deploy
166172
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
2+
# VCS & tooling
3+
.git
4+
.github
5+
.DS_Store
6+
7+
# Build artifacts
38
bin/
9+
dist/
10+
11+
# Utilities
12+
hack/
13+
14+
# Go junk you don't want in the image
15+
**/*_test.go
16+
coverage.*
17+
*.log
18+
19+
# If you use vendor, remove this ignore or whitelist it instead
20+
vendor/

docs/book/src/multiversion-tutorial/testdata/project/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
15+
COPY . .
1816

1917
# Build
2018
# the GOARCH has not a default value to allow the binary be built according to the host where the command

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ ifndef ignore-not-found
157157
endif
158158

159159
.PHONY: install
160-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. No-op if none exist.
161-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
162-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) apply -f -; else echo "No CRDs to install; skipping."; fi
160+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
161+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
162+
$(KUBECTL) apply -k config/crd; \
163+
else \
164+
echo "No CRDs to install; skipping."; \
165+
fi
163166

164167
.PHONY: uninstall
165-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. No-op if none exist.
166-
@out="$$( $(KUSTOMIZE) build config/crd 2>/dev/null || true )"; \
167-
if [ -n "$$out" ]; then echo "$$out" | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
168+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
169+
@if [ -d config/crd ] && [ -f config/crd/kustomization.yaml ]; then \
170+
$(KUBECTL) delete -k config/crd --ignore-not-found=$(ignore-not-found); \
171+
else \
172+
echo "No CRDs to delete; skipping."; \
173+
fi
168174

169175
.PHONY: deploy
170176
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.

pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
Copyright 2022 The Kubernetes Authors.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,9 +53,7 @@ COPY go.sum go.sum
5253
RUN go mod download
5354
5455
# Copy the go source
55-
COPY cmd/main.go cmd/main.go
56-
COPY api/ api/
57-
COPY internal/ internal/
56+
COPY . .
5857
5958
# Build
6059
# the GOARCH has not a default value to allow the binary be built according to the host where the command

0 commit comments

Comments
 (0)