-
Notifications
You must be signed in to change notification settings - Fork 17
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
Docker for development and preview of DApps in container environment #848
Changes from all commits
bdd2f07
e4201fb
08a2874
59ef409
d8cbd9e
0cc0555
a3b3f3b
d578a83
fdc6c5f
a11e24a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apps/bridge-dapp/build | ||
apps/bridge-dapp/node_modules | ||
apps/stats-dapp/build | ||
apps/stats-dapp/node_modules | ||
apps/webbsite/build | ||
apps/webbsite/node_modules | ||
build/ | ||
node_modules/ | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PUBLIC_IP_ADDRESS= | ||
NODE_ENV=development | ||
PORT_BRIDGE_DAPP=3000 | ||
PORT_STATS_DAPP=3001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: "3.8" | ||
services: | ||
dev: | ||
container_name: ${NAME_PROJECT}-dev | ||
restart: always | ||
build: | ||
context: "." | ||
dockerfile: ./docker/Dockerfile.dev | ||
args: | ||
- NAME_PROJECT=${NAME_PROJECT} | ||
- NAME_BRIDGE_DAPP=${NAME_BRIDGE_DAPP} | ||
- NAME_STATS_DAPP=${NAME_STATS_DAPP} | ||
- PORT_BRIDGE_DAPP=${PORT_BRIDGE_DAPP} | ||
- PORT_STATS_DAPP=${PORT_STATS_DAPP} | ||
volumes: | ||
- ./:/app/${NAME_PROJECT}:delegated | ||
- ignore:/app/${NAME_PROJECT}/node_modules | ||
ports: | ||
- "${PORT_BRIDGE_DAPP}:${PORT_BRIDGE_DAPP}" | ||
- "${PORT_STATS_DAPP}:${PORT_STATS_DAPP}" | ||
env_file: | ||
- .env | ||
|
||
volumes: | ||
ignore: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
trap "echo; exit" INT | ||
trap "echo; exit" HUP | ||
|
||
# try to fetch public IP address if value not set in .env | ||
PUBLIC_IP_ADDRESS_FALLBACK=$(wget http://ipecho.net/plain -O - -q ; echo) | ||
NAME_PROJECT_FALLBACK=webb-monorepo | ||
NAME_BRIDGE_DAPP_FALLBACK=bridge-dapp | ||
NAME_STATS_DAPP_FALLBACK=stats-dapp | ||
|
||
# assign fallback values for environment variables from .env.example incase | ||
# not declared in .env file. alternative approach is `echo ${X:=$X_FALLBACK}` | ||
source $(dirname "$0")/.env.example | ||
source $(dirname "$0")/.env | ||
export NAME_PROJECT=$(jq '.name' $PWD/package.json | sed 's/\"//g') | ||
export NAME_BRIDGE_DAPP=$(jq '.name' $PWD/apps/bridge-dapp/package.json | sed 's/\"//g' | sed 's/.*\///g') | ||
export NAME_STATS_DAPP=$(jq '.name' $PWD/apps/stats-dapp/package.json | sed 's/\"//g' | sed 's/.*\///g') | ||
export PORT_BRIDGE_DAPP PORT_STATS_DAPP | ||
echo ${PUBLIC_IP_ADDRESS:=$PUBLIC_IP_ADDRESS_FALLBACK} | ||
echo ${NAME_PROJECT:=$NAME_PROJECT_FALLBACK} | ||
echo ${NAME_BRIDGE_DAPP:=$NAME_BRIDGE_DAPP_FALLBACK} | ||
echo ${NAME_STATS_DAPP:=$NAME_STATS_DAPP_FALLBACK} | ||
if [ "$NODE_ENV" != "development" ]; then | ||
printf "\nError: NODE_ENV should be set to development in .env\n"; | ||
kill "$PPID"; exit 1; | ||
fi | ||
printf "\n*** Started building Docker container." | ||
printf "\n*** Please wait... \n***" | ||
DOCKER_BUILDKIT=0 docker compose -f docker-compose-dev.yml up --build -d | ||
if [ $? -ne 0 ]; then | ||
kill "$PPID"; exit 1; | ||
fi | ||
printf "\n*** Finished building Docker container.\n" | ||
if [ "$PUBLIC_IP_ADDRESS" != "" ]; then | ||
printf "\n*** Public IP address: http://${PUBLIC_IP_ADDRESS}\n***\n"; | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM node:gallium-alpine | ||
|
||
ARG NAME_PROJECT=${NAME_PROJECT} | ||
ARG NAME_BRIDGE_DAPP=${NAME_BRIDGE_DAPP} | ||
ARG NAME_STATS_DAPP=${NAME_STATS_DAPP} | ||
ARG PORT_BRIDGE_DAPP=${PORT_BRIDGE_DAPP} | ||
ARG PORT_STATS_DAPP=${PORT_STATS_DAPP} | ||
|
||
ARG PATH_PROJECT=/app/${NAME_PROJECT} | ||
|
||
ENV PATH=${PATH_PROJECT}/node_modules/.bin:$PATH | ||
|
||
WORKDIR ${PATH_PROJECT} | ||
|
||
COPY package.json yarn.lock ./ | ||
|
||
RUN apk update && apk add --update git python3 make g++ \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding this line to install to improve the time to install the npm packages. COPY yarn.lock . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've pushed commit adding this ae65b67 without yarn.lock copied it took although it now shows this when building
|
||
RUN yarn | ||
|
||
COPY . . | ||
|
||
EXPOSE ${PORT_BRIDGE_DAPP} | ||
EXPOSE ${PORT_STATS_DAPP} | ||
|
||
CMD tail -f /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding
wget
here, becausewget
does not exist by default in some OS.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think its a requirement as you have fallback namespaces in place, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good idea. i think it would be most seamless to embed a script like this in the docker-dev.sh script https://github.com/paritytech/scripts/blob/master/get-substrate.sh, where it installs the necessary dependencies depending on what operating system it detects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just tried a fresh install on my local macOS machine where i don't have wget and haven't created the .env file. when i run docker-dev.sh it outputs the following. so yes it uses the existing fallbacks defined in the docker-dev.sh file so it works even if wget command not found, but probably should detect their OS and try to install it.
i was also concerned because we don't have fallbacks for the ports
PORT_BRIDGE_DAPP
andPORT_STATS_DAPP
, but it doesn't get any further than trying to rundocker compose ...
command where expects an .env file to continue, since in docker-compose-dev.yml it has:i think we'd only be concerned about fallbacks if the user created an empty .env file but didn't follow the README.md instructions where it says to create it based on the .env.example with
cp .env.example .env