Skip to content

Commit ca34f74

Browse files
committed
Merge branch 'docker.nu' of github.com:windmill-labs/windmill into docker.nu
2 parents 669a1ff + cd6b35d commit ca34f74

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

docker/docker.nu

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#! /usr/bin/env nu
2+
# ------------------------------------ #
3+
# Build and Test docker images locally #
4+
# run: #
5+
# docker/docker.nu --help #
6+
# ------------------------------------ #
7+
8+
let branch = git branch --show-current;
9+
# TODO: Use podman
10+
let use_podman = false;
11+
12+
# Build and Test docker images
13+
#
14+
# For more info run:
15+
# docker.nu up --help
16+
# docker.nu build --help
17+
#
18+
# Should be invoked in repo root
19+
def main [] {
20+
./docker/docker.nu --help;
21+
}
22+
23+
# Run and Build (if not yet) docker image
24+
def "main up" [
25+
custom_dockerfile?: path # Any dockerfile that depends on root Dockerfile
26+
--features(-f): string = "deno_core" # Features that will be passed to base Dockerfile to compile windmill
27+
--dir(-d): path = ../windmill-ee-private # Path to EE repo
28+
] {
29+
let ident = get_ident $custom_dockerfile -f $features;
30+
if not (sudo docker images | into string | str contains $ident) {
31+
print $"($ident) is not found, building..."
32+
main build $custom_dockerfile -f $features -d $dir
33+
} else {
34+
print $"($ident) was found"
35+
}
36+
print $"Running: ($ident)"
37+
sudo WM_IMAGE=($ident) docker compose up --pull never
38+
}
39+
40+
# Build docker image
41+
def "main build" [
42+
custom_dockerfile?: path # Any dockerfile that depends on root Dockerfile
43+
--features(-f): string = "deno_core" # Features that will be passed to base Dockerfile to compile windmill
44+
--mock(-m) # Ignore building base image
45+
--dir(-d): path = ../windmill-ee-private # Path to EE repo
46+
] {
47+
if not $mock {
48+
build_base -f $features -d $dir;
49+
}
50+
if $custom_dockerfile != null {
51+
let ident = get_ident $custom_dockerfile -f $features;
52+
let tmpfile = patch $custom_dockerfile -f $features;
53+
print $"Building image by path ($custom_dockerfile) with ident: ($ident)"
54+
sudo docker build -f $tmpfile -t $ident ../
55+
}
56+
}
57+
58+
def build_base [
59+
--features(-f): string
60+
--dir(-d): path
61+
] {
62+
if not ($features | str contains "deno_core") {
63+
print "Warning! deno_core feature not enabled"
64+
print "Compilation may fail"
65+
}
66+
67+
if ($features | str contains "enterprise") {
68+
print "Building in EE mode"
69+
print $"EE repo path: ($dir)"
70+
(cd ./backend; ./substitute_ee_code.sh --copy --dir $dir)
71+
}
72+
73+
let ident = get_ident -f $features;
74+
print $"Building base image with ident: ($ident)"
75+
sudo docker build -t ($ident) ../ --build-arg features=($features)
76+
(cd ./backend; ./substitute_ee_code.sh --revert --dir $dir )
77+
}
78+
79+
def get_ident [
80+
custom_dockerfile?: path # Any dockerfile that depends on root Dockerfile
81+
--features(-f): string = "deno_core" # Features that will be passed to base Dockerfile to compile windmill
82+
] {
83+
let feat_postfix = $features | split row ',' | each { |e| $e | str trim --left --right } | sort | str join "-";
84+
if $custom_dockerfile != null {
85+
let df_postfix = $"($custom_dockerfile)" | split row "Dockerfile" | get 1 | str downcase;
86+
return ($branch | append $df_postfix | append $feat_postfix | str join "__");
87+
} else {
88+
return ($branch | append $feat_postfix | str join "-");
89+
}
90+
}
91+
92+
def patch [
93+
file: path
94+
--features(-f): string
95+
] {
96+
let tmpfile = $"(mktemp -d)/Dockerfile";
97+
open $file | str replace 'ghcr.io/windmill-labs/windmill-ee:dev' (get_ident -f $features) | save $tmpfile;
98+
return $tmpfile;
99+
}

0 commit comments

Comments
 (0)