Skip to content

Commit

Permalink
add docs and dockerfile for portable blockscout rapid development
Browse files Browse the repository at this point in the history
  • Loading branch information
galxy25 committed Nov 17, 2023
1 parent 524c007 commit 2cc8c5b
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
52 changes: 52 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,58 @@ cd ../../
make refresh
```

#### Portable Docker Dev Environment

Requires
- vscode
- docker

Build an image that has all elixir and node dependnecies to run the app, and all current source code and compiled assets

```bash
make local
```

run a docker container using the above image

```bash
docker run -it -d -v ./blockscout/blockscout-base:/src/blockscout -v ./blockscout/patches:/src/patches kava-blockscout:local

# apply current patches
cd /blockscout/blockscout-base && git apply ../patches/*.patch && git add ./ && git commit -m "REVERT-ME-PATCH-COMMIT"
# REVERT this commit before pushing to origin for a PR)
```

Attach a [vs code editor dev container](https://code.visualstudio.com/docs/devcontainers/containers) to the running container (open command member, type/select Dev Containers: Attach to running container)

Now any code changes you make inside the container will be persisted on your local machine, and you can use the patch workflow below to upstream your code changes.

Create a patch of your changes to be applied when the development or production docker image is built

```bash
# from your host machine
cd /blockcout/blockscout-base
git diff > ../patches/NAME_OF_PATCH.patch
```

Some helpful commands

```bash
# from inside /src/blockscout of dev container
# fetch dependencies from all apps
mix deps.get
# compile sources for all apps (indexer, explorer)
mix compile

# if you want to just update / compile a single app, such as the indexer
# from inside /src/blockscout of dev container
cd /apps/indexer
# fetch dependencies for just this app
mix deps.get
# compile sources for just this app
mix compile
```

#### Indexer status

To see how far back the block explorer has indexed blocks, connect to the database and query to see what is the earliest block it has indexed, if these values change that means earlier and earlier blocks are being indexed (`refetch_needed` indicates whether the indexing was successful)
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ build:
cd blockscout && \
docker build ./ -f Dockerfile -t ${IMAGE_NAME}:${LOCAL_IMAGE_TAG} --build-arg BLOCKSCOUT_VERSION=${BLOCKSCOUT_DOCKER_VERSION}

local:
cd blockscout && \
docker build ./ -f local.Dockerfile -t ${IMAGE_NAME}:${LOCAL_IMAGE_TAG} --build-arg BLOCKSCOUT_VERSION=${BLOCKSCOUT_DOCKER_VERSION}

.PHONY: build-db-exporter
# build the exporter image
build-db-exporter:
Expand Down
82 changes: 82 additions & 0 deletions blockscout/local.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Raw version representing v5.3.1-beta
ARG BLOCKSCOUT_VERSION=5.3.1

#
# The backend-builder uses the official exlixir docker image that contains
# Elixir, Erlang, compatiable OTP version, and mix.
#
FROM elixir:1.14-otp-25 as backend-builder
ARG BLOCKSCOUT_VERSION

WORKDIR /src

# All elixir dependencies are already installed
# We only need git to clone and apply patches
RUN apt-get update \
&& apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*

# COPY patches first, since we want to apply after clone, but before compiling
# This does force a re-clone if there are patch changes, but also reduces our layers.
#
COPY ./patches /src/patches

# The order of the below steps must be kept the same
#
# Clone the blockscout repository
RUN git clone --depth 1 --branch v${BLOCKSCOUT_VERSION}-beta https://github.com/blockscout/blockscout.git
WORKDIR blockscout
# apply patches
RUN git apply /src/patches/*.patch
RUN mix local.hex --force
RUN mix local.rebar --force
# install prod dependencies
RUN mix deps.get
# compile minimal production optimized version of application
RUN mix compile
# The order of the above steps must be kept the same
#

#
# The frontend-builder copies builds the block_scout_web frontend and installs solc for the explorer using npm.
#

WORKDIR /src

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs \
build-essential && \
node --version && \
npm --version
# Build the user interface (block_scout_web/assets) and then install the solc npm package (explorer)
RUN cd blockscout/apps/block_scout_web/assets \
&& npm install \
&& NODE_ENV=prod npm run deploy \
&& cd ../../explorer \
&& npm install

#
# The runner uses debian 11 (bullseye), which matches the OS used in previous steps.
#
# For elixir applications, we must ensure the locale is UTF-8.
#
# In addition, we also ensure ca-certificates are up to date.
#
# FROM debian:11 as runner
# ARG BLOCKSCOUT_VERSION

# Install locale, update ca certs, install node for contract verification
RUN apt-get update \
&& apt-get install -y locales ca-certificates nodejs \
&& rm -rf /var/lib/apt/lists/* \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
&& update-ca-certificates

# Ensure utf8 locale is used
ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

WORKDIR /src/blockscout

#
CMD tail -f /dev/null

0 comments on commit 2cc8c5b

Please sign in to comment.