1
1
# build image
2
- FROM rust:1.47 .0 as cargo-build
2
+ FROM rust:1.66 .0 as cargo-build
3
3
4
4
# rust toolchain version
5
5
ARG RUST_TC_VER=stable
6
6
ARG KEY_SIZE=8
7
7
ARG COMMIT_HASH
8
+ ARG BUILD_PROFILE=release
9
+ ARG BUILD_TARGET=x86_64-unknown-linux-musl
8
10
9
11
RUN apt-get update \
10
12
&& apt-get install -y --no-install-recommends musl-tools \
11
13
&& rustup install $RUST_TC_VER \
12
14
&& rustup default $RUST_TC_VER \
13
- && rustup target add x86_64-unknown-linux-musl
15
+ && rustup target add $BUILD_TARGET
14
16
15
17
WORKDIR /usr/src/bob
16
18
17
19
# crates downloading and initial build
18
20
RUN mkdir -p bob/src bob-backend/src bob-common/src bob-grpc/src bob-apps/bin bob-access/src
19
21
RUN mkdir target
20
- ENV OUT_DIR /usr/src/bob/target
21
22
COPY Cargo.toml Cargo.toml
22
23
COPY bob/Cargo.toml bob/Cargo.toml
23
24
COPY bob-backend/Cargo.toml bob-backend/Cargo.toml
@@ -27,6 +28,14 @@ COPY bob-apps/Cargo.toml bob-apps/Cargo.toml
27
28
COPY bob-access/Cargo.toml bob-access/Cargo.toml
28
29
RUN sed -i "s|\[\[ bench\]\] |\[\[ bench_ignore\]\] |g" */Cargo.toml
29
30
31
+ # estimate build directory
32
+ RUN echo "$(case " $BUILD_PROFILE" in\
33
+ (" dev") echo " debug";;\
34
+ (" test") echo " debug";;\
35
+ (" bench") echo " release";;\
36
+ (*) echo " $BUILD_PROFILE";;\
37
+ esac)" >> ./build_profile_dir
38
+
30
39
RUN echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob/src/lib.rs \
31
40
&& echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob-backend/src/lib.rs \
32
41
&& echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob-common/src/lib.rs \
@@ -39,26 +48,28 @@ RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > bob/src/
39
48
&& echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob-apps/bin/brt.rs \
40
49
&& echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob-apps/bin/bobt.rs \
41
50
&& echo "fn main() {println!(\" if you see this, the build broke\" )}" > bob-access/src/lib.rs \
42
- && cargo build --release --target=x86_64-unknown-linux-musl
51
+ && cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET
43
52
44
53
45
54
# separate stage for proto build
46
55
RUN echo "fn main() {println!(\" if you see this, the build broke\" )} pub mod grpc {include!(\" bob_storage.rs\" );}" > bob-grpc/src/lib.rs \
47
56
&& mkdir -p bob-grpc/proto
48
57
COPY bob-grpc/proto/* bob-grpc/proto/
49
58
COPY bob-grpc/build.rs bob-grpc/build.rs
50
- RUN cargo build --release --target=x86_64-unknown-linux-musl \
51
- && rm -f target/x86_64-unknown-linux-musl/release /deps/bob* \
52
- && rm -f target/x86_64-unknown-linux-musl/release/ deps/libbob*
59
+ RUN cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET \
60
+ && rm -f target/$BUILD_TARGET/$(cat ./build_profile_dir) /deps/bob* \
61
+ && rm -f target/$BUILD_TARGET/$(cat ./build_profile_dir)/ deps/libbob*
53
62
54
63
# final build
55
64
COPY . .
56
65
ENV BOB_KEY_SIZE=${KEY_SIZE}
57
66
ENV BOB_COMMIT_HASH=${COMMIT_HASH}
58
- RUN cargo build --release --target=x86_64-unknown-linux-musl
67
+ RUN cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET \
68
+ && mkdir target/build_output \
69
+ && mv target/$BUILD_TARGET/$(cat ./build_profile_dir)/bobd target/build_output/bobd
59
70
60
71
# bobd image
61
- FROM alpine:3.12.0
72
+ FROM alpine:3.16
62
73
63
74
# SSH
64
75
ENV NOTVISIBLE "in users profile"
@@ -75,9 +86,8 @@ RUN apk update \
75
86
&& adduser --shell /bin/bash -G bobd -G wheel -S bobd
76
87
77
88
WORKDIR /home/bob/bin/
78
- COPY --from=cargo-build /usr/src/bob/target/x86_64-unknown-linux-musl/release/bobd .
79
- RUN chown bobd:bobd bobd \
80
- && mkdir /bob/log -p && chown bobd:bobd /bob/log -R \
89
+ COPY --chown=bobd:bobd --from=cargo-build /usr/src/bob/target/build_output/bobd .
90
+ RUN mkdir /bob/log -p && chown bobd:bobd /bob/log -R \
81
91
&& mkdir /bob/data/d1 -p && chown bobd:bobd /bob/data/d1 -R \
82
92
&& mkdir /bob/configs -p && chown bobd:bobd /bob/configs -R \
83
93
&& mkdir ~/.ssh \
@@ -103,9 +113,7 @@ RUN chown bobd:bobd bobd \
103
113
104
114
COPY dockerfiles/default-configs/ /bob/configs
105
115
106
- EXPOSE 80
107
- EXPOSE 22
108
- EXPOSE 20000
116
+ EXPOSE 22 80 20000
109
117
USER bobd
110
118
ENTRYPOINT ["/bin/bash" , "./run.sh" ]
111
119
CMD ["cluster.yaml" , "node.yaml" ]
0 commit comments