Skip to content

Commit d32104f

Browse files
authored
feat: improve tiltfile, cleanup makefile (#117)
1 parent 35ae341 commit d32104f

File tree

10 files changed

+158
-146
lines changed

10 files changed

+158
-146
lines changed

.dockerignore

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
4+
5+
# Ignore build and test binaries
6+
bin/
7+
*.exe
8+
*.exe~
9+
*.dll
10+
*.so
11+
*.dylib
12+
*.test
13+
*.out
14+
15+
# Ignore Go workspace and vendor files
16+
go.work
17+
go.work.sum
18+
vendor/
19+
20+
# Ignore project directories not needed in container
21+
docs/
22+
hack/
23+
config/
24+
examples/
25+
scripts/
26+
tools/
27+
.github/
28+
.gitlab/
29+
30+
# Ignore test files and directories
31+
*_test.go
32+
testdata/
33+
test/
34+
35+
# Ignore IDE and editor files
36+
.vscode/
37+
.idea/
38+
*.swp
39+
*.swo
40+
*~
41+
42+
# Ignore OS generated files
43+
.DS_Store
44+
.DS_Store?
45+
._*
46+
.Spotlight-V100
47+
.Trashes
48+
ehthumbs.db
49+
Thumbs.db
50+
51+
# Ignore Git and CI/CD files
52+
.git/
53+
.gitignore
54+
.gitattributes
55+
56+
# Ignore Docker files (except main Dockerfile)
57+
.dockerignore
58+
docker-compose*.yml
59+
60+
# Ignore documentation and config files
61+
*.md
62+
README*
63+
LICENSE*
64+
CONTRIBUTING*
65+
CHANGELOG*
66+
.env
67+
.env.*
68+
69+
# Ignore temporary and log files
70+
tmp/
71+
temp/
72+
*.tmp
73+
*.log

Makefile

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,15 @@ GOLANGCI_LINT_VERSION ?= v1.59.1
5656
GORELEASER_VERSION ?= v1.21.0
5757
MDTOC_VERSION ?= v1.1.0
5858
NANCY_VERSION ?= v1.0.46
59-
KIND_VERSION ?= v0.22.0
59+
KIND_VERSION ?= v0.30.0
6060

6161
##@ Build
62-
.PHONY: all build copy run clean
62+
.PHONY: all
6363
all: clean build copy docker-build apply
6464

6565
build:
6666
@go mod tidy
67-
@if [ "$(OS)" = "mac" ]; then \
68-
echo "Building $(BINARY_NAME) for mac..." && \
69-
GOOS="darwin" CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) $(PKG_PATH); \
70-
else \
71-
echo "Building $(BINARY_NAME) for linux..." && \
72-
GOOS="linux" CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) $(PKG_PATH); \
73-
fi
67+
go build $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) $(PKG_PATH); \
7468

7569
test:
7670
@echo "Testing App..."
@@ -90,13 +84,13 @@ DEBUG = 0
9084

9185
##@ Local Development
9286
.PHONY: docker-build
93-
docker-build: ## Build a garm image with the k8s provider
94-
docker build -t localhost:5000/garm-with-k8s:latest ./hack
87+
docker-build: ## Build image with the k8s provider
88+
docker build -f ./hack/Dockerfile -t localhost:5000/garm-with-k8s:latest .
9589
docker push localhost:5000/garm-with-k8s:latest
9690

9791
.PHONY: docker-build-summerwind-runner
9892
docker-build-summerwind-runner: ## Build the used runner image
99-
$(eval RUNNER_IMAGE ?= $(shell echo "localhost:5000/runner:linux-ubuntu-22.04-$(shell uname -m)"))
93+
$(eval RUNNER_IMAGE ?= $(shell echo "localhost:5000/runner:linux-ubuntu-22.04"))
10094
docker build -t $(RUNNER_IMAGE) ./runner/summerwind
10195
docker push $(RUNNER_IMAGE)
10296

@@ -127,7 +121,7 @@ endif
127121
GARM_GITHUB_ORGANIZATION=$(GARM_GITHUB_ORGANIZATION) \
128122
GARM_GITHUB_TOKEN=$(shell echo -n $(GARM_GITHUB_TOKEN) | base64) \
129123
GARM_GITHUB_WEBHOOK_SECRET=$(shell echo -n $(GARM_GITHUB_WEBHOOK_SECRET) | base64) \
130-
RUNNER_IMAGE=$(shell echo "localhost:5000/runner:linux-ubuntu-22.04-$(shell uname -m)") \
124+
RUNNER_IMAGE=$(shell echo "localhost:5000/runner:linux-ubuntu-22.04") \
131125
envsubst < hack/local-development/kubernetes/garm-operator-crs-envsubst.yaml > hack/local-development/kubernetes/garm-operator-crs.yaml
132126

