Skip to content

Commit

Permalink
Copy existing binaries to Docker image (linera-io#1188)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
Andre da Silva authored Nov 1, 2023
1 parent 329c99d commit 6985d30
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ npm-debug.log
README-secret.md
# github related files
.github/
target
scripts/target
examples/target
Dockerfile
Expand Down
40 changes: 40 additions & 0 deletions docker/Dockerfile.copy
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion kubernetes/linera-validator/build_and_redeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ; }
Expand All @@ -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
Expand All @@ -42,6 +44,9 @@ handle_options() {
--clean)
clean=true
;;
--copy)
copy=true
;;
*)
echo "Invalid option: $1" >&2
usage
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6985d30

Please sign in to comment.