-
Notifications
You must be signed in to change notification settings - Fork 2
/
justfile
117 lines (91 loc) · 5.59 KB
/
justfile
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
set shell := ["bash", "-euo", "pipefail", "-c"]
import "hack/tools.just"
# Print list of available recipes
default:
@just --list
export CGO_ENABLED := "0"
_gotools: _touch_embed
go fmt ./...
go vet {{go_flags}} ./...
# Called in CI
_lint: _license_headers _gotools
# Generate, lint, test and build everything
all: gen lint lint-gha test build kube-build && version
# Run linters against code (incl. license headers)
lint: _lint _golangci_lint
{{golangci_lint}} run --show-stats ./...
# Run golangci-lint to attempt to fix issues
lint-fix: _lint _golangci_lint
{{golangci_lint}} run --show-stats --fix ./...
go_flags := "--tags containers_image_openpgp,containers_image_storage_stub -ldflags=\"-w -s -X go.githedgehog.com/fabric/pkg/version.Version=" + version + "\""
go_build := "go build " + go_flags
go_linux_build := "GOOS=linux GOARCH=amd64 " + go_build
_touch_embed:
@touch pkg/boot/nosinstall/bin/fabric-nos-install
_embed: _touch_embed
# Build fabric-nos-install binary for embedding
{{go_linux_build}} -o ./pkg/boot/nosinstall/bin/fabric-nos-install ./cmd/fabric-nos-install
_kube_gen: _controller_gen
# Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject implementations
{{controller_gen}} object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects
{{controller_gen}} rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Generate docs, code/manifests, things to embed, etc
gen: _kube_gen _embed _crd_ref_docs
{{crd_ref_docs}} --source-path=./api/ --config=api/docs.config.yaml --renderer=markdown --output-path=./docs/api.md
go run cmd/fabric-gen/main.go profiles-ref
# Build all artifacts
build: _license_headers _kube_gen _gotools _embed && version
{{go_linux_build}} -o ./bin/fabric ./cmd
{{go_linux_build}} -o ./bin/agent ./cmd/agent
{{go_linux_build}} -o ./bin/hhfctl ./cmd/hhfctl
{{go_linux_build}} -o ./bin/fabric-boot ./cmd/fabric-boot
{{go_linux_build}} -o ./bin/fabric-dhcpd ./cmd/fabric-dhcpd
# Build complete
_hhfctl-build GOOS GOARCH: _license_headers _kube_gen _gotools _embed
GOOS={{GOOS}} GOARCH={{GOARCH}} {{go_build}} -o ./bin/hhfctl-{{GOOS}}-{{GOARCH}}/hhfctl ./cmd/hhfctl
cd bin && tar -czvf hhfctl-{{GOOS}}-{{GOARCH}}-{{version}}.tar.gz hhfctl-{{GOOS}}-{{GOARCH}}/hhfctl
# Build hhfctl and other user-facing binaries for all supported OS/Arch
build-multi: (_hhfctl-build "linux" "amd64") (_hhfctl-build "linux" "arm64") (_hhfctl-build "darwin" "amd64") (_hhfctl-build "darwin" "arm64") && version
oci_repo := "127.0.0.1:30000"
oci_prefix := "githedgehog/fabric"
_helm-fabric-api: _kustomize _helm _kube_gen
@rm config/helm/fabric-api-v*.tgz || true
{{kustomize}} build config/crd > config/helm/fabric-api/templates/crds.yaml
{{helm}} package config/helm/fabric-api --destination config/helm --version {{version}}
{{helm}} lint config/helm/fabric-api-{{version}}.tgz
_helm-fabric: _kustomize _helm _helmify _kube_gen
@rm config/helm/fabric-v*.tgz || true
@rm config/helm/fabric/templates/*.yaml config/helm/fabric/values.yaml || true
{{kustomize}} build config/default | {{helmify}} config/helm/fabric
{{helm}} package config/helm/fabric --destination config/helm --version {{version}}
{{helm}} lint config/helm/fabric-{{version}}.tgz
# Build all K8s artifacts (images and charts)
kube-build: build (_docker-build "fabric") _helm-fabric-api _helm-fabric (_kube-build "fabric-dhcpd") (_kube-build "fabric-boot") (_helm-build "fabric-proxy") && version
# Docker images and Helm charts built
# Push all K8s artifacts (images and charts)
kube-push: kube-build (_helm-push "fabric-api") (_kube-push "fabric") (_kube-push "fabric-dhcpd") (_kube-push "fabric-boot") (_helm-push "fabric-proxy") && version
# Docker images and Helm charts pushed
# Push all K8s artifacts (images and charts) and binaries
push: kube-push && version
cd bin && oras push {{oras_insecure}} {{oci_repo}}/{{oci_prefix}}/agent:{{version}} agent
cd bin && oras push {{oras_insecure}} {{oci_repo}}/{{oci_prefix}}/hhfctl:{{version}} hhfctl
_hhfctl-push GOOS GOARCH: _oras (_hhfctl-build GOOS GOARCH)
cd bin/hhfctl-{{GOOS}}-{{GOARCH}} && oras push {{oras_insecure}} {{oci_repo}}/{{oci_prefix}}/hhfctl-{{GOOS}}-{{GOARCH}}:{{version}} hhfctl
# Publish hhfctl and other user-facing binaries for all supported OS/Arch
push-multi: (_hhfctl-push "linux" "amd64") (_hhfctl-push "linux" "arm64") (_hhfctl-push "darwin" "amd64") (_hhfctl-push "darwin" "arm64") && version
# Install API on a kind cluster and wait for CRDs to be ready
test-api: _helm-fabric-api
kind export kubeconfig --name kind || kind create cluster --name kind
kind export kubeconfig --name kind
{{helm}} install -n default fabric-api config/helm/fabric-api-{{version}}.tgz
sleep 10
kubectl wait --for condition=established --timeout=60s crd/connections.wiring.githedgehog.com
kubectl wait --for condition=established --timeout=60s crd/vpcs.vpc.githedgehog.com
kubectl wait --for condition=established --timeout=60s crd/agents.agent.githedgehog.com
kubectl wait --for condition=established --timeout=60s crd/dhcpsubnets.dhcp.githedgehog.com
kubectl get crd | grep hedgehog
kind delete cluster --name kind
# Patch deployment using the default kubeconfig (KUBECONFIG env or ~/.kube/config)
patch: && version
kubectl -n fab patch fab/default --type=merge -p '{"spec":{"overrides":{"versions":{"fabric":{"api":"{{version}}","agent":"{{version}}","boot":"{{version}}","controller":"{{version}}","ctl":"{{version}}","dhcpd":"{{version}}","proxyChart":"{{version}}"}}}}}'