Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightnode docker #726

Merged
merged 23 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ coverage.*

contracts/broadcast

lightnode/docker/build-info.txt
lightnode/docker/args.sh

.idea
30 changes: 30 additions & 0 deletions lightnode/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SHELL := /bin/bash

# Clean the light node build files.
clean:
rm -rf ./bin

# Build the light node.
build: clean
go mod tidy
go build -o ./bin/lnode ./main

# Run the light node.
run: build
./bin/lnode

# Delete the docker images for the light node.
clean-docker:
./docker/clean.sh

# Build the docker images for the light node.
build-docker:
./docker/build.sh

# Run the docker image for the light node.
run-docker:
./docker/run.sh

# Open an interactive bash shell inside the light node docker container. Useful for debugging issues with the image.
debug-docker:
./docker/debug.sh
48 changes: 48 additions & 0 deletions lightnode/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM golang:1.21.12-bookworm AS base

# Install core dependencies
RUN apt update
RUN apt install -y build-essential

# Set up lnode user
RUN useradd -m -s /bin/bash lnode
USER lnode
WORKDIR /home/lnode
# Remove default crud
RUN rm .bashrc
RUN rm .bash_logout
RUN rm .profile

# Copy go.mod and download dependencies without copying the entire repository.
# Prevents us from downloading dependencies every time we make a change to the repository.
RUN mkdir -p /home/lnode/eigenda
COPY --chown=lnode go.mod /home/lnode/eigenda/go.mod
COPY --chown=lnode go.sum /home/lnode/eigenda/go.sum
WORKDIR /home/lnode/eigenda
RUN go mod download

# Copy the remainder of the eigenda repository
COPY --chown=lnode . /home/lnode/eigenda

# Download all go dependencies and build the binary.
WORKDIR /home/lnode/eigenda/lightnode
RUN make build

# In order to equip this image with a shell for debugging,
# swap out the "FROM scratch" below with "FROM golang:1.21.12-bookworm"
FROM scratch AS final

# Copy over files needed for lnode user.
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group

USER lnode
WORKDIR /home/lnode

# Copy the executable binary.
COPY --from=base /home/lnode/eigenda/lightnode/bin/lnode /home/lnode/lnode

# Run the light node when the container starts.
CMD ["/home/lnode/lnode"]
13 changes: 13 additions & 0 deletions lightnode/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# The location where this script can be found.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

docker build \
--build-arg="REPO_ROOT=${REPO_ROOT}" \
-f "lightnode/docker/Dockerfile" \
--tag lnode:latest \
.
5 changes: 5 additions & 0 deletions lightnode/docker/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# Cleans the docker image and all cached steps.
docker image rm lnode 2> /dev/null || true
docker builder prune -f
13 changes: 13 additions & 0 deletions lightnode/docker/debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Starts the container with an interactive bash shell. This is useful for debugging the container.

# Do setup for the data directory. This is a directory where data that needs
# to persist in-between container runs is stored.
source ./docker/setup-data-dir.sh

docker container run \
--mount "type=bind,source=${DATA_PATH},target=/home/lnode/data" \
--rm \
-it \
lnode bash
5 changes: 5 additions & 0 deletions lightnode/docker/default-args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default arguments for building the docker image.
# To override these values locally, create a file named `args.sh` in the same directory. 'args.sh' is ignored by git.

# The location on the host file system where light node data will be stored.
export DATA_PATH=~/.lnode-data
12 changes: 12 additions & 0 deletions lightnode/docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Starts the container and runs the light node.

# Do setup for the data directory. This is a directory where data that needs
# to persist in-between container runs is stored.
source ./docker/setup-data-dir.sh

docker run \
--rm \
--mount "type=bind,source=${DATA_PATH},target=/home/lnode/data" \
lnode
13 changes: 13 additions & 0 deletions lightnode/docker/setup-data-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Sets up the data directory for the light node container.

# Default arguments.
source docker/default-args.sh
# Local overrides for arguments.
source docker/args.sh

# Create the data directory if it doesn't exist.
mkdir -p $DATA_PATH

echo "Using data directory $DATA_PATH"
8 changes: 8 additions & 0 deletions lightnode/main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "fmt"

// main is the entrypoint for the light node.
func main() {
fmt.Println("Hello world")
}
Loading