forked from windmill-labs/windmill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.nu
More file actions
executable file
·166 lines (143 loc) · 5.24 KB
/
Copy pathdev.nu
File metadata and controls
executable file
·166 lines (143 loc) · 5.24 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
#! /usr/bin/env nu
# ------------------------------------ #
# Build and Test docker images locally #
# run: #
# docker/dev.nu --help #
# ------------------------------------ #
# NOTE:
# Does not work if built from git worktree branch
let branch = git branch --show-current;
# cp -f Caddyfile .dev-docker/Caddyfile
# --- Constraints --- #
def constraints [
custom_dockerfile?: path
features?: string
] {
# if ($features | str contains "enterprise") {
# print "Building in EE mode"
# print "Is windmill ee private repo mounted? [Y/n]";
# let inp = input listen --types [key]
# if ($inp.code != "y") {
# # print "You can use --auto-substitute(-s) to automatically mount ee private repo (TODO)"
# print "Aborted"
# return;
# }
# }
if not ($features | str contains "static_frontend") {
panic "If you compile without 'static_frontend' you won't be able to load frontend"
}
if ($features | str contains "enterprise") and not ($features | str contains "license") {
panic "If you build enterprise you also need to include 'license' feature"
}
}
# --- Patches --- #
# ./Dockerfile
def patch_main_dockerfile [
features?: string
wasm_pkg?: string
] {
let dockerfile = open ./Dockerfile
# Spread wasm parser
if $wasm_pkg != null {
$dockerfile
| str replace '# -- MACRO-SPREAD-WASM-PARSER-DEV-ONLY -- #' $"COPY ./backend/parsers/windmill-parser-wasm/pkg-($wasm_pkg) ./node_modules/windmill-parser-wasm-($wasm_pkg)"
| return $in
}
print $dockerfile
return $dockerfile
}
# ./docker/Dockerfile*
def patch_custom_dockerfile [
custom_dockerfile: path
features?: string
] {
open $custom_dockerfile
| str replace 'ghcr.io/windmill-labs/windmill-ee:dev' (get_ident -f $features)
| str replace 'ghcr.io/windmill-labs/windmill:dev' (get_ident -f $features)
| return $in
}
# ./docker-compose.yml
def patch_docker_compose [
custom_dockerfile?: path
features?: string
] {
mut compose = open ./docker-compose.yml
$compose.services.windmill_worker.pull_policy = "never"
$compose.services.windmill_worker_native.pull_policy = "never"
$compose.services.windmill_server.pull_policy = "never"
$compose.services.windmill_indexer.pull_policy = "never"
return ($compose | to yaml)
}
# Build and Test docker images
#
# For more info run:
# docker.nu up --help
# docker.nu build --help
#
# Should be invoked in repo root
def main [] {
./docker/dev.nu --help;
}
# TODO:
# Also we need single tmpdir for it
def kill [] {}
# Get tag for dockerfile + features
def "main tag" [
custom_dockerfile?: path # Any dockerfile that depends on root Dockerfile
--features(-f): string # Features that will be passed to base Dockerfile to compile windmill
] {
get_ident $custom_dockerfile -f $features
}
# Run and Build (if not yet) docker image
def "main up" [
custom_dockerfile?: path # Any dockerfile that depends on root Dockerfile
--features(-f): string = "static_frontend" # Features that will be passed to base Dockerfile to compile windmill
--wasm-pkg: string # Include unreleased wasm parser in docker image
--rebuild(-r) # Rebuild if there is existing image with same tag
--yes(-y) # Say yes for every confirmation (TODO)
--podman(-p) # Use podman as a backend (TODO)
] {
constraints $custom_dockerfile $features
# let base_ident = get_ident -f $features;
let ident = get_ident $custom_dockerfile -f $features;
if $rebuild or not (docker images | into string | str contains $ident) {
let base_ident = get_ident -f $features;
if $rebuild or not (docker images | into string | str contains $base_ident) {
print $"Building base image with ident: ($base_ident)"
docker build . -t ($base_ident) -f (wrap "Dockerfile" (patch_main_dockerfile $features $wasm_pkg)) --build-arg features=($features)
}
if $custom_dockerfile != null {
# let ident = get_ident $custom_dockerfile -f $features;
print $"Building image by path ($custom_dockerfile) with ident: ($ident)"
docker build -f (wrap "DockerfileCustom" (patch_custom_dockerfile $custom_dockerfile $features)) -t $ident /
}
} else {
print $"($ident) was found"
}
print $"Running: ($ident)"
WM_IMAGE=$"($ident)" docker compose -f (wrap "docker-compose.yml" (patch_docker_compose $custom_dockerfile $features)) up
}
# TODO
def clone_ee_private [] {
let rev = open backend/ee-repo-ref.txt
git clone --depth 1 git@github.com:windmill-labs/windmill-ee-private.git .docker.nu/private-ee-repo-rev-($rev)
# git checkout ddcfdfc18a9833a5fc4e62ad62a265ef1e06a0aa)
}
def get_ident [ custom_dockerfile?: path, --features(-f): string ] {
let feat_postfix = if $features != null {
$features | split row ',' | each { |e| $e | str trim --left --right } | sort | str join "-";
} else {
"no-features"
}
if $custom_dockerfile != null {
let df_postfix = $"($custom_dockerfile)" | split row "Dockerfile" | get 1 | str downcase;
return ($branch | append $df_postfix | append $feat_postfix | str join "__");
} else {
return ($branch | append $feat_postfix | str join "-");
}
}
def wrap [ filename content ] {
let tmpfile = ".dev-docker-wrapper-" ++ $filename;
$content | save -f $tmpfile
return $tmpfile
}