-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuilder
executable file
·160 lines (140 loc) · 4.71 KB
/
builder
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
#!/usr/bin/env bash
set -euo pipefail
# This is used, in concert with scripts/build/_build-server, to run Dark inside
# the devcontainer. There is a strong connection between these files and
# .circleci/config.yml, as well as devcontainer.yaml. Generally, if you add
# something to one of these files, there's an equivalent to be added in both
# .circleci/config.yml and devcontainer.yaml.
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
# Because we use `-v`
echo "We require bash >= 4. Assuming you're on a Mac and have homebrew installed,"
echo "upgrade by running \`brew install bash\`."
exit 1
fi
# Sometimes these dirs leak out of the container, causing confusion and
# slowness
rm -Rf node_modules
rm -Rf lib
rm -Rf backend/src/*/obj
rm -Rf backend/tests/*/obj
rm -Rf backend/Build
# See Dockerfile for an explanation of uid/gid.
gid="$(id -g)"
# Below is max($gid, 1000); on OS X, the user's group might be staff, with
# gid=20, which conflicts with ubuntu group dialout.
gid=$((gid > 1000 ? gid : 1000))
# --------------
# Build image from clean start
# --------------
if [[ ! -v NEVER_REBUILD_DOCKER ]]; then
echo "Building docker image"
# Always build for linux/amd64 (new OSX arm machines have emulation). This is
# slow on MacOS but it gets there eventually.
# Most of the work is done to enable arm64 builds, but rescript 9.1.4 won't
# build on arm64 (10 supposedly does), and dotnet won't support building wasm
# until dotnet 8 at the earliest.
docker buildx build --platform linux/amd64 -t dark-classic --build-arg uid="$(id -u)" --build-arg gid="$gid" .
echo "Removing running containers"
c=$(docker ps --filter "name=dark-builder" -q)
if [[ -n "${c}" ]]; then
docker kill "${c}";
fi
fi
# --------------
# --------------
echo "watching for local changes"
RELOAD_BROWSER=""
for i in "$@"
do
case $i in
--watch)
RELOAD_BROWSER=true
;;
esac
done
if [ -n "$RELOAD_BROWSER" ]; then
echo "Starting the browser reload script"
mkdir -p rundir/logs
scripts/build/_reload-browser > rundir/logs/browser.log 2>&1 &
fi
# --------------
# Mounts
# --------------
MOUNTS="--mount type=bind,src=$PWD,dst=/home/dark/app"
# Avoid docker syncing everything to the host, slowing compiles down by 5x
MOUNTS+=" --mount type=volume,src=dark_classic_fsharp_build,dst=/home/dark/app/backend/Build"
MOUNTS+=" --mount type=volume,src=dark_classic_lib,dst=/home/dark/app/lib"
MOUNTS+=" --mount type=volume,src=dark_classic_node_modules,dst=/home/dark/app/node_modules"
MOUNTS+=" --mount type=volume,src=dark_classic_nuget,dst=/home/dark/.nuget"
if [[ -e "$HOME/.config/gcloud" ]]; then
MOUNTS="$MOUNTS --mount type=bind,src=$HOME/.config/gcloud,dst=/home/dark/.config/gcloud"
fi
# make sure this exists first, so it doesn't get created as a directory
touch "$HOME/.dark_bash_history"
MOUNTS="$MOUNTS --mount type=bind,src=$HOME/.dark_bash_history,dst=/home/dark/.bash_history"
# --------------
# environment
# --------------
ENV="dev"
for i in "$@"
do
case $i in
--prodclone)
ENV="dev_prodclone"
;;
esac
done
ENV_FILE="config/$ENV"
if [[ -e "config/local" ]]; then
ENV_FILE="$ENV_FILE config/local"
fi
echo "Using env: $ENV_FILE"
# --------------
# create the network
# --------------
./scripts/devcontainer/_create-dark-dev-network
# --------------
# --------------
echo "Run the build"
# --init here keeps orphaned processes (`<defunct>`, in ps) from
# hanging around forever; see https://tech.fpcomplete.com/rust/pid1
# (above the fold) for a description of the process 1 problem in
# docker, and
# https://docs.docker.com/engine/reference/run/#specify-an-init-process
# for documentation of --init.
# -p 5433:5432 to expose the postgres DB to outside the container
# -p 2345:2345 to expose the cloud_sql_proxy to outside the container
# -p 9000:9000 to expose the F# api server
# -p 11001:11001 to expose the F# bwd server
# -cap-add & -security-opt to attach a gdb/strace to .net code
# --ulimit=nofile=65536:65536 to match CI
docker run \
--init \
--rm \
-i \
--platform linux/amd64 \
--dns 8.8.8.8 \
--dns 8.8.4.4 \
--name dark-classic-builder \
--hostname dark-classic-dev \
--env-file "$ENV_FILE" \
--env HOST_PWD="$PWD" \
--env IN_DEV_CONTAINER=true \
-v pgconf-classic:/etc/postgresql \
-v pglogs-classic:/var/log/postgresql \
-v pgdata-classic:/var/lib/postgresql \
-v cloudstorage:/home/dark/cloud-storage \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 9000:9000 \
-p 11001:11001 \
-p 5433:5432 \
-p 2345:2345 \
--security-opt seccomp=scripts/devcontainer/chrome-seccomp.json \
-w /home/dark/app \
--user "$(id -u):$gid" \
--cap-add=ALL \
--security-opt seccomp=unconfined \
--ulimit=nofile=65536:65536 \
$MOUNTS \
dark-classic \
scripts/build/_build-server "${@}"