Skip to content

Commit 7869db9

Browse files
ZiktorinMax
andauthored
added configurable build profiles to dockerfiles (#721)
* added configurable build profiles to dockerfiles * update changelog * updated defaults * moved to changed * Revert "updated defaults" This reverts commit dece6e3. * updated defaults * fixed build profile dir not acesseible from stage 2 * added bob_storage to dockerignore * change rust ver and remove unnecessary lines * combined consecutive run commands * fixes * swapped musl for gnu in build * build docker images with itegration-test profile * added build target arg * fix * added build profile to docker image build section Co-authored-by: Max <[email protected]>
1 parent 99ede40 commit 7869db9

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ Cargo.lock
1414
/cluster_test
1515
/dockerfiles/*
1616
!/dockerfiles/default-configs
17-
/compose_examples
17+
/compose_examples
18+
bob-grpc/src/bob_storage.rs

.github/workflows/integration-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ jobs:
9898
strategy:
9999
matrix:
100100
key: [8, 16]
101+
env:
102+
BUILD_PROFILE: "integration-test"
101103
steps:
102104
- name: Checks-out repository
103105
uses: actions/checkout@v3
@@ -124,6 +126,7 @@ jobs:
124126
build-args: |
125127
COMMIT_HASH=${{ env.BOB_COMMIT_HASH }}
126128
KEY_SIZE=${{ matrix.key}}
129+
BUILD_PROFILE=${{ env.BUILD_PROFILE }}
127130
- name: Save image
128131
run: |
129132
docker save -o /tmp/bob-image-key${{ matrix.key }}.tar qoollo/bob:${{ env.VERSION }}-key${{ matrix.key }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Bob versions changelog
2020
- Remove 'termion' crate from dependencies (#718)
2121
- Make delete operation recoverable (#533)
2222
- Binaries sizes reduced for 'integration-test' profile (#727)
23+
- Configurable build profiles in Dockerfiles (#717)
2324

2425
#### Fixed
2526
- PID unsafe type conversion fixed (#719)

dockerfiles/alpine/Dockerfile

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# build image
2-
FROM rust:1.47.0 as cargo-build
2+
FROM rust:1.66.0 as cargo-build
33

44
# rust toolchain version
55
ARG RUST_TC_VER=stable
66
ARG KEY_SIZE=8
77
ARG COMMIT_HASH
8+
ARG BUILD_PROFILE=release
9+
ARG BUILD_TARGET=x86_64-unknown-linux-musl
810

911
RUN apt-get update \
1012
&& apt-get install -y --no-install-recommends musl-tools \
1113
&& rustup install $RUST_TC_VER \
1214
&& rustup default $RUST_TC_VER \
13-
&& rustup target add x86_64-unknown-linux-musl
15+
&& rustup target add $BUILD_TARGET
1416

1517
WORKDIR /usr/src/bob
1618

1719
# crates downloading and initial build
1820
RUN mkdir -p bob/src bob-backend/src bob-common/src bob-grpc/src bob-apps/bin bob-access/src
1921
RUN mkdir target
20-
ENV OUT_DIR /usr/src/bob/target
2122
COPY Cargo.toml Cargo.toml
2223
COPY bob/Cargo.toml bob/Cargo.toml
2324
COPY bob-backend/Cargo.toml bob-backend/Cargo.toml
@@ -27,6 +28,14 @@ COPY bob-apps/Cargo.toml bob-apps/Cargo.toml
2728
COPY bob-access/Cargo.toml bob-access/Cargo.toml
2829
RUN sed -i "s|\[\[bench\]\]|\[\[bench_ignore\]\]|g" */Cargo.toml
2930

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+
3039
RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > bob/src/lib.rs \
3140
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-backend/src/lib.rs \
3241
&& 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/
3948
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-apps/bin/brt.rs \
4049
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-apps/bin/bobt.rs \
4150
&& 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
4352

4453

4554
# separate stage for proto build
4655
RUN echo "fn main() {println!(\"if you see this, the build broke\")} pub mod grpc {include!(\"bob_storage.rs\");}" > bob-grpc/src/lib.rs \
4756
&& mkdir -p bob-grpc/proto
4857
COPY bob-grpc/proto/* bob-grpc/proto/
4958
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*
5362

5463
# final build
5564
COPY . .
5665
ENV BOB_KEY_SIZE=${KEY_SIZE}
5766
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
5970

6071
# bobd image
61-
FROM alpine:3.12.0
72+
FROM alpine:3.16
6273

6374
# SSH
6475
ENV NOTVISIBLE "in users profile"
@@ -75,9 +86,8 @@ RUN apk update \
7586
&& adduser --shell /bin/bash -G bobd -G wheel -S bobd
7687

7788
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 \
8191
&& mkdir /bob/data/d1 -p && chown bobd:bobd /bob/data/d1 -R \
8292
&& mkdir /bob/configs -p && chown bobd:bobd /bob/configs -R \
8393
&& mkdir ~/.ssh \
@@ -103,9 +113,7 @@ RUN chown bobd:bobd bobd \
103113

104114
COPY dockerfiles/default-configs/ /bob/configs
105115

106-
EXPOSE 80
107-
EXPOSE 22
108-
EXPOSE 20000
116+
EXPOSE 22 80 20000
109117
USER bobd
110118
ENTRYPOINT ["/bin/bash", "./run.sh"]
111119
CMD ["cluster.yaml", "node.yaml"]

dockerfiles/ubuntu/Dockerfile

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# build image
2-
FROM rust:1.47.0 as cargo-build
2+
FROM rust:1.66.0 as cargo-build
33

44
# rust toolchain version
55
ARG RUST_TC_VER=stable
66
ARG KEY_SIZE=8
77
ARG COMMIT_HASH
8+
ARG BUILD_PROFILE=release
9+
ARG BUILD_TARGET=x86_64-unknown-linux-gnu
810

911
RUN rustup install $RUST_TC_VER \
1012
&& rustup default $RUST_TC_VER \
11-
&& rustup target add x86_64-unknown-linux-gnu
13+
&& rustup target add $BUILD_TARGET
1214

1315
WORKDIR /usr/src/bob
1416

1517
# crates downloading and initial build
1618
RUN mkdir -p bob/src bob-backend/src bob-common/src bob-grpc/src bob-apps/bin bob-access/src
1719
RUN mkdir target
18-
ENV OUT_DIR /usr/src/bob/target
1920
COPY Cargo.toml Cargo.toml
2021
COPY bob/Cargo.toml bob/Cargo.toml
2122
COPY bob-backend/Cargo.toml bob-backend/Cargo.toml
@@ -25,6 +26,14 @@ COPY bob-apps/Cargo.toml bob-apps/Cargo.toml
2526
COPY bob-access/Cargo.toml bob-access/Cargo.toml
2627
RUN sed -i "s|\[\[bench\]\]|\[\[bench_ignore\]\]|g" */Cargo.toml
2728

29+
# estimate build directory
30+
RUN echo "$(case "$BUILD_PROFILE" in\
31+
("dev") echo "debug";;\
32+
("test") echo "debug";;\
33+
("bench") echo "release";;\
34+
(*) echo "$BUILD_PROFILE";;\
35+
esac)" >> ./build_profile_dir
36+
2837
RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > bob/src/lib.rs \
2938
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-backend/src/lib.rs \
3039
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-common/src/lib.rs \
@@ -37,23 +46,25 @@ RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > bob/src/
3746
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-apps/bin/brt.rs \
3847
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-apps/bin/bobt.rs \
3948
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > bob-access/src/lib.rs \
40-
&& cargo build --release --target=x86_64-unknown-linux-gnu
49+
&& cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET
4150

