forked from josh-project/josh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
286 lines (223 loc) · 6.34 KB
/
Dockerfile
File metadata and controls
286 lines (223 loc) · 6.34 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# syntax=docker/dockerfile:1.15.1@sha256:9857836c9ee4268391bb5b09f9f157f3c91bb15821bb77969642813b0d00518d
ARG ALPINE_VERSION=3.22.0
ARG ARCH=${TARGETARCH}
FROM alpine:${ALPINE_VERSION} AS rust-base
RUN apk add --no-cache ca-certificates gcc musl-dev
ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:${PATH}
ARG ARCH
# Update check: https://github.com/rust-lang/rustup/tags
ARG RUSTUP_VERSION=1.28.2
# Update check: https://github.com/rust-lang/rust/tags
ARG RUST_VERSION=1.89.0
# https://github.com/sfackler/rust-openssl/issues/1462
ENV RUSTFLAGS="-Ctarget-feature=-crt-static"
RUN <<EOF
set -eux
apk add --no-cache curl
if [ "$ARCH" = amd64 ]; then
rust_arch=x86_64;
elif [ "$ARCH" = arm64 ]; then
rust_arch=aarch64;
else
echo "Unsupported arch";
exit 1
fi
rust_arch=${rust_arch}-unknown-linux-musl
curl -sSL https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/${rust_arch}/rustup-init -o /tmp/rustup-init
chmod +x /tmp/rustup-init
/tmp/rustup-init \
-y \
--no-modify-path \
--profile minimal \
--default-toolchain ${RUST_VERSION} \
--default-host ${rust_arch}
rm /tmp/rustup-init
apk del curl
EOF
FROM rust-base AS dev-planner
# Update check: https://github.com/LukeMathWalker/cargo-chef/releases
RUN cargo install --version 0.1.72 cargo-chef
WORKDIR /usr/src/josh
COPY . .
ENV CARGO_TARGET_DIR=/opt/cargo-target
RUN cargo chef prepare --recipe-path recipe.json
FROM rust-base AS dev
RUN apk add --no-cache \
zlib-static \
zlib-dev \
openssl-libs-static \
openssl-dev \
curl-dev
WORKDIR /usr/src/josh
RUN rustup component add rustfmt
RUN cargo install --version 0.1.72 cargo-chef &&\
cargo install --verbose --version 0.14.0 graphql_client_cli
RUN apk add --no-cache \
bash \
coreutils \
curl \
cmake \
make \
expat-dev \
gettext \
python3 \
python3-dev \
libffi-dev \
py3-pip \
tree \
autoconf \
libgit2-dev \
psmisc
# Update check: https://github.com/git/git/tags
ARG GIT_VERSION=2.50.0
ENV PATH=${PATH}:/opt/git-install/bin
WORKDIR /usr/src/git
RUN <<EOF
set -e
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz
tar --extract --gzip --file git-${GIT_VERSION}.tar.gz
rm git-${GIT_VERSION}.tar.gz
cd git-${GIT_VERSION}
make configure
./configure \
--without-tcltk \
--prefix=/opt/git-install \
--exec-prefix=/opt/git-install
make -j$(nproc)
make install
mkdir /opt/git-install/etc
git config -f /opt/git-install/etc/gitconfig --add safe.directory "*"
git config -f /opt/git-install/etc/gitconfig protocol.file.allow "always"
EOF
# Update check: https://github.com/prysk/prysk/releases
ARG PRYSK_VERSION=0.20.0
# This is a Docker image so --break-system-packages is okay
RUN pip3 install --break-system-packages \
git+https://github.com/prysk/prysk.git@${PRYSK_VERSION}
RUN apk add --no-cache go nodejs npm openssh-client patch
COPY lfs-test-server lfs-test-server
RUN cd lfs-test-server && GOPATH=/opt/git-lfs go install
ENV PATH=${PATH}:/opt/git-lfs/bin
RUN <<EOF
set -eux
git clone https://github.com/git-lfs/git-lfs.git /usr/src/git-lfs
cd /usr/src/git-lfs
make
cp bin/git-lfs /opt/git-lfs/bin
EOF
WORKDIR /usr/src/josh
FROM dev AS dev-local
RUN <<EOF
set -eux
mkdir -p /opt/cache /josh/static
chmod 777 /opt/cache /josh/static
EOF
VOLUME /opt/cache
ENV CARGO_TARGET_DIR=/opt/cache/cargo-target
ENV CARGO_HOME=/opt/cache/cargo-cache
ENV GOCACHE=/opt/cache/go-cache
ENV GOPATH=/opt/cache/go-path
ENV GOFLAGS=-buildvcs=false
RUN npm config set cache /opt/cache/npm-cache --global
ARG USER_GID
ARG USER_UID
RUN <<EOF
set -eux
if [ ! $(getent group ${USER_GID}) ] ; then
addgroup -g ${USER_GID} dev
fi
adduser \
-u ${USER_UID} \
-G $(getent group ${USER_GID} | cut -d: -f1) \
-D \
-H \
-g '' \
dev
EOF
FROM dev AS dev-cache
COPY --from=dev-planner /usr/src/josh/recipe.json .
ENV CARGO_TARGET_DIR=/opt/cargo-target
FROM dev-cache AS dev-ci
RUN mkdir -p /josh/static && \
chmod 777 /josh/static
RUN cargo chef cook --workspace --recipe-path recipe.json
RUN mkdir -p josh-ui
COPY josh-ui/package.json josh-ui/package-lock.json josh-ui/
RUN cd josh-ui && npm install
FROM dev-cache AS build
RUN cargo chef cook --release --workspace --recipe-path recipe.json
COPY Cargo.toml Cargo.lock josh-ui josh-ui/
RUN cargo build -p josh-ui --release
COPY . .
RUN --mount=target=.git,from=git \
cargo build -p josh-proxy -p josh-ssh-shell --release
ARG ALPINE_VERSION
FROM alpine:${ALPINE_VERSION} AS run
RUN apk add --no-cache \
zlib \
openssl \
libexpat \
libgit2 \
libgcc \
libcurl \
ca-certificates \
openssh \
bash \
xz \
shadow \
gettext
COPY --from=dev --link=false /opt/git-install /opt/git-install
ENV PATH=${PATH}:/opt/git-install/bin
COPY --from=build --link=false /opt/cargo-target/release/josh-proxy /usr/bin/
COPY --from=build --link=false /opt/cargo-target/release/josh-ssh-shell /usr/bin/
COPY --from=build --link=false /usr/src/josh/static/ /josh/static/
ARG S6_OVERLAY_VERSION=3.2.1.0
ARG ARCH
RUN <<EOF
set -eux
apk add --no-cache curl
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz \
-o /tmp/s6-overlay-noarch.tar.xz
tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
rm /tmp/s6-overlay-noarch.tar.xz
if [ "$ARCH" = amd64 ]; then
s6_arch=x86_64;
elif [ "$ARCH" = arm64 ]; then
s6_arch=aarch64;
else
echo "Unsupported arch";
exit 1
fi
curl -sSL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${s6_arch}.tar.xz \
-o /tmp/s6-overlay-arch.tar.xz
tar -C / -Jxpf /tmp/s6-overlay-arch.tar.xz
rm /tmp/s6-overlay-arch.tar.xz
apk del curl
EOF
ARG GIT_GID_UID=2001
RUN <<EOF
set -eux
addgroup -g ${GIT_GID_UID} git
adduser \
-h /home/git \
-s /usr/bin/josh-ssh-shell \
-G git \
-D \
-u ${GIT_GID_UID} \
git
# https://unix.stackexchange.com/a/193131/336647
usermod -p '*' git
EOF
COPY docker/etc/ssh/sshd_config.template /etc/ssh/
ARG RC6_D=/etc/s6-overlay/s6-rc.d
COPY docker/josh-auth-key docker/josh-ensure-* /opt/josh-scripts/
COPY docker/s6-rc.d/. ${RC6_D}/
COPY docker/finish ${RC6_D}/josh/
COPY docker/finish ${RC6_D}/sshd/
WORKDIR /
ENV S6_KEEP_ENV=1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
ENV PATH=${PATH}:/command:/opt/josh-scripts
ENTRYPOINT ["/init"]