From 621ec7cd2c05c411bb8092fd4fecf3feb92034e9 Mon Sep 17 00:00:00 2001 From: antondlr Date: Thu, 16 May 2024 15:47:15 +0300 Subject: [PATCH] Package siren (#234) --- .env.example | 10 +++++----- Dockerfile | 23 ----------------------- Dockerfile.dev | 15 ++++++++++----- Dockerfile.release | 3 --- Makefile | 4 ---- README.md | 28 +++++++++++++++------------- docker-entrypoint-dev.sh | 8 ++++++++ 7 files changed, 38 insertions(+), 53 deletions(-) delete mode 100644 Dockerfile delete mode 100644 Dockerfile.release create mode 100755 docker-entrypoint-dev.sh diff --git a/.env.example b/.env.example index 0cd94100..a4d8ce63 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ PORT=3000 -BACKEND_URL= -VALIDATOR_URL= -BEACON_URL= -API_TOKEN= -SESSION_PASSWORD= \ No newline at end of file +BACKEND_URL=http://127.0.0.1:3001 +BEACON_URL=http://your-BN-ip:5062 +VALIDATOR_URL=http://your-VC-ip:5052 +API_TOKEN=get-it-from-'.lighthouse/validators/api-token.txt' +SESSION_PASSWORD="your-password" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 33256115..00000000 --- a/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -ARG node_version=18 -ARG node_image=node:${node_version} - -# STAGE 1: builder -FROM $node_image AS builder - -COPY . /app/ -WORKDIR /app - -ENV NODE_ENV=development - -# install (dev) deps -# on GitHub runners, timeouts occur in emulated containers -RUN yarn --network-timeout 300000 - -ENV NODE_ENV=production -# build (prod) app -RUN yarn build - -# STAGE 2 -FROM nginx:alpine AS production - -COPY --from=builder /app/build/ /usr/share/nginx/html/ diff --git a/Dockerfile.dev b/Dockerfile.dev index b67b0450..8f4a7f59 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,12 +1,17 @@ ARG node_version=18 ARG node_image=node:${node_version} -FROM $node_image -ENV NODE_ENV=development +FROM $node_image AS dev -EXPOSE 5000/tcp COPY . /app/ +ENV NODE_ENV=development + +WORKDIR /app/backend +RUN yarn --network-timeout 300000 + WORKDIR /app +RUN yarn --network-timeout 300000 + +ENTRYPOINT /app/docker-entrypoint-dev.sh -RUN yarn install -CMD ["yarn", "run", "dev"] \ No newline at end of file +# run with docker run --rm -ti -p 3000:3000 -v $PWD/.env:/app/.env:ro your-image-name diff --git a/Dockerfile.release b/Dockerfile.release deleted file mode 100644 index 86e40597..00000000 --- a/Dockerfile.release +++ /dev/null @@ -1,3 +0,0 @@ -FROM nginx:alpine - -COPY html/ /usr/share/nginx/html/ diff --git a/Makefile b/Makefile index 366ab82a..57a1233f 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,6 @@ build: dev: yarn && yarn start -# Runs a docker production webserver -docker: - docker build -t siren . && docker run --rm -it --name siren -p 80:80 siren - # Compile into a number of releases release: yarn && yarn build-all diff --git a/README.md b/README.md index 1b3a4e8e..35852976 100644 --- a/README.md +++ b/README.md @@ -56,35 +56,37 @@ $ yarn dev #### Docker (Recommended) Docker is the recommended way to run a webserver that hosts Siren and can be -connected to via a web browser. We recommend this method as it established a -production-grade web-server to host the application. +connected to via a web browser. For now, we only have a development docker image. `docker` is required to be installed with the service running. -The docker image can be built and run via the Makefile by running: +Recommended config for using the development docker image (assuming the BN/VC API's are exposed on your localhost): ``` -$ make docker +PORT=3000 +BACKEND_URL=http://127.0.0.1:3001 +VALIDATOR_URL=http://host.docker.internal:5062 +BEACON_URL=http://host.docker.internal:5052 ``` -Alternatively, to run with Docker, the image needs to be built. From the repository directory -run: - +The docker image can be built and run with the following commands: ``` -$ docker build -t siren . +$ docker build -f Dockerfile.dev -t siren . ``` Then to run the image: ``` -$ docker run --rm -ti --name siren -p 80:80 siren +$ docker run --rm -ti -p 3000:3000 -v $PWD/.env:/app/.env:ro siren ``` +Linux users may want to add this flag: +`--add-host=host.docker.internal:host-gateway` + + +This will open port 3000 and allow your browser to connect. -This will open port 80 and allow your browser to connect. You can choose -another local port by modifying the command. For example `-p 8000:80` will open -port 8000. +To view Siren, simply go to `http://localhost:3000` in your web browser. -To view Siren, simply go to `http://localhost` in your web browser. # Running a Local Testnet diff --git a/docker-entrypoint-dev.sh b/docker-entrypoint-dev.sh new file mode 100755 index 00000000..54f5dd06 --- /dev/null +++ b/docker-entrypoint-dev.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /app/backend +yarn start & + +cd /app + +yarn dev