diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6786b95 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +scripts/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f2ec46 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.20.7-bookworm AS builder +COPY . /src +WORKDIR /src/cmd/monitor +RUN APPVERSION=$(git describe --tags --long --always | tail -c 11) && echo "package main\n\nfunc init() {\n\tappVersion = \"${APPVERSION}\"\n}" > local.go +RUN go build + +FROM debian:bookworm-slim AS usermanager +ARG UID=10000 +ARG GID=10000 +ARG USERNAME="mx" +ARG PACKAGES="ca-certificates" +RUN apt-get update && apt-get upgrade && apt-get install -y ${PACKAGES} +RUN adduser --uid ${UID} ${USERNAME} + +FROM scratch AS runner +ARG UID=10000 +ARG GID=10000 +ARG USERNAME="mx" +COPY --from=builder /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 +COPY --from=builder /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 +COPY --from=usermanager /etc/ssl/certs /etc/ssl/certs +COPY --from=usermanager /etc/passwd /etc/passwd +COPY --from=usermanager /etc/group /etc/group +USER ${USERNAME} +WORKDIR /home/mx +COPY --chown=${UID}:${GID} --from=builder /src/cmd/monitor/monitor /home/mx/monitor +ENTRYPOINT [ "/home/mx/monitor" ] + diff --git a/README.md b/README.md index 4a94f7d..5cd57a6 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,45 @@ and the application will automatically fetch the registered BLS keys for that id ## Installation +You can choose to run this tool either in a Docker on in a systemd service. + +### Docker Setup + +You need to have [docker](https://docs.docker.com/engine/install/) installed on your machine. + +Create a directory to save your configs in, and copy the 3 example files required for the tool to run : +```bash +mkdir +cp ./cmd/monitor/config/example/config.toml /config.toml +cp ./cmd/monitor/config/example/credentials.toml /credentials.toml +cp ./cmd/monitor/config/example/network1.list /network1.list +``` + +Customize your 3 files : +- config.toml is the tool global configuration +- credentials.toml is where you save your secrets +- network1.list is where you fill your addresses to monitor (⚠️ this file will be located in /network1.list in the container, **make sure to make this path correspond in the config.toml file** ⚠️) + +Build the image, use the Dockerfile ; +```bash +docker buildx build -t mx-chain-keys-monitor-go:latest -f Dockerfile . +``` + +Then, edit the lines 7-9 in `./docker-compose.yml` : +- `///config.toml:/config.toml:ro` +- `///credentials.toml:/credentials.toml:ro` +- `///network1.list:/network1.list:ro` +- You can append more networkX.list files if you want to + +If you want to provide extra arguments to the tool, add them under the `command` object. + +You're ready 🚀 + +```bash +docker compose up -d +``` + + ### Initial setup Although it's possible, it is not recommended to run the application as `root`. For that reason, a new user is required to be created. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..345b6e1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + mx-chain-keys-monitor-go: + image: mx-chain-keys-monitor-go:latest + container_name: mx-chain-keys-monitor-go + volumes: + - ./cmd/monitor/config/example/config.toml:/config.toml:ro + - ./cmd/monitor/config/example/credentials.toml:/credentials.toml:ro + - ./cmd/monitor/config/example/network1.list:/network1.list:ro + restart: always + command: + - '--config=/config.toml' + - '--credentials=/credentials.toml' + - '-log-level=*:DEBUG' \ No newline at end of file