133127
.PHONY: prepare-operator
@@ -150,7 +144,7 @@ delete-kind-cluster:
150144

151145
.PHONY: tilt-up
152146
tilt-up: kind-cluster ## Start tilt and build kind cluster
153-
tilt up
147+
tilt up --port $(or $(PORT),10350)
154148

155149
##@ Release
156150
.PHONY: release

Tiltfile

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,15 @@ deploy_cert_manager(
1212
version='v1.15.3' # the version of cert-manager to deploy
1313
)
1414

15-
# build garm-provider-k8s binary with 'make build copy'
16-
local_resource(
17-
"build provider",
18-
cmd="make build copy",
19-
auto_init=True,
20-
trigger_mode=TRIGGER_MODE_MANUAL,
21-
labels=["garm-k8s-provider"],
22-
deps=["."]
23-
)
24-
25-
# build garm image garm-with-k8s and push to localhost:5000/garm-with-k8s in ./hack context
15+
# build image localhost:5000/garm-provider-k8s:latest in current context
2616
docker_build(
27-
'localhost:5000/garm-with-k8s',
28-
'./hack'
17+
"localhost:5000/garm-with-k8s",
18+
".",
19+
dockerfile="./hack/Dockerfile"
2920
)
3021

3122
# build gh action runner image in ./runner context
32-
cpu_arch = str(local('uname -m')).strip()
33-
image_tag="localhost:5000/runner:linux-ubuntu-22.04-" + cpu_arch
23+
image_tag="localhost:5000/runner:linux-ubuntu-22.04"
3424

3525
local_resource(
3626
"build runner",
@@ -57,16 +47,13 @@ k8s_resource(
5747
'garm-kubernetes-provider-config:ConfigMap:garm-server',
5848
'garm-data:PersistentVolumeClaim:garm-server',
5949
'garm-home:PersistentVolumeClaim:garm-server'
60-
6150
],
6251
labels=["garm-server"],
6352
)
6453

65-
# deploy the garm-operator and CRs
54+
# deploy the garm-operator
6655
k8s_yaml('hack/local-development/kubernetes/garm-operator-all.yaml')
6756

68-
k8s_yaml('hack/local-development/kubernetes/garm-operator-crs.yaml')
69-
7057
k8s_resource(
7158
"garm-operator-controller-manager",
7259
objects=[
@@ -90,14 +77,32 @@ k8s_resource(
9077
'garm-operator-serving-cert:Certificate:garm-operator-system',
9178
'garm-operator-selfsigned-issuer:Issuer:garm-operator-system',
9279
'garm-operator-validating-webhook-configuration:ValidatingWebhookConfiguration:default',
93-
'garm-server-config:GarmServerConfig:garm-operator-system',
94-
'github:GitHubEndpoint:garm-operator-system',
95-
'github-pat:GitHubCredential:garm-operator-system',
96-
'github-pat:Secret:garm-operator-system',
97-
'test-workflows:Repository:garm-operator-system',
98-
'repo-webhook-secret:Secret:garm-operator-system',
99-
'runner-default:Image:garm-operator-system',
100-
'kubernetes-pool-repo:Pool:garm-operator-system'
10180
],
10281
labels=["operator"],
10382
)
83+
84+
# Extract all resource names and kinds dynamically from the garm-operator-crs.yaml
85+
k8s_yaml('hack/local-development/kubernetes/garm-operator-crs.yaml')
86+
87+
def get_operator_objects():
88+
result = []
89+
yaml_content = read_yaml_stream('hack/local-development/kubernetes/garm-operator-crs.yaml')
90+
for resource in yaml_content:
91+
if 'kind' in resource and 'metadata' in resource:
92+
kind = resource['kind']
93+
metadata = resource['metadata']
94+
if 'name' in metadata:
95+
name = metadata['name']
96+
namespace = metadata.get('namespace', 'garm-operator-system') if 'namespace' in metadata else 'garm-operator-system'
97+
result.append(name + ':' + kind + ':' + namespace)
98+
print('Total objects returned: %s' % len(result))
99+
return result
100+
101+
operator_objects = get_operator_objects()
102+
103+
k8s_resource(
104+
new_name='garm-operator-crs',
105+
objects=operator_objects,
106+
labels=["operator"],
107+
resource_deps=['garm-operator-controller-manager']
108+
)

hack/.dockerignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

hack/Dockerfile

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
# SPDX-License-Identifier: MIT
22

3+
ARG garm_repo_ref=v0.1.5
4+
35
FROM golang:1.24.2 AS build
46

5-
ARG garm_repo=https://github.com/cloudbase/garm
6-
ARG garm_repo_ref=v0.1.5
7+
WORKDIR /app
78

8-
# build garm binary
9-
# primarly used to get the binary build for
10-
# the local CPU architecture
11-
RUN git clone $garm_repo garm_repo && \
12-
cd garm_repo && \
13-
git checkout $garm_repo_ref && \
14-
CGO_ENABLED=1 go install -ldflags "-linkmode external -extldflags '-static' -X github.com/cloudbase/garm/util/appdefaults.Version=$garm_repo_ref" ./cmd/garm && \
15-
CGO_ENABLED=1 go install -ldflags "-linkmode external -extldflags '-static' -X github.com/cloudbase/garm/util/appdefaults.Version=$garm_repo_ref" ./cmd/garm-cli
9+
# Get default value from ARG assigned before FROM
10+
ARG garm_repo_ref
1611

12+
RUN ARCH=$(uname -m) && \
13+
case ${ARCH} in \
14+
x86_64) ARCH=amd64 ;; \
15+
aarch64) ARCH=arm64 ;; \
16+
*) echo "Unsupported architecture: ${ARCH}" ;; \
17+
esac && \
18+
wget -q https://github.com/cloudbase/garm/releases/download/${garm_repo_ref}/garm-cli-linux-${ARCH}.tgz && \
19+
tar -xzf garm-cli-linux-${ARCH}.tgz && \
20+
mv garm-cli /go/bin/garm-cli && \
21+
chmod +x /go/bin/garm-cli && \
22+
rm garm-cli-linux-${ARCH}.tgz
1723

