Skip to content

Commit

Permalink
Amend 2-phase docker image building
Browse files Browse the repository at this point in the history
  • Loading branch information
doyoubi committed Jan 2, 2021
1 parent 137e049 commit 2b98f7a
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 179 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/target
**/*.rs.bk
examples/target_volume/
chaostest/__pycache__/
chaostest/chaos-docker-compose.yml
*.pyc
Expand Down
11 changes: 4 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde = "1.0"
serde_derive = "1.0.88"
serde_json = "1.0"
log = "0.4"
env_logger = "0.6.0"
env_logger = "0.8.2"
scopeguard = "1.1.0"
itertools = "0.8.0"
futures-batch = "0.6.0"
Expand Down
35 changes: 1 addition & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,13 @@ broker2:
flame:
sudo flamegraph -o $(name).svg target/release/server_proxy conf/server-proxy.toml

# Debug image and release image use different ways for building image.
# For faster rebuild, builder image will only build the binaries and move it out
# to the host by shared volume. The debug undermoon image will not get the image
# when being built. Instead we need to specify the volume to `insert` the binary
# to the debug undermoon image.
docker-build-image:
docker image build -f examples/Dockerfile-builder -t undermoon_builder .
sh scripts/dkrebuild.sh
docker image build -f examples/Dockerfile-undermoon -t undermoon .

docker-rebuild-bin:
sh scripts/dkrebuild.sh

# Image for testing undermoon-operator
docker-build-test-image:
rm -f examples/target_volume/debug/*
rm -f examples/target_volume/release/*
docker image build -f examples/Dockerfile-builder-test -t undermoon_builder_test .
mkdir -p ./examples/target_volume/debug
docker rm undermoon-builder-container-debug || true
docker create -it --name undermoon-builder-container-debug undermoon_builder_test bash
docker cp undermoon-builder-container-debug:/undermoon/target/debug/server_proxy ./examples/target_volume/debug/
docker cp undermoon-builder-container-debug:/undermoon/target/debug/coordinator ./examples/target_volume/debug/
docker cp undermoon-builder-container-debug:/undermoon/target/debug/mem_broker ./examples/target_volume/debug/
docker rm undermoon-builder-container-debug
docker image build -f examples/Dockerfile-undermoon-test -t undermoon_test .

# The release builder will build the binaries and move it out by `docker cp`.
# When the release undermoon image is built, the binaries will be moved into it.
docker-build-release:
rm -f examples/target_volume/debug/*
rm -f examples/target_volume/release/*
docker image build -f examples/Dockerfile-builder-release -t undermoon_builder_release .
mkdir -p ./examples/target_volume/release
docker rm undermoon-builder-container || true
docker create -it --name undermoon-builder-container undermoon_builder_release bash
docker cp undermoon-builder-container:/undermoon/target/release/server_proxy ./examples/target_volume/release/
docker cp undermoon-builder-container:/undermoon/target/release/coordinator ./examples/target_volume/release/
docker cp undermoon-builder-container:/undermoon/target/release/mem_broker ./examples/target_volume/release/
docker rm undermoon-builder-container
docker image build -f examples/Dockerfile-undermoon-release -t undermoon .

docker-mem-broker:
Expand Down Expand Up @@ -113,6 +80,6 @@ chaos-test:
func-test:
python chaostest/random_test.py exit-on-error

.PHONY: build test lint release server coord test_broker flame docker-build-image docker-multi-redis docker-multi-shard docker-failover docker-mem-broker \
.PHONY: build test lint release server coord test_broker flame docker-multi-redis docker-multi-shard docker-failover docker-mem-broker \
start-func-test start-chaos stop-chaos list-chaos-services chaos-test func-test

10 changes: 4 additions & 6 deletions chaostest/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ python chaostest/render_compose.py mem_broker [enable_failure]

Build `undermoon`:
```
make docker-build-image
```

Or rebuild if the source codes are changed:
```
make docker-rebuild-bin
make docker-build-release-image
// or
make docker-build-test-image
docker tag undermoon_test undermoon
```

Start Docker Swarm:
Expand Down
12 changes: 3 additions & 9 deletions chaostest/test_stack_mem_broker.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ services:
restart_policy:
condition: any
delay: 30s
volumes:
- ${PWD}/examples/target_volume:/undermoon/target
command: /undermoon/target/debug/mem_broker
command: mem_broker
ports:
- "{{ broker_port }}:{{ broker_port }}"
environment:
Expand All @@ -27,9 +25,7 @@ coordinator{{ coordinator_id }}:
restart_policy:
condition: any
delay: 30s
volumes:
- ${PWD}/examples/target_volume:/undermoon/target
command: /undermoon/target/debug/coordinator
command: coordinator
environment:
- RUST_LOG=undermoon=debug,coordinator=debug
- RUST_BACKTRACE=full
Expand Down Expand Up @@ -60,9 +56,7 @@ server_proxy{{ proxy_port }}:
restart_policy:
condition: any
delay: 30s
volumes:
- ${PWD}/examples/target_volume:/undermoon/target
command: /undermoon/target/debug/server_proxy
command: server_proxy
ports:
- "{{ proxy_port }}:{{ proxy_port }}"
environment:
Expand Down
2 changes: 1 addition & 1 deletion docs/docker_compose_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ make docker-mem-broker-example

Or build it yourself and run the `undermoon` docker image:
```bash
$ make docker-build-image
$ make docker-build-test-image
$ make docker-mem-broker
```

Expand Down
16 changes: 0 additions & 16 deletions examples/Dockerfile-builder

This file was deleted.

7 changes: 0 additions & 7 deletions examples/Dockerfile-builder-release

This file was deleted.

7 changes: 0 additions & 7 deletions examples/Dockerfile-builder-test

This file was deleted.

5 changes: 0 additions & 5 deletions examples/Dockerfile-undermoon

This file was deleted.

30 changes: 26 additions & 4 deletions examples/Dockerfile-undermoon-release
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
FROM rust:1.43-buster
# Use https://crates.io/crates/cargo-chef to cache dependencies.

FROM rust:1.49-buster as planner
WORKDIR /undermoon
RUN cargo install cargo-chef
COPY src /undermoon/src
COPY Cargo.toml Cargo.lock /undermoon/
RUN cargo chef prepare --recipe-path recipe.json

COPY ./examples/target_volume/release/server_proxy /bin/
COPY ./examples/target_volume/release/coordinator /bin/
COPY ./examples/target_volume/release/mem_broker /bin/
FROM rust:1.49-buster as cacher
WORKDIR /undermoon
RUN cargo install cargo-chef
COPY --from=planner /undermoon/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

FROM rust:1.49-buster as builder
WORKDIR /undermoon
COPY src /undermoon/src
COPY Cargo.toml Cargo.lock /undermoon/
# Copy over the cached dependencies
COPY --from=cacher /undermoon/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
RUN cargo build --release

FROM debian:buster as undermoon
WORKDIR /undermoon
COPY --from=builder /undermoon/target/release/server_proxy /bin
COPY --from=builder /undermoon/target/release/coordinator /bin
COPY --from=builder /undermoon/target/release/mem_broker /bin
30 changes: 26 additions & 4 deletions examples/Dockerfile-undermoon-test
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
FROM rust:1.43-buster
# Use https://crates.io/crates/cargo-chef to cache dependencies.

FROM rust:1.49-buster as planner
WORKDIR /undermoon
RUN cargo install cargo-chef
COPY src /undermoon/src
COPY Cargo.toml Cargo.lock /undermoon/
RUN cargo chef prepare --recipe-path recipe.json

COPY ./examples/target_volume/debug/server_proxy /bin/
COPY ./examples/target_volume/debug/coordinator /bin/
COPY ./examples/target_volume/debug/mem_broker /bin/
FROM rust:1.49-buster as cacher
WORKDIR /undermoon
RUN cargo install cargo-chef
COPY --from=planner /undermoon/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json

FROM rust:1.49-buster as builder
WORKDIR /undermoon
COPY src /undermoon/src
COPY Cargo.toml Cargo.lock /undermoon/
# Copy over the cached dependencies
COPY --from=cacher /undermoon/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
RUN cargo build

FROM debian:buster as undermoon
WORKDIR /undermoon
COPY --from=builder /undermoon/target/debug/server_proxy /bin
COPY --from=builder /undermoon/target/debug/coordinator /bin
COPY --from=builder /undermoon/target/debug/mem_broker /bin
6 changes: 0 additions & 6 deletions examples/copy_target.sh

This file was deleted.

27 changes: 9 additions & 18 deletions examples/docker-compose-mem-broker-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ version: '3'
services:
server_proxy1:
container_name: server_proxy1
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy1.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6001:6001"
Expand All @@ -18,11 +17,10 @@ services:
- "redis2"
server_proxy2:
container_name: server_proxy2
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy2.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6002:6002"
Expand All @@ -34,11 +32,10 @@ services:
- "redis4"
server_proxy3:
container_name: server_proxy3
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy3.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6003:6003"
Expand All @@ -51,11 +48,10 @@ services:

server_proxy4:
container_name: server_proxy4
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy4.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6004:6004"
Expand All @@ -67,11 +63,10 @@ services:
- "redis8"
server_proxy5:
container_name: server_proxy5
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy5.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6005:6005"
Expand All @@ -83,11 +78,10 @@ services:
- "redis10"
server_proxy6:
container_name: server_proxy6
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/server_proxy6.toml:/undermoon/config/server_proxy.toml
- ${PWD}/examples/run_proxy.sh:/undermoon/run_proxy.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_proxy.sh
ports:
- "6006:6006"
Expand All @@ -100,11 +94,10 @@ services:

coordinator1:
container_name: coordinator1
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/coordinator1.toml:/undermoon/config/coordinator.toml
- ${PWD}/examples/run_coordinator.sh:/undermoon/run_coordinator.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_coordinator.sh
environment:
- RUST_LOG=undermoon=debug,coordinator=debug
Expand All @@ -119,11 +112,10 @@ services:
- "mem_broker"
coordinator2:
container_name: coordinator2
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/coordinator2.toml:/undermoon/config/coordinator.toml
- ${PWD}/examples/run_coordinator.sh:/undermoon/run_coordinator.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_coordinator.sh
environment:
- RUST_LOG=undermoon=debug,coordinator=debug
Expand All @@ -139,11 +131,10 @@ services:

mem_broker:
container_name: mem_broker
image: "doyoubi/undermoon:0.3.0-buster"
image: "doyoubi/undermoon:0.4.1-buster"
volumes:
- ${PWD}/examples/mem-broker/mem-broker.toml:/undermoon/config/mem-broker.toml
- ${PWD}/examples/run_broker.sh:/undermoon/run_broker.sh
- ${PWD}/examples/target_volume:/undermoon/target
command: bash /undermoon/run_broker.sh
environment:
- RUST_LOG=undermoon=debug,mem_broker=debug
Expand Down
Loading

0 comments on commit 2b98f7a

Please sign in to comment.