-
Notifications
You must be signed in to change notification settings - Fork 2
/
justfile
117 lines (91 loc) · 4.66 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 docs 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 ./...
oem_dir := "./pkg/embed/flatcaroem"
go_flags := "--tags containers_image_openpgp,containers_image_storage_stub -ldflags=\"-w -s -X go.githedgehog.com/fabricator/pkg/version.Version=" + version + "\""
go_build := "go build " + go_flags
go_linux_build := "GOOS=linux GOARCH=amd64 " + go_build
_touch_embed:
@touch ./pkg/embed/recipebin/hhfab-recipe.gz
@touch {{oem_dir}}/oem.cpio.gz
@touch {{oem_dir}}/hhfab-flatcar-install
_hhfab_embed: _touch_embed _butane
# Build hhfab-recipe binary for embedding
{{go_linux_build}} -o ./pkg/embed/recipebin/hhfab-recipe ./cmd/hhfab-recipe
gzip -fk ./pkg/embed/recipebin/hhfab-recipe
# Build flatcar oem.cpio.gz for embedding
@mkdir -p {{oem_dir}}/usr/share/oem
{{go_linux_build}} -o {{oem_dir}}/hhfab-flatcar-install ./cmd/hhfab-flatcar-install
{{butane}} --strict --output {{oem_dir}}/usr/share/oem/config.ign --files-dir {{oem_dir}} ./pkg/fab/recipe/control_build_usb_butane.yaml
cd {{oem_dir}} && find usr | cpio -o -H newc | gzip -f > oem.cpio.gz
_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 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Generate code/manifests, things to embed, etc
gen: _kube_gen _hhfab_embed
_hhfab_build: _license_headers _gotools _kube_gen _hhfab_embed
{{go_linux_build}} -o ./bin/hhfab ./cmd/hhfab
# Build hhfab for local OS/Arch
hhfab-build-local: _license_headers _gotools _kube_gen _hhfab_embed && version
{{go_build}} -o ./bin/hhfab ./cmd/hhfab
# Build all artifacts
build: _license_headers _gotools _hhfab_build && version
{{go_linux_build}} -o ./bin/fabricator ./cmd
# Build complete
# TODO rework by using existing recipes and installing with helm chart
# Run e2e tests on existing Kind cluster
# test-e2e:
# go test ./test/e2e/ -v -ginkgo.v
oci_repo := "127.0.0.1:30000"
oci_prefix := "githedgehog/fabricator"
_helm-fabricator-api: _kustomize _helm _kube_gen
@rm config/helm/fabricator-api-v*.tgz || true
{{kustomize}} build config/crd > config/helm/fabricator-api/templates/crds.yaml
{{helm}} package config/helm/fabricator-api --destination config/helm --version {{version}}
{{helm}} lint config/helm/fabricator-api-{{version}}.tgz
_helm-fabricator: _kustomize _helm _helmify _kube_gen
@rm config/helm/fabricator-v*.tgz || true
@rm config/helm/fabricator/templates/*.yaml config/helm/fabricator/values.yaml || true
{{kustomize}} build config/default | {{helmify}} config/helm/fabricator
{{helm}} package config/helm/fabricator --destination config/helm --version {{version}}
{{helm}} lint config/helm/fabricator-{{version}}.tgz
# Build all K8s artifacts (images and charts)
kube-build: build (_docker-build "fabricator") _helm-fabricator-api _helm-fabricator && version
# Docker images and Helm charts built
# Push all K8s artifacts (images and charts)
kube-push: kube-build (_helm-push "fabricator-api") (_kube-push "fabricator") && version
# Docker images and Helm charts pushed
# Push all K8s artifacts (images and charts) and binaries
push: kube-push && version
cd bin && oras push {{oci_repo}}/{{oci_prefix}}/hhfab:{{version}} hhfab
# Install API on a kind cluster and wait for CRDs to be ready
test-api: _helm-fabricator-api
kind export kubeconfig --name kind || kind create cluster --name kind
kind export kubeconfig --name kind
{{helm}} install -n default fabricator-api config/helm/fabricator-api-{{version}}.tgz
sleep 10
kubectl wait --for condition=established --timeout=60s crd/fabricators.fabricator.githedgehog.com
kubectl wait --for condition=established --timeout=60s crd/controlnodes.fabricator.githedgehog.com
kubectl get crd | grep fabricator
kind delete cluster --name kind
# Generate docs
docs: gen _crd_ref_docs
{{crd_ref_docs}} --source-path=./api/ --config=api/docs.config.yaml --renderer=markdown --output-path=./docs/api.md