18-
FROM alpine:3.18
1924

20-
WORKDIR /opt/garm/
25+
COPY go.mod go.sum ./
2126

22-
ENV PATH="${PATH}:/opt/garm/bin"
27+
RUN go mod download
2328

24-
COPY --from=build /go/bin/garm ./bin/garm
25-
COPY --from=build /go/bin/garm-cli ./bin/garm-cli
29+
COPY . .
30+
31+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o ./garm-provider-k8s ./cmd/garm-provider-k8s
2632

27-
COPY ./scripts/entrypoint.sh ./bin/entrypoint.sh
28-
COPY ./bin/garm-provider-k8s ./bin/garm-provider-k8s
33+
RUN chmod +x ./garm-provider-k8s && \
34+
chmod +x /go/bin/garm-cli
2935

30-
RUN chmod +x ./bin/entrypoint.sh && \
31-
chmod +x ./bin/garm && \
32-
chmod +x ./bin/garm-cli && \
33-
chmod +x ./bin/garm-provider-k8s
3436

35-
USER 65543:65543
37+
FROM ghcr.io/cloudbase/garm:${garm_repo_ref}
3638

37-
EXPOSE 9997
39+
COPY --from=build /go/bin/garm-cli ./bin/garm-cli
3840

39-
ENTRYPOINT ["/opt/garm/bin/entrypoint.sh"]
41+
COPY --from=build /app/garm-provider-k8s /opt/garm/providers.d/garm-provider-k8s

hack/Dockerfile.debug

Lines changed: 0 additions & 55 deletions
This file was deleted.

hack/local-development/kubernetes/configmap.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ data:
3939
description = "kubernetes provider"
4040
provider_type = "external"
4141
[provider.external]
42-
config_file = "/opt/garm/provider-config/garm-provider-k8s-config.yaml"
43-
provider_executable = "/opt/garm/bin/garm-provider-k8s"
42+
config_file = "/etc/garm/garm-provider-k8s-config.yaml"
43+
provider_executable = "/opt/garm/providers.d/garm-provider-k8s"
4444
environment_variables = ["KUBERNETES_"]
4545
---
4646
apiVersion: v1

hack/local-development/kubernetes/deployment.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ spec:
2121
- image: localhost:5000/garm-with-k8s:latest
2222
name: garm-server
2323
imagePullPolicy: Always
24-
env:
25-
- name: ARCH
26-
value: <ARCH>
2724
volumeMounts:
2825
- name: data
2926
mountPath: /opt/garm/data
3027
- name: cli-config
3128
mountPath: /.local/share/garm-cli
3229
- name: garm-config
33-
mountPath: /opt/garm/config
30+
mountPath: /etc/garm/config.toml
31+
subPath: config.toml
3432
readOnly: true
3533
- name: garm-kubernetes-provider-config
36-
mountPath: /opt/garm/provider-config
34+
mountPath: /etc/garm/garm-provider-k8s-config.yaml
35+
subPath: garm-provider-k8s-config.yaml
36+
readOnly: true
3737
securityContext:
38+
runAsUser: 65534
39+
runAsGroup: 65534
3840
runAsNonRoot: true
3941
fsGroup: 65534
4042
serviceAccountName: garm-server

hack/local-development/kubernetes/garm-operator-crs-envsubst.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ spec:
105105
runnerBootstrapTimeout: 2
106106
runnerPrefix: "garm-k8s"
107107
tags:
108-
- linux-ubuntu-22.04-x86_64
108+
- linux-ubuntu-22.04

0 commit comments

Comments
 (0)