From 6985d30adcdebde5efd47dc8829fb936ec3ca205 Mon Sep 17 00:00:00 2001 From: Andre da Silva Date: Wed, 1 Nov 2023 11:48:48 -0300 Subject: [PATCH] Copy existing binaries to Docker image (#1188) ## Motivation Development cycles are slow when deploying a local cluster because of how slow the Docker build is, which also slows down CI. ## Proposal Let's have an option to build locally the binaries (outside of Docker) then just copy them over to build the image. This should speed up development cycles for people using Linux. AFAIK there are no Apple M1 Silicon Docker images that we could use, so people not using Linux (me) are out of luck on this. ## Test Plan This will be triggered in the following PR by CI, which we'll use as a test for this (I can't test it locally because I don't have a Linux machine) --- .dockerignore | 1 - docker/Dockerfile.copy | 40 +++++++++++++++++++ .../linera-validator/build_and_redeploy.sh | 9 ++++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 docker/Dockerfile.copy diff --git a/.dockerignore b/.dockerignore index 5515ca5fa6f..945bd5a2a3a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,7 +13,6 @@ npm-debug.log README-secret.md # github related files .github/ -target scripts/target examples/target Dockerfile diff --git a/docker/Dockerfile.copy b/docker/Dockerfile.copy new file mode 100644 index 00000000000..7c14961e70d --- /dev/null +++ b/docker/Dockerfile.copy @@ -0,0 +1,40 @@ +FROM debian:latest + +RUN mkdir -p /opt/linera + +WORKDIR /opt/linera + +# Copying binaries +COPY target/release/linera . +COPY target/release/linera-server . +COPY target/release/linera-proxy . +COPY target/release/linera-db . + +# Copying configuration files +COPY configuration/k8s-local/validator_1.toml . + +# Copy entrypoint +COPY docker/server-entrypoint.sh . +RUN chmod +x server-entrypoint.sh + +# Copy init +COPY docker/server-init.sh . +RUN chmod +x server-init.sh + +RUN apt-get update && apt-get install -y libssl-dev + +# Create configuration files for the validator according to the validator's config file. +# * Private server states are stored in `server*.json`. +# * `committee.json` is the public description of the Linera committee. +RUN ./linera-server generate --validators validator_1.toml --committee committee.json + +# Create configuration files for 1000 user chains. +# * Private chain states are stored in one local wallet `wallet.json`. +# * `genesis.json` will contain the initial balances of chains as well as the initial committee. +RUN ./linera \ + --wallet wallet.json \ + --storage rocksdb:linera.db \ + create-genesis-config 1000 \ + --genesis genesis.json \ + --initial-funding 100 \ + --committee committee.json diff --git a/kubernetes/linera-validator/build_and_redeploy.sh b/kubernetes/linera-validator/build_and_redeploy.sh index eb1931d3d48..d8648ed4b3d 100755 --- a/kubernetes/linera-validator/build_and_redeploy.sh +++ b/kubernetes/linera-validator/build_and_redeploy.sh @@ -6,6 +6,7 @@ cloud_mode=false port_forward=false do_build=true clean=false +copy=false # Guard clause check if required binaries are installed which kind > /dev/null || { echo "Error: kind not installed." ; exit 1 ; } @@ -20,6 +21,7 @@ usage() { echo " --port-forward Start port forwarding at the end of the script, so that the validator is accessible. Don't use this if you plan to use this terminal for something else after running this script" echo " --no-build Don't actually build another version of the Docker image, just use the existing one for the current mode (cloud or not)" echo " --clean Clean up DB state and delete kind cluster before starting a new one. This will guarantee that the Validator state will be clean for the new run" + echo " --copy Have the Dockerfile copy over the already built binaries in the target/release directory. Binaries need to be built beforehand. Works only when --cloud is NOT set" } # Function to handle options and arguments @@ -42,6 +44,9 @@ handle_options() { --clean) clean=true ;; + --copy) + copy=true + ;; *) echo "Invalid option: $1" >&2 usage @@ -86,7 +91,9 @@ if [ "$cloud_mode" = true ]; then else docker_image="linera-test:latest" if [ "$do_build" = true ]; then - if [ "$(uname -m)" = "x86_64" ]; then + if [ "$copy" = true ]; then + docker build -f ../../docker/Dockerfile.copy ../../ -t $docker_image || exit 1 + elif [ "$(uname -m)" = "x86_64" ]; then docker build -f ../../docker/Dockerfile.local ../../ -t $docker_image || exit 1 else docker build -f ../../docker/Dockerfile.local-aarch64 ../../ -t $docker_image || exit 1