-
Notifications
You must be signed in to change notification settings - Fork 5
/
justfile
174 lines (145 loc) · 5.86 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
# Default command when 'just' is run without arguments
# Run 'just <command>' to execute a command.
default: list
# Display help
help:
@printf "\nSee Makefile targets for just and direnv installation."
@printf "\nRun 'just -n <command>' to print what would be executed...\n\n"
@just --list --unsorted
@echo "\n...by running 'just <command>'.\n"
@echo "This message is printed by 'just help'."
@echo "Just 'just' will just list the available recipes.\n"
# List just recipes
list:
@just --list --unsorted
# List evaluated just variables
vars:
@just --evaluate
builder := env_var_or_default('BUILDER', 'podman')
container_user := "runner"
container_home := "/home" / container_user
container_work := container_home / "work"
git_username := env_var_or_default('GITHUB_USERNAME', 'pinellolab')
git_org_name := env_var_or_default('GITHUB_ORG_NAME', 'pinellolab')
git_repo_name := env_var_or_default('GITHUB_REPO_NAME', 'pyrovelocity')
git_branch_name := env_var_or_default('GITHUB_BRANCH_NAME', 'main')
container_registry := "ghcr.io/" + git_org_name + "/"
pod_accelerator_type := env_var_or_default('POD_ACCELERATOR_TYPE', 'nvidia-tesla-t4')
accelerator_node_selector := "gpu-type=" + pod_accelerator_type
container_type := "dev" # or "app"
container_image := if container_type == "dev" {
"pyrovelocitygpu"
} else if container_type == "app" {
"pyrovelocityapp"
} else {
error("container_type must be either 'dev' or 'app'")
}
container_tag := "latest"
pod_source_type := env_var_or_default('POD_SOURCE_TYPE', 'git')
pod_git_provider := env_var_or_default('POD_GIT_PROVIDER', 'github')
pod_disk_size := env_var_or_default('POD_DISK_SIZE', '400Gi')
pod_min_cpu := env_var_or_default('POD_MIN_CPU', '16')
pod_min_mem := env_var_or_default('POD_MIN_MEM', '64Gi')
pod_max_cpu := env_var_or_default('POD_MAX_CPU', '32')
pod_max_mem := env_var_or_default('POD_MAX_MEM', '96Gi')
pod_max_accel := env_var_or_default('POD_MAX_ACCEL', '1')
pod_resources := "requests.cpu=" + pod_min_cpu + ",requests.memory=" + pod_min_mem + ",limits.cpu=" + pod_max_cpu + ",limits.memory=" + pod_max_mem + ",limits.nvidia.com/gpu=" + pod_max_accel
architecture := if arch() == "x86_64" {
"amd64"
} else if arch() == "aarch64" {
"arm64"
} else {
error("unsupported architecture must be amd64 or arm64")
}
opsys := if os() == "macos" {
"darwin"
} else if os() == "linux" {
"linux"
} else {
error("unsupported operating system must be darwin or linux")
}
devpod_release := "latest" # or "v0.3.7" or "v0.4.0-alpha.4"
devpod_binary_url := if devpod_release == "latest" {
"https://github.com/loft-sh/devpod/releases/latest/download/devpod-" + opsys + "-" + architecture
} else {
"https://github.com/loft-sh/devpod/releases/download/" + devpod_release + "/devpod-" + opsys + "-" + architecture
}
# Install devpod (check/set: devpod_release)
[unix]
install-devpod:
curl -L -o devpod {{devpod_binary_url}} && \
sudo install -c -m 0755 devpod /usr/local/bin && \
rm -f devpod
which devpod
devpod version
# Print devpod info
devpod:
devpod version && echo
devpod context list
devpod provider list
devpod list
# Install and use devpod kubernetes provider
provider:
devpod provider add kubernetes --silent || true \
&& devpod provider use kubernetes
# Run latest container_image in current kube context
pod:
devpod up \
--debug \
--devcontainer-image {{container_registry}}{{container_image}}:{{container_tag}} \
--provider kubernetes \
--ide vscode \
--open-ide \
--source {{pod_source_type}}:https://{{pod_git_provider}}.com/{{git_username}}/{{git_repo_name}} \
--provider-option DISK_SIZE={{pod_disk_size}} \
--provider-option NODE_SELECTOR={{accelerator_node_selector}} \
--provider-option RESOURCES={{pod_resources}} \
{{container_image}}
# Stop devpod (check container_image hasn't changed with -n)
stop:
devpod stop {{container_image}}
# Delete devpod (check container_image hasn't changed with -n)
delete:
devpod delete {{container_image}}
## secrets
# Define the project variable
gcp_project_id := env_var_or_default('GCP_PROJECT_ID', 'development')
# Show existing secrets
show:
@teller show
# Create a secret with the given name
create-secret name:
@gcloud secrets create {{name}} --replication-policy="automatic" --project {{gcp_project_id}}
# Populate a single secret with the contents of a dotenv-formatted file
populate-single-secret name path:
@gcloud secrets versions add {{name}} --data-file={{path}} --project {{gcp_project_id}}
# Populate each line of a dotenv-formatted file as a separate secret
populate-separate-secrets path:
@while IFS= read -r line; do \
KEY=$(echo $line | cut -d '=' -f 1); \
VALUE=$(echo $line | cut -d '=' -f 2); \
gcloud secrets create $KEY --replication-policy="automatic" --project {{gcp_project_id}} 2>/dev/null; \
printf "$VALUE" | gcloud secrets versions add $KEY --data-file=- --project {{gcp_project_id}}; \
done < {{path}}
# Complete process: Create a secret and populate it with the entire contents of a dotenv file
create-and-populate-single-secret name path:
@just create-secret {{name}}
@just populate-single-secret {{name}} {{path}}
# Complete process: Create and populate separate secrets for each line in the dotenv file
create-and-populate-separate-secrets path:
@just populate-separate-secrets {{path}}
# Retrieve the contents of a given secret
get-secret name:
@gcloud secrets versions access latest --secret={{name}} --project={{gcp_project_id}}
# Create empty dotenv from template
seed-dotenv:
@cp .template.env .env
# Export unique secrets to dotenv format
export:
@teller export env | sort | uniq | grep -v '^$' > .secrets.env
# Check secrets are available in teller shell.
check-secrets:
@printf "Check teller environment for secrets\n\n"
@teller run -s -- env | grep -E 'GITHUB|CACHIX' | teller redact
get-kubeconfig:
@teller run -s -- printenv KUBECONFIG > dev-kubeconfig.yaml