-
Notifications
You must be signed in to change notification settings - Fork 352
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 production environments #261
Open
ltfschoen
wants to merge
15
commits into
jimmychu0807:main
Choose a base branch
from
ltfschoen:luke/docker-minimal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58ccd10
setup to run in docker container
ltfschoen 9dcdb86
wip
ltfschoen af4e211
finish script
ltfschoen ac7a70e
newline to dockerignore
ltfschoen a398684
remove comment clutter
ltfschoen f96ce9b
fix formatting
ltfschoen 5d53996
fix production
ltfschoen fb2f566
refactor
ltfschoen 8f2f741
add todo
ltfschoen d5a9ea9
wip
ltfschoen 1e66f98
wip
ltfschoen d35b6fd
simplify
ltfschoen 0a6b665
fixes
ltfschoen f44b2b5
reorder
ltfschoen 57c4216
fix image name
ltfschoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# items that do not need to be in a Docker image as they | ||
# are not used by the build system | ||
.circleci/ | ||
.git/ | ||
docker/Dockerfile.* | ||
.dockerignore | ||
.env | ||
.gitignore | ||
README.md | ||
docker-* | ||
|
||
# items that may be built during Docker image creation | ||
build/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
PUBLIC_IP_ADDRESS= | ||
# set to development or production | ||
NODE_ENV=development | ||
# React requires variable name to be `PORT` in development | ||
PORT=8000 | ||
PORT_PROD=8001 | ||
PORT_NGINX=80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
PUBLIC_IP_ADDRESS= | ||
# set to development or production | ||
NODE_ENV=development | ||
# React requires variable name to be `PORT` in development | ||
PORT=8000 | ||
PORT_PROD=8001 | ||
PORT_NGINX=80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ coverage | |
!.yarn/sdks | ||
!.yarn/versions | ||
.pnp.* | ||
docker-dev.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: "3.8" | ||
services: | ||
dev: | ||
container_name: ${APP_NAME}-dev | ||
restart: always | ||
build: | ||
context: "." | ||
dockerfile: ./docker/Dockerfile.dev | ||
args: | ||
- APP_NAME=${APP_NAME} | ||
- PORT=${PORT} | ||
volumes: | ||
- ./:/app/${APP_NAME}:delegated | ||
- ignore:/app/${APP_NAME}/node_modules | ||
ports: | ||
- "${PORT}:${PORT}" | ||
env_file: | ||
- .env | ||
|
||
volumes: | ||
ignore: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: "3.8" | ||
services: | ||
prod: | ||
container_name: ${APP_NAME}-prod | ||
restart: always | ||
build: | ||
context: "." | ||
dockerfile: ./docker/Dockerfile.prod | ||
args: | ||
- NODE_ENV=${NODE_ENV} | ||
- PORT_NGINX=${PORT_NGINX} | ||
- PORT_PROD=${PORT_PROD} | ||
- PUBLIC_URL=${PUBLIC_URL} | ||
volumes: | ||
- ./:/app:delegated | ||
- ignore:/app/node_modules | ||
ports: | ||
- ${PORT_PROD}:${PORT_NGINX} | ||
env_file: | ||
- .env | ||
|
||
volumes: | ||
ignore: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2017-2022 @polkadot authors & contributors | ||
# This software may be modified and distributed under the terms | ||
# of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
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) | ||
|
||
# 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 | ||
${PUBLIC_IP_ADDRESS:=$PUBLIC_IP_ADDRESS_FALLBACK} | ||
export APP_NAME=$(jq '.name' package.json | sed 's/\"//g') | ||
export PORT | ||
if [ "$NODE_ENV" != "development" ]; then | ||
printf "\nError: NODE_ENV should be set to development in .env\n"; | ||
kill "$PPID"; exit 1; | ||
fi | ||
|
||
printf "\n*** Building Docker container. 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. Please open:\n***" | ||
printf "\n*** - http://localhost:${PORT} (local server)" | ||
if [ "$PUBLIC_IP_ADDRESS" != "" ]; then | ||
printf "\n*** - http://${PUBLIC_IP_ADDRESS}:${PORT} (remote server)\n***\n"; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2017-2022 @polkadot authors & contributors | ||
# This software may be modified and distributed under the terms | ||
# of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
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) | ||
|
||
# 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 PUBLIC_IP_ADDRESS NODE_ENV PORT_NGINX PORT_PROD | ||
export APP_NAME=$(jq '.name' package.json | sed 's/\"//g') | ||
if [ "$NODE_ENV" != "production" ]; then | ||
printf "\nError: NODE_ENV should be set to production in .env\n"; | ||
kill "$PPID"; exit 1; | ||
fi | ||
echo ${PUBLIC_IP_ADDRESS:=$PUBLIC_IP_ADDRESS_FALLBACK} | ||
if [ "$PUBLIC_IP_ADDRESS" = "" ]; then | ||
printf "\nError: PUBLIC_IP_ADDRESS should be set in .env\n"; | ||
kill "$PPID"; exit 1; | ||
fi | ||
export PUBLIC_URL="http://${PUBLIC_IP_ADDRESS}:${PORT_PROD}" | ||
|
||
printf "\n*** Building $NODE_ENV $APP_NAME. Please wait...\n***" | ||
DOCKER_BUILDKIT=0 docker compose -f docker-compose-prod.yml up --build -d | ||
if [ $? -ne 0 ]; then | ||
kill "$PPID"; exit 1; | ||
fi | ||
|
||
printf "\n*** Finished building ${NODE_ENV}.\n***" | ||
printf "\n*** Please open: ${PUBLIC_URL}.\n***\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM node:gallium-alpine | ||
|
||
ARG APP_NAME=${APP_NAME} | ||
ARG APP_PATH=/app/${APP_NAME} | ||
ARG PORT=${PORT} | ||
|
||
ENV PATH=${APP_PATH}/node_modules/.bin:$PATH | ||
|
||
WORKDIR ${APP_PATH} | ||
|
||
COPY package.json . | ||
|
||
RUN apk update && apk add --update git && rm -rf /var/cache/apk/* | ||
RUN corepack enable \ | ||
&& corepack prepare yarn@stable --activate \ | ||
&& yarn set version 3.1.1 \ | ||
&& yarn plugin import interactive-tools \ | ||
&& echo -e "nodeLinker: node-modules\n\n$(cat ${APP_PATH}/.yarnrc.yml)" > ${APP_PATH}/.yarnrc.yml \ | ||
&& yarn | ||
|
||
COPY . . | ||
|
||
EXPOSE ${PORT} | ||
|
||
CMD ["yarn", "run", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM node:gallium-alpine AS builder | ||
|
||
ARG NODE_ENV=${NODE_ENV} | ||
ARG PORT_NGINX=${PORT_NGINX} | ||
ARG PUBLIC_URL=${PUBLIC_URL} | ||
ARG APP_PATH=/app | ||
ENV PUBLIC_URL=${PUBLIC_URL} | ||
ENV PATH=${APP_PATH}/node_modules/.bin:$PATH | ||
WORKDIR ${APP_PATH} | ||
|
||
COPY package.json . | ||
|
||
RUN apk update && apk add --update git && rm -rf /var/cache/apk/* | ||
RUN corepack enable \ | ||
&& corepack prepare yarn@stable --activate \ | ||
&& yarn set version 3.1.1 \ | ||
&& yarn plugin import interactive-tools \ | ||
&& echo -e "nodeLinker: node-modules\n\n$(cat ${APP_PATH}/.yarnrc.yml)" > ${APP_PATH}/.yarnrc.yml \ | ||
&& yarn | ||
|
||
COPY . . | ||
|
||
RUN NODE_ENV=${NODE_ENV} yarn build | ||
|
||
# =========================================================== | ||
FROM nginx:stable-alpine | ||
|
||
ARG APP_PATH=/app | ||
ARG NGINX_PATH=/usr/share/nginx/html | ||
ARG PUBLIC_URL=${PUBLIC_URL} | ||
ENV PUBLIC_URL=${PUBLIC_URL} | ||
WORKDIR ${NGINX_PATH} | ||
|
||
COPY --from=builder ${APP_PATH}/docker/nginx.conf /etc/nginx/nginx.conf | ||
COPY --from=builder ${APP_PATH}/build/index.html ${NGINX_PATH}/index.html | ||
COPY --from=builder ${APP_PATH}/build ${NGINX_PATH} | ||
|
||
EXPOSE ${PORT_NGINX} | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2017-2022 @polkadot/apps authors & contributors | ||
# This software may be modified and distributed under the terms | ||
# of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
# Reference: https://github.com/polkadot-js/apps/blob/master/docker/nginx.conf | ||
|
||
# Directives and parameters | ||
user nginx; # Directive in the 'main' context | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
# Configuration of connection processing | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
# Configuration specific to HTTP and affecting all virtual servers | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
#tcp_nopush on; | ||
|
||
keepalive_timeout 65; | ||
gzip on; | ||
|
||
# Includes server contexts for configuring each HTTP virtual server | ||
include /etc/nginx/conf.d/*.conf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should be
yarn install --production