-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJustfile
393 lines (349 loc) · 13.8 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
set dotenv-load
dagger_version := "v0.11.9"
pulumi_version := "3.108.0"
kops_version := "1.29.2"
kops_module := "kops"
kubectl_version := "1.28.8"
gh_deployment_module := "gh-deployment"
container_module := "container-image"
deploy_module := "pulumi-ops"
bin_path := `mktemp -d`
action_bin := bin_path + "/actions"
dagger_bin := bin_path + "/dagger"
kubectl_file := `mktemp -d` + "/dictycr.yaml"
base_gha_download_url := "https://github.com/dictybase-docker/github-actions/releases/download/v2.10.0/action_2.10.0_"
gha_download_url := if os() == "macos" {
base_gha_download_url + "darwin_arm64"
} else {
base_gha_download_url + "linux_amd64"
}
file_suffix := ".tar.gz"
dagger_file := if os() == "macos" {
"darwin_arm64" + file_suffix
} else {
"linux_amd64" + file_suffix
}
# Display system information
#
# This recipe prints the architecture and operating system of the current machine.
system-info:
@echo this is an {{arch()}} os {{os()}}
# Check environment variables
#
# This recipe displays the values of important environment variables
# used by other recipes for deployment and configuration.
check-env:
@echo $DOCKERFILE $DOCKER_IMAGE $DOCKER_NAMESPACE
@echo $REPOSITORY $ENVIRONMENT $PROJECT $STACK $APP
# Set up required tools
#
# This recipe installs the necessary binaries for GitHub Actions and Dagger.
setup: install-gha-binary install-dagger-binary
# Install GitHub Actions binary
#
# Downloads and installs the GitHub Actions binary appropriate for the current
# platform.
[group('setup-tools')]
install-gha-binary:
@curl -L -o {{action_bin}} {{gha_download_url}}
@chmod +x {{action_bin}}
# Install Dagger binary
#
# Downloads and installs the Dagger binary appropriate for the current platform.
[group('setup-tools')]
install-dagger-binary:
{{action_bin}} sd --dagger-version {{dagger_version}} --dagger-bin-dir {{bin_path}} --dagger-file {{dagger_file}}
# Export kubectl configuration
#
# This recipe generates a kubectl configuration file for accessing a Kubernetes
# cluster.
#
# Args:
# cluster: The name of the Kubernetes cluster
# cluster-state: The GCS bucket containing the cluster state
# gcp-credentials-file: Path to the GCP credentials file
export-kubectl cluster cluster-state gcp-credentials-file: setup
#!/usr/bin/env bash
set -euxo pipefail
{{dagger_bin}} call -m {{kops_module}} \
with-kops --version={{kops_version}} with-kubectl --version={{kubectl_version}} \
with-state-storage --storage={{cluster-state}} \
with-credentials --credentials={{gcp-credentials-file}} \
with-cluster --name={{cluster}} \
export-kubectl --output={{kubectl_file}}
# Deploy a backend application without building a new Docker image
#
# This recipe deploys a backend application using an existing Docker image.
# It creates a GitHub deployment, sets up Kubernetes configuration, and deploys
# the application using Pulumi without building a new Docker image.
#
# Args:
# cluster: The name of the Kubernetes cluster
# cluster-state: The GCS bucket containing the cluster state
# pulumi-state: The Pulumi state backend URL
# gcp-credentials-file: Path to the GCP credentials file
# ref: The Git reference to deploy
# token: GitHub token for creating deployments
# user: Docker registry username
# pass: Docker registry password
#
# Environment variables required:
# APP: Application name
# DOCKER_IMAGE: Docker image name
# DOCKER_NAMESPACE: Docker namespace
# DOCKERFILE: Path to Dockerfile
# PROJECT: Pulumi project name
# STACK: Pulumi stack name
# ENVIRONMENT: Deployment environment
# REPOSITORY: GitHub repository in owner/repo format
deploy-buildless-backend cluster cluster-state pulumi-state gcp-credentials-file ref token user pass: setup
#!/usr/bin/env bash
set -euxo pipefail
# create github deployment
deployment_id=`{{dagger_bin}} call -m {{gh_deployment_module}} \
with-application --application=$APP \
with-docker-image --docker-image=$DOCKER_IMAGE \
with-docker-namespace --docker-namespace=$DOCKER_NAMESPACE \
with-dockerfile --dockerfile=$DOCKERFILE \
with-project --project=$PROJECT \
with-stack --stack=$STACK \
with-environment --environment=$ENVIRONMENT \
with-kubectl-file --kubectl-file={{kubectl_file}} \
with-repository --repository=$REPOSITORY \
with-ref --ref={{ref}} \
create-github-deployment --token={{token}}`
# set deployment to in_progress
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status=in_progress
# generate kubectl file
{{dagger_bin}} call -m {{kops_module}} \
with-kops --version={{kops_version}} with-kubectl \
with-state-storage --storage={{cluster-state}} \
with-credentials --credentials={{gcp-credentials-file}} \
with-cluster --name={{cluster}} \
export-kubectl --output={{kubectl_file}}
#deploy the application
{{dagger_bin}} call -m {{deploy_module}} \
with-repository --repository=$REPOSITORY \
with-credentials --credentials={{gcp-credentials-file}} \
with-kube-config --config={{kubectl_file}} \
with-backend --backend={{pulumi-state}} \
with-pulumi --version={{pulumi_version}} \
deploy-backend-through-github --token={{token}} \
--deployment-id=$deployment_id
# finish with successful deployment
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status="success"
# Deploy a backend application
#
# This recipe builds and deploys a backend application.
# It creates a GitHub deployment, builds and publishes a Docker image,
# and deploys the application using Pulumi.
#
# Args:
# cluster: The name of the Kubernetes cluster
# cluster-state: The GCS bucket containing the cluster state
# pulumi-state: The Pulumi state backend URL
# gcp-credentials-file: Path to the GCP credentials file
# ref: The Git reference to deploy
# token: GitHub token for creating deployments
# user: Docker registry username
# pass: Docker registry password
#
# Environment variables required:
# APP: Application name
# DOCKER_IMAGE: Docker image name
# DOCKER_NAMESPACE: Docker namespace
# DOCKERFILE: Path to Dockerfile
# PROJECT: Pulumi project name
# STACK: Pulumi stack name
# ENVIRONMENT: Deployment environment
# REPOSITORY: GitHub repository in owner/repo format
deploy-backend cluster cluster-state pulumi-state gcp-credentials-file ref token user pass: setup
#!/usr/bin/env bash
set -euxo pipefail
# create github deployment
deployment_id=`{{dagger_bin}} call -m {{gh_deployment_module}} \
with-application --application=$APP \
with-docker-image --docker-image=$DOCKER_IMAGE \
with-docker-namespace --docker-namespace=$DOCKER_NAMESPACE \
with-dockerfile --dockerfile=$DOCKERFILE \
with-project --project=$PROJECT \
with-stack --stack=$STACK \
with-environment --environment=$ENVIRONMENT \
with-kubectl-file --kubectl-file={{kubectl_file}} \
with-repository --repository=$REPOSITORY \
with-ref --ref={{ref}} \
create-github-deployment --token={{token}}`
# set deployment to in_progress
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status=in_progress
# generate kubectl file
{{dagger_bin}} call -m {{kops_module}} \
with-kops --version={{kops_version}} with-kubectl \
with-state-storage --storage={{cluster-state}} \
with-credentials --credentials={{gcp-credentials-file}} \
with-cluster --name={{cluster}} \
export-kubectl --output={{kubectl_file}}
# create and publish docker image
{{dagger_bin}} call -m {{container_module}} \
with-repository --repository=$REPOSITORY --should-prepend=false \
publish-from-repo-with-deployment-id --token={{token}} \
--user={{user}} --password={{pass}} \
--deployment-id=$deployment_id
#deploy the application
{{dagger_bin}} call -m {{deploy_module}} \
with-repository --repository=$REPOSITORY \
with-credentials --credentials={{gcp-credentials-file}} \
with-kube-config --config={{kubectl_file}} \
with-backend --backend={{pulumi-state}} \
with-pulumi --version={{pulumi_version}} \
deploy-backend-through-github --token={{token}} \
--deployment-id=$deployment_id
# finish with successful deployment
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status="success"
# Deploy a frontend application
#
# This recipe builds and deploys a frontend application.
# It creates a GitHub deployment, builds and publishes a Docker image,
# and deploys the application using Pulumi.
#
# Args:
# cluster: The name of the Kubernetes cluster
# cluster-state: The GCS bucket containing the cluster state
# pulumi-state: The Pulumi state backend URL
# gcp-credentials-file: Path to the GCP credentials file
# ref: The Git reference to deploy
# token: GitHub token for creating deployments
# user: Docker registry username
# pass: Docker registry password
#
# Environment variables required:
# APP: Application name
# DOCKER_IMAGE: Docker image name
# DOCKER_NAMESPACE: Docker namespace
# DOCKERFILE: Path to Dockerfile
# PROJECT: Pulumi project name
# STACK: Pulumi stack name
# ENVIRONMENT: Deployment environment
# REPOSITORY: GitHub repository in owner/repo format
deploy-frontend cluster cluster-state pulumi-state gcp-credentials-file ref token user pass: setup
#!/usr/bin/env bash
set -euxo pipefail
# create github deployment
deployment_id=`{{dagger_bin}} call -m {{gh_deployment_module}} \
with-application --application=$APP \
with-docker-image --docker-image=$DOCKER_IMAGE \
with-docker-namespace --docker-namespace=$DOCKER_NAMESPACE \
with-dockerfile --dockerfile=$DOCKERFILE \
with-project --project=$PROJECT \
with-stack --stack=$STACK \
with-environment --environment=$ENVIRONMENT \
with-kubectl-file --kubectl-file={{kubectl_file}} \
with-repository --repository=$REPOSITORY \
with-ref --ref={{ref}} \
create-github-deployment --token={{token}}`
# set deployment to in_progress
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status=in_progress
# generate kubectl file
{{dagger_bin}} call -m {{kops_module}} \
with-kops --version={{kops_version}} with-kubectl \
with-state-storage --storage={{cluster-state}} \
with-credentials --credentials={{gcp-credentials-file}} \
with-cluster --name={{cluster}} \
export-kubectl --output={{kubectl_file}}
# create and publish docker image
{{dagger_bin}} call -m {{container_module}} \
with-repository --repository=$REPOSITORY --should-prepend=false \
publish-frontend-from-repo-with-deployment-id --token={{token}} \
--user={{user}} --password={{pass}} \
--deployment-id=$deployment_id
#deploy the application
{{dagger_bin}} call -m {{deploy_module}} \
with-repository --repository=$REPOSITORY \
with-credentials --credentials={{gcp-credentials-file}} \
with-kube-config --config={{kubectl_file}} \
with-backend --backend={{pulumi-state}} \
with-pulumi --version={{pulumi_version}} \
deploy-frontend-through-github --token={{token}} \
--deployment-id=$deployment_id
# finish with successful deployment
{{dagger_bin}} call -m {{gh_deployment_module}} \
with-repository --repository=$REPOSITORY \
set-deployment-status --token={{token}} \
--deployment-id=$deployment_id \
--status="success"
# Build and publish a Docker image
#
# This recipe builds and publishes a Docker image from a repository.
#
# Args:
# repository: GitHub repository in owner/repo format
# ref: The Git reference to use
# user: Docker registry username
# pass: Docker registry password
# namespace: Docker namespace
# image: Docker image name
# dockerfile: Path to Dockerfile
build-publish-image repository ref user pass namespace image dockerfile: setup
#!/usr/bin/env bash
set -euxo pipefail
{{dagger_bin}} call -m {{container_module}} \
with-ref --ref={{ref}} \
with-namespace --namespace={{namespace}} \
with-image --image={{image}} \
with-dockerfile --docker-file={{dockerfile}} \
with-repository --repository={{repository}} \
publish-from-repo \
--user={{user}} --password={{pass}}
# Build and publish ArangoDB with PostgreSQL image
#
# This recipe builds and publishes a specialized Docker image containing
# both ArangoDB and PostgreSQL.
#
# Args:
# ref: The Git reference to use
# user: Docker registry username
# pass: Docker registry password
# namespace: Docker namespace
# image: Docker image name
build-publish-arangopg-image ref user pass namespace image: setup
#!/usr/bin/env bash
set -euxo pipefail
{{dagger_bin}} call -m {{container_module}} \
with-ref --ref={{ref}} \
with-namespace --namespace={{namespace}} \
with-image --image={{image}} \
build-and-publish-arango-postgres-container \
--user={{user}} --password={{pass}}
# Lint a repository
#
# This recipe runs linting checks on a GitHub repository.
#
# Args:
# repository: GitHub repository in owner/repo format
# ref: The Git reference to lint
lint-repo repository ref: setup
#!/usr/bin/env bash
set -euxo pipefail
{{dagger_bin}} call -m golang \
lint-git-hub \
--repository={{repository}} \
--git-ref={{ref}}