-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJustfile
More file actions
219 lines (177 loc) · 5.3 KB
/
Justfile
File metadata and controls
219 lines (177 loc) · 5.3 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
IMAGE_REGISTRY := "ghcr.io/posit-dev"
IMAGE_NAME := "team-operator"
DEV_IMAGE_NAME := "adhoc-team-operator"
VERSION := `git describe --always --dirty --tags`
DEV_VERSION := "$(git describe --always --dirty --tags)-${BRANCH_NAME}"
postgres_pass := "dev-postgres-password"
BUILDX_PATH := ""
# this needs to be accessible from wherever the operator is running...
db_host := "team-operator-db-postgresql.default.svc.cluster.local"
db_port := "5432"
db_url_secret := "team-operator-main-db-url"
default: build test
# Install dependencies
deps: install-git-hooks
go get -t ./...
# Install git hooks via pre-commit (fails silently in CI)
install-git-hooks:
-uvx pre-commit install
# Update dependencies
deps-up:
go get -t -u ./...
# Run team-operator directly from source
run:
go run cmd/team-operator/main.go
# Run team-operator via the Makefile target
mrun:
make run
# Build ./bin/team-operator
build:
go build \
-ldflags="-X 'github.com/posit-dev/team-operator/internal.VersionString={{ VERSION }}'" \
-a \
-o ./bin/team-operator \
cmd/team-operator/main.go
# Build ./bin/team-operator via the Makefile target
mbuild:
make build
# Format code
format:
go fmt ./...
# Static analysis
vet:
go vet ./...
create-db-url-secret:
#!/bin/bash
set -xe
kubectl delete secret --ignore-not-found '{{ db_url_secret }}'
# TODO: should we delete the secret? Make idempotent? URL encode for weird characters?...
kubectl create secret generic '{{ db_url_secret }}' \
--from-literal \
url='postgres://postgres:{{ postgres_pass }}@{{ db_host }}:{{ db_port }}/postgres?sslmode=require'
k3d-up:
k3d cluster create dev
license:
kubectl create secret generic license \
-n posit-team \
--from-file=lic/pw.lic \
--from-file=lic/pc.lic \
--from-file=lic/ppm.lic
k3d-down:
k3d cluster stop dev
# Install CRDs via the Makefile 'install' target
crds:
make install
mgenerate:
make generate-all && make manifests
crd-test:
#!/bin/bash
set -xe
kubectl apply -f config/samples/test_site.yaml
kubectl apply -f config/samples/test-secret.yaml
crd-test-diff:
kubectl diff -f config/samples/test_site.yaml
crd-test-delete:
kubectl delete -f config/samples/test_site.yaml
# Deploy full kustomization via the Makefile target
mdeploy:
make deploy IMG="{{ IMAGE_REGISTRY }}/{{ IMAGE_NAME }}:{{ VERSION }}"
# Un-deploy via the Makefile target
mundeploy:
make undeploy
db-up:
docker run --rm -d \
--name team-operator-db \
-p {{ db_port }}:5432 \
-e POSTGRES_PASSWORD={{ postgres_pass }} \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=postgres \
postgres:16
db-down:
docker stop team-operator-db
psql:
#!/bin/bash
set -xe
echo 'Password is: {{ postgres_pass }}'
echo ''
psql -h '{{ db_host }}' -p '{{ db_port }}' -d postgres -U postgres -W
db-k8s-create:
#!/bin/bash
# NOTE: accessing this can be tricky from the operator when running locally
set -xe
helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade --install team-operator-db bitnami/postgresql \
--version 11.6.16 \
--set auth.database="postgres" \
--set auth.username="postgres" \
--set global.postgresql.auth.postgresPassword="{{ postgres_pass }}" \
--set primary.persistence.enabled=false
db-k8s-delete:
@helm uninstall team-operator-db
db-k8s-forward:
@kubectl port-forward svc/team-operator-db-postgresql 5432:5432
docker-build:
#!/bin/bash
set -xe
# variable placeholers
BUILDX_ARGS=""
BUILDER=""
# set buildx args
if [[ "{{BUILDX_PATH}}" != "" ]]; then
BUILDER="--builder={{ BUILDX_PATH }}"
BUILDX_ARGS="--cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache"
fi
# Get Go version from go.mod. The 4 curly brackets on the left side look odd,
# but this is intentional and the escaping that works for the combination of
# just and bash parsing. The echo statement proves that it is extracting the
# version correctly.
GO_VERSION=$(go list -m -f "{{{{.GoVersion}}")
if [[ -z "$GO_VERSION" ]]; then
echo "Error: Could not extract Go version from go.mod"
exit 1
fi
echo Getting Go version from go.mod: ${GO_VERSION}
docker buildx $BUILDER build --load $BUILDX_ARGS \
--platform=linux/amd64 \
--build-arg "VERSION={{ VERSION }}" \
--build-arg "GO_VERSION=${GO_VERSION}" \
-t {{ IMAGE_REGISTRY }}/$(just echo-image) \
.
docker-push:
docker push {{ IMAGE_REGISTRY }}/$(just echo-image)
echo-image:
#!/bin/bash
if [[ -z "${BRANCH_NAME}" ]]; then
echo "BRANCH_NAME is not set... trying with CLI" >&2
export BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
echo "BRANCH_NAME=${BRANCH_NAME}" >&2
fi
if [[ "${BRANCH_NAME}" == "main" ]]; then
echo {{ IMAGE_NAME }}:{{ VERSION }}
else
echo {{ DEV_IMAGE_NAME }}:{{ DEV_VERSION }}
fi
# Run go tests without envtest
test:
go test -v ./... -coverprofile coverage.out
# Run tests with envtest via the Makefile target
mtest:
make test
# Generate Helm chart from kustomize
helm-generate:
make helm-generate
# Install operator via Helm
helm-install:
make helm-install
# Uninstall operator via Helm
helm-uninstall:
make helm-uninstall
# Lint Helm chart
helm-lint:
make helm-lint
# Render Helm templates locally
helm-template:
make helm-template
# Package Helm chart as .tar.gz
helm-package:
make helm-package