forked from iansinnott/prompta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
132 lines (102 loc) · 2.95 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1.3-labs
FROM node:20-slim as builder
# Set sensible shell
SHELL ["/bin/bash", "-e", "-c"]
# Install pnpm globally
RUN npm install -g pnpm
# Install needed debian packages
RUN <<EOF
apt-get update
DEBIAN_FRONTEND=noninteractive
apt install -y --no-install-recommends curl python-is-python3 pkg-config build-essential s6 nginx unzip
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOF
# Install app
ENV HOME=/home/prompta
ENV APP=$HOME/app
ENV SYNC_SERVER_PATH=/db/
ENV DATA=/data
# Create entrypoint, prompta user, and key directories
RUN <<EOF
cat <<EOT >/entrypoint.sh
#!/bin/bash
exec /usr/bin/s6-svscan $HOME/s6
EOT
useradd --home-dir $HOME --shell /bin/bash prompta
mkdir -p $APP $DATA
chown -R prompta:prompta $HOME $DATA /entrypoint.sh
chmod 755 /entrypoint.sh
EOF
# Do the rest as prompta user, in the app dir
USER prompta
WORKDIR $APP
# Copy in the code
COPY --chown=prompta:prompta . .
# Make client app's default sync-server URI relative to URI on which it's hosted
RUN sed -r -i.bak "s|return.*https://prompta-production.up.railway.app.*$|return window.location.href.replace(/(https?:\\\/\\\/[^\\\/]+)(\\\/.*)?$/, \"\$1$SYNC_SERVER_PATH\");|" src/lib/sync/vlcn.ts
# Disable telemetry
RUN sed -r -i.bak 's!(cap\(|window.posthog.capture\()!return; // &!' src/lib/capture.ts
# Install packages for app
RUN pnpm install
# Build static client
RUN pnpm run ui:build-static
# Compile db server typescript
RUN pnpm tsc -p ./tsconfig.server.json
# Create s6 runscripts
WORKDIR $HOME
RUN <<EOF
mkdir -p s6/db s6/www
cat <<EOT >$HOME/s6/www/run
#!/bin/bash
/usr/sbin/nginx -c $APP/nginx.conf -g 'daemon off;'
EOT
cat <<EOT >$HOME/s6/db/run
#!/bin/bash
cd $APP
export PORT=8081
export HOST=127.0.0.1
export BODYLIMIT=100
export RAILWAY_VOLUME_MOUNT_PATH="$DATA"
node ./dist-server/server.js
EOT
chmod 755 $HOME/s6/*/run
cat <<'EOT' >$APP/nginx.conf
pid /tmp/nginx.pid;
worker_processes auto;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_body_temp_path /tmp;
proxy_temp_path /tmp;
fastcgi_temp_path /tmp;
uwsgi_temp_path /tmp;
scgi_temp_path /tmp;
access_log /dev/stdout;
error_log /dev/stderr;
server {
listen 8080;
location / {
root APP/build;
index index.html;
}
location ~ ^SYNC_SERVER_PATH(.*) {
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_pass http://127.0.0.1:8081/$1$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Cookie $http_cookie;
}
}
}
EOT
sed -ri "s|APP|$APP|g; s|SYNC_SERVER_PATH|$SYNC_SERVER_PATH|g" $APP/nginx.conf
EOF
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8080