4251

4352
# separate stage for proto build
4453
RUN echo "fn main() {println!(\"if you see this, the build broke\")} pub mod grpc {include!(\"bob_storage.rs\");}" > bob-grpc/src/lib.rs \
4554
&& mkdir -p bob-grpc/proto
4655
COPY bob-grpc/proto/* bob-grpc/proto/
4756
COPY bob-grpc/build.rs bob-grpc/build.rs
48-
RUN cargo build --release --target=x86_64-unknown-linux-gnu \
49-
&& rm -f target/x86_64-unknown-linux-gnu/release/deps/bob* \
50-
&& rm -f target/x86_64-unknown-linux-gnu/release/deps/libbob*
57+
RUN cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET \
58+
&& rm -f target/$BUILD_TARGET/$(cat ./build_profile_dir)/deps/bob* \
59+
&& rm -f target/$BUILD_TARGET/$(cat ./build_profile_dir)/deps/libbob*
5160

5261
# final build
5362
COPY . .
5463
ENV BOB_KEY_SIZE=${KEY_SIZE}
5564
ENV BOB_COMMIT_HASH=${COMMIT_HASH}
56-
RUN cargo build --release --target=x86_64-unknown-linux-gnu
65+
RUN cargo build --profile=${BUILD_PROFILE} --target=$BUILD_TARGET \
66+
&& mkdir target/build_output \
67+
&& mv target/$BUILD_TARGET/$(cat ./build_profile_dir)/bobd target/build_output/bobd
5768

5869
# bobd image
5970
FROM ubuntu:20.04
@@ -76,9 +87,8 @@ RUN apt-get update \
7687
&& rm -rf /var/lib/apt/lists/*
7788

7889
WORKDIR /home/bob/bin/
79-
COPY --from=cargo-build /usr/src/bob/target/x86_64-unknown-linux-gnu/release/bobd .
80-
RUN chown bobd:bobd bobd \
81-
&& mkdir /bob/log -p && chown bobd:bobd /bob/log -R \
90+
COPY --chown=bobd:bobd --from=cargo-build /usr/src/bob/target/build_output/bobd .
91+
RUN mkdir /bob/log -p && chown bobd:bobd /bob/log -R \
8292
&& mkdir /bob/data/d1 -p && chown bobd:bobd /bob/data/d1 -R \
8393
&& mkdir /bob/configs -p && chown bobd:bobd /bob/configs -R \
8494
&& mkdir ~/.ssh \
@@ -104,9 +114,7 @@ RUN chown bobd:bobd bobd \
104114

105115
COPY dockerfiles/default-configs/ /bob/configs
106116

107-
EXPOSE 80
108-
EXPOSE 22
109-
EXPOSE 20000
117+
EXPOSE 22 80 20000
110118
USER bobd
111119
ENTRYPOINT ["./run.sh"]
112120
CMD ["cluster.yaml", "node.yaml"]

0 commit comments

Comments
 (0)