-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial files * Add end of file and format * Fix if syntax * Add script path * Fix new line * Fix new line and add force remove * Delete directory after move * Add better outputs * Fix to only delete backup folder if exist * Update License * Move docker-compose files download * Remove unnecessary rm * Update name * Add client Dockerfile * Fix folder name * Change backup folder name * Fix branch name * Fix condition and download env * Add wget overwrite * Move command to download env * Fix client folder permission denied * Fix permission * Change react app to use npm instead of yarn * Add prompt check yes no before creating react app * Fix quiet parameter * Add sudo to docker and fix variable * Add new line * Add more files for client folder * Attempt to fix arg not found * Added backend section * Add ARG to dev file * Add backend files * Fix npm init dir * Change to sh * Fix commands * Add title to Server configuration * Remove mkdir * Improve output * Extracted function into a separate file * Improve output * Separate command from docker run * Change variable name * Pass in temp string as env * Combine to multiline * Add silent * Remove old e variable * Pass ARG to backend Dockerfiles * Add initial db setup * Add default * Fix condition * Remove .env file * Change sample size * Change comparison operator * Fix condition brackets * Fix bash condition * Renaming configuration * Change argument * Add ignore files * Download ignore files too * Add proxy section * Remove useless echo * Make constants into variables * Convert variables in conf file * Fixed replacement redirect bug * Add docker-compose files * Add sample env files * Pass env variables to command * Fix syntax * Change incorrect output * Add docker-compose for ssl * Update syntax * Fix args syntax * Change to mapping * Fix copy syntax * Add todo * Pass env variable to a single envsubst call * Add option to add SSL info * Add user to mongo image * Extracted sh into script * Add startup script for backend * Add nginx conf for client * Add backend starter script * Add missing rm * Add comment * Attempt to fix permission in db * Fix path * Fix file path * Add note * Update ReadMe * Download LICENSE * Accept dynamic branch variable * Fix syntax * Fix permission for correct folder * Update ReadMe * Update README
- Loading branch information
1 parent
6fc3b0a
commit 38adda9
Showing
27 changed files
with
682 additions
and
2 deletions.
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,2 @@ | ||
.git | ||
.env |
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 @@ | ||
DOCKER_NODE_VERSION=15.13.0-alpine |
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,4 @@ | ||
.env | ||
|
||
# Ignore all database volume files | ||
db/mongo-volume |
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 |
---|---|---|
@@ -1 +1,53 @@ | ||
# docker-mern | ||
# Docker MERN | ||
|
||
This repo aims to create a one-stop script which would allow the setup of a MERN stack via multiple containers reliably. | ||
|
||
# Requirements | ||
|
||
- docker (with external network created) | ||
- docker-compose | ||
- wget | ||
|
||
# Setup | ||
|
||
```bash | ||
$ wget https://raw.githubusercontent.com/NanoCode012/docker-mern/main/setup-server.sh -O setup-server.sh | ||
$ chmod +x setup-server.sh | ||
$ ./setup-server.sh | ||
``` | ||
|
||
Note: Ignore `Git repo not initialized Error: Command failed: git --version` when creating base react files | ||
|
||
### Optional arguments: | ||
|
||
- `barebone` run with default options and without creating react and node files | ||
|
||
# Usage | ||
|
||
## Production | ||
|
||
```bash | ||
$ docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build | ||
``` | ||
|
||
Add `-f docker-compose.ssl.yml` for SSL setup | ||
|
||
## Development | ||
|
||
```bash | ||
$ docker-compose up -d --build | ||
``` | ||
|
||
# Configuration | ||
|
||
- For more docker-configuration, consider creating a new compose file with the changes and adding it via `-f` option | ||
|
||
# Script Development/Test | ||
|
||
Pass in environment variable `BRANCH=the_branch_name` before calling script, so that the script knows where to `wget` the files. | ||
|
||
# Contribution | ||
|
||
PRs are **greatly** appreciated, but please open an Issue first to discuss. | ||
|
||
Questions? Open an Issue. |
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 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ARG DOCKER_NODE_VERSION | ||
|
||
FROM node:$DOCKER_NODE_VERSION AS alpine | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
|
||
EXPOSE 3001 | ||
|
||
# Default command | ||
CMD ["npm", "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,15 @@ | ||
ARG DOCKER_NODE_VERSION | ||
|
||
FROM node:$DOCKER_NODE_VERSION AS alpine | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY package*.json . | ||
RUN npm install --save-dev | ||
# COPY . . | ||
|
||
EXPOSE 3001 | ||
|
||
# Default command | ||
CMD ["npm", "run", "test"] |
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,12 @@ | ||
// Start code from: https://expressjs.com/en/starter/hello-world.html | ||
const express = require("express"); | ||
const app = express(); | ||
const port = 3001; | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Hello World!"); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening at http://localhost:${port}`); | ||
}); |
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,13 @@ | ||
#!/bin/sh | ||
|
||
# To be run inside docker container | ||
|
||
cd backend | ||
|
||
npm init -y | ||
npm install --save express | ||
|
||
npm install --save-dev --silent nodemon | ||
|
||
npm set-script start "node src/index.js" | ||
npm set-script test "nodemon src/index.js" |
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 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ARG DOCKER_NODE_VERSION | ||
|
||
FROM node:$DOCKER_NODE_VERSION as build | ||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
RUN npm run build | ||
|
||
FROM nginx | ||
EXPOSE 3000 | ||
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf | ||
COPY --from=build /app/build /usr/share/nginx/html |
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,9 @@ | ||
ARG DOCKER_NODE_VERSION | ||
|
||
FROM node:$DOCKER_NODE_VERSION as build | ||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
|
||
# Default command | ||
CMD ["npm", "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,9 @@ | ||
server { | ||
listen 3000; | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html index.htm; | ||
try_files $uri $uri/ /index.html; | ||
} | ||
} |
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,24 @@ | ||
version: "3.3" | ||
services: | ||
nginx: | ||
ports: | ||
- "80:80" | ||
backend: | ||
build: | ||
context: ./backend | ||
dockerfile: Dockerfile.dev | ||
volumes: | ||
- ./backend/:/app/ | ||
environment: | ||
- NODE_ENV=development | ||
- CHOKIDAR_USEPOLLING=true | ||
|
||
client: | ||
build: | ||
context: ./client | ||
dockerfile: Dockerfile.dev | ||
volumes: | ||
- ./client/:/app/ | ||
environment: | ||
- NODE_ENV=development | ||
- CHOKIDAR_USEPOLLING=true |
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,11 @@ | ||
version: "3.3" | ||
services: | ||
backend: | ||
build: | ||
context: ./backend | ||
dockerfile: Dockerfile | ||
|
||
client: | ||
build: | ||
context: ./client | ||
dockerfile: Dockerfile |
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,5 @@ | ||
version: '3.3' | ||
services: | ||
nginx: | ||
env_file: | ||
- ./env/nginx.env |
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,46 @@ | ||
version: "3.3" | ||
services: | ||
nginx: | ||
container_name: ${NGINX_NAME} | ||
depends_on: | ||
- client | ||
- backend | ||
restart: always | ||
build: | ||
dockerfile: Dockerfile | ||
context: ./nginx | ||
client: | ||
container_name: ${CLIENT_NAME} | ||
build: | ||
args: | ||
DOCKER_NODE_VERSION: ${DOCKER_NODE_VERSION} | ||
volumes: | ||
- /app/node_modules # Inside the container, don't try to override this folder, just leave as is | ||
restart: on-failure | ||
|
||
backend: | ||
container_name: ${BACKEND_NAME} | ||
build: | ||
args: | ||
DOCKER_NODE_VERSION: ${DOCKER_NODE_VERSION} | ||
volumes: | ||
- /app/node_modules # Inside the container, don't try to override this folder, just leave as is | ||
env_file: | ||
- ./env/backend.env | ||
restart: on-failure | ||
|
||
mongo: | ||
image: mongo | ||
container_name: ${DB_NAME} | ||
user: ${USER}:${USER} | ||
volumes: | ||
- ./db/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro | ||
- ./db/mongo-volume:/data/db | ||
env_file: | ||
- ./env/mongo.env | ||
restart: on-failure | ||
|
||
networks: | ||
default: | ||
external: | ||
name: ${PROXY_NAME} |
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 @@ | ||
DB_CONNECTION_STRING=mongodb://$DB_NAME:27017/$MONGO_INITDB_DATABASE |
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,3 @@ | ||
MONGO_INITDB_DATABASE=$MONGO_INITDB_DATABASE | ||
MONGO_INITDB_USERNAME=$MONGO_INITDB_USERNAME | ||
MONGO_INITDB_PASSWORD=$MONGO_INITDB_PASSWORD |
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,4 @@ | ||
VIRTUAL_HOST=$VIRTUAL_HOST | ||
VIRTUAL_PORT=$VIRTUAL_PORT | ||
LETSENCRYPT_HOST=$LETSENCRYPT_HOST | ||
LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL |
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,43 @@ | ||
#!/bin/bash | ||
|
||
# Function to read input from user with a prompt | ||
# Credits: https://github.com/TheRemote/MinecraftBedrockServer/blob/1f27b8ab82f920bb967d1c27ee2fd120a484c99c/SetupMinecraft.sh | ||
function read_with_prompt { | ||
variable_name="$1" | ||
prompt="$2" | ||
default="${3-}" | ||
unset $variable_name | ||
while [[ ! -n ${!variable_name} ]]; do | ||
read -p "$prompt: " $variable_name < /dev/tty | ||
if [ ! -n "`which xargs`" ]; then | ||
declare -g $variable_name=$(echo "${!variable_name}" | xargs) | ||
fi | ||
declare -g $variable_name=$(echo "${!variable_name}" | head -n1 | awk '{print $1;}') | ||
if [[ -z ${!variable_name} ]] && [[ -n "$default" ]] ; then | ||
declare -g $variable_name=$default | ||
fi | ||
echo -n "$prompt : ${!variable_name} -- accept (y/n)?" | ||
read answer < /dev/tty | ||
if [ "$answer" == "${answer#[Yy]}" ]; then | ||
unset $variable_name | ||
else | ||
echo "$prompt: ${!variable_name}" | ||
fi | ||
done | ||
} | ||
|
||
function read_yes_no { | ||
variable_name="$1" | ||
prompt="$2" | ||
unset $variable_name | ||
|
||
read -p "$prompt -- (y/n)?" answer | ||
case ${answer:0:1} in | ||
y|Y ) | ||
declare -g $variable_name=true | ||
;; | ||
* ) | ||
declare -g $variable_name=false | ||
;; | ||
esac | ||
} |
Oops, something went wrong.