diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6f87030 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +.env \ No newline at end of file diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..06c117c --- /dev/null +++ b/.env.sample @@ -0,0 +1 @@ +DOCKER_NODE_VERSION=15.13.0-alpine diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e610599 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env + +# Ignore all database volume files +db/mongo-volume \ No newline at end of file diff --git a/LICENSE b/LICENSE index c48fc24..aadd1b2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 NanoCode012 +Copyright (c) 2021 Chanvichet Vong Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1e30275..fb23ab8 100644 --- a/README.md +++ b/README.md @@ -1 +1,53 @@ -# docker-mern \ No newline at end of file +# 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://github.com/raw/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. diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..1aaa192 --- /dev/null +++ b/backend/.dockerignore @@ -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* diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..1aaa192 --- /dev/null +++ b/backend/.gitignore @@ -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* diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..4fac041 --- /dev/null +++ b/backend/Dockerfile @@ -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"] diff --git a/backend/Dockerfile.dev b/backend/Dockerfile.dev new file mode 100644 index 0000000..f476594 --- /dev/null +++ b/backend/Dockerfile.dev @@ -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"] \ No newline at end of file diff --git a/backend/src/index.js b/backend/src/index.js new file mode 100644 index 0000000..70fba10 --- /dev/null +++ b/backend/src/index.js @@ -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}`); +}); diff --git a/backend/startup.sh b/backend/startup.sh new file mode 100644 index 0000000..e7b03d7 --- /dev/null +++ b/backend/startup.sh @@ -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" \ No newline at end of file diff --git a/client/.dockerignore b/client/.dockerignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/client/.dockerignore @@ -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* diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/client/.gitignore @@ -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* diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..8ae70f5 --- /dev/null +++ b/client/Dockerfile @@ -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 \ No newline at end of file diff --git a/client/Dockerfile.dev b/client/Dockerfile.dev new file mode 100644 index 0000000..f6a2af3 --- /dev/null +++ b/client/Dockerfile.dev @@ -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"] \ No newline at end of file diff --git a/client/nginx/default.conf b/client/nginx/default.conf new file mode 100644 index 0000000..6e2201c --- /dev/null +++ b/client/nginx/default.conf @@ -0,0 +1,9 @@ +server { + listen 3000; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..9ce83ac --- /dev/null +++ b/docker-compose.override.yml @@ -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 diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..2395472 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,11 @@ +version: "3.3" +services: + backend: + build: + context: ./backend + dockerfile: Dockerfile + + client: + build: + context: ./client + dockerfile: Dockerfile diff --git a/docker-compose.ssl.yml b/docker-compose.ssl.yml new file mode 100644 index 0000000..19a8601 --- /dev/null +++ b/docker-compose.ssl.yml @@ -0,0 +1,5 @@ +version: '3.3' +services: + nginx: + env_file: + - ./env/nginx.env diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a5e5d54 --- /dev/null +++ b/docker-compose.yml @@ -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} diff --git a/env/backend.env.sample b/env/backend.env.sample new file mode 100644 index 0000000..126619c --- /dev/null +++ b/env/backend.env.sample @@ -0,0 +1 @@ +DB_CONNECTION_STRING=mongodb://$DB_NAME:27017/$MONGO_INITDB_DATABASE diff --git a/env/mongo.env.sample b/env/mongo.env.sample new file mode 100644 index 0000000..d8ccd8e --- /dev/null +++ b/env/mongo.env.sample @@ -0,0 +1,3 @@ +MONGO_INITDB_DATABASE=$MONGO_INITDB_DATABASE +MONGO_INITDB_USERNAME=$MONGO_INITDB_USERNAME +MONGO_INITDB_PASSWORD=$MONGO_INITDB_PASSWORD \ No newline at end of file diff --git a/env/nginx.env.sample b/env/nginx.env.sample new file mode 100644 index 0000000..9e4b7e8 --- /dev/null +++ b/env/nginx.env.sample @@ -0,0 +1,4 @@ +VIRTUAL_HOST=$VIRTUAL_HOST +VIRTUAL_PORT=$VIRTUAL_PORT +LETSENCRYPT_HOST=$LETSENCRYPT_HOST +LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL \ No newline at end of file diff --git a/local-scripts.sh b/local-scripts.sh new file mode 100644 index 0000000..8e896c7 --- /dev/null +++ b/local-scripts.sh @@ -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 +} diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..abb6ad2 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,13 @@ +# Pull in the from the official nginx image. +FROM nginx + +EXPOSE 80 + +# Delete the default welcome to nginx page. +RUN rm /usr/share/nginx/html/* + +# Copy over the custom default configs. +COPY configs/default.conf /etc/nginx/conf.d/default.conf + +# Start nginx in the foreground to play nicely with Docker. +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx/configs/default.conf b/nginx/configs/default.conf new file mode 100644 index 0000000..946b210 --- /dev/null +++ b/nginx/configs/default.conf @@ -0,0 +1,20 @@ +upstream $BACKEND_NAME { + server $BACKEND_NAME:3001; +} + +upstream $CLIENT_NAME { + server $CLIENT_NAME:3000; +} + +server { + listen 80; + + location /backend { + rewrite /backend/(.*) /$1 break; + proxy_pass http://$BACKEND_NAME; + } + + location / { + proxy_pass http://$CLIENT_NAME; + } +} \ No newline at end of file diff --git a/setup-server.sh b/setup-server.sh new file mode 100644 index 0000000..07ce458 --- /dev/null +++ b/setup-server.sh @@ -0,0 +1,291 @@ +#!/bin/bash + +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# + +# Server Setup Script - set up Docker MERN on a new server + +# + +# https://github.com/NanoCode012/docker-mern + +# + +# Script developed by + +# Chanvichet Vong + +# + +# Copyright 2021 Chanvichet Vong + +# License at + +# https://github.com/NanoCode012/docker-mern/blob/main/LICENSE + +# + +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +echo "=========================================================" +echo "Docker-Mern server startup script by Chanvichet Vong" +echo "Get latest at https://github.com/NanoCode012/docker-mern/" +echo "=========================================================" +echo "" + +# When development, pass env BRANCH=branch_name before calling script +if [ -z ${BRANCH+x} ]; then + BRANCH="main" # default +else + echo "Running on custom branch $BRANCH" + echo "" +fi + +SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" +SCRIPT_NAME="${0##*/}" + +echo "Downloading base scripts" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/local-scripts.sh" -qO local-scripts.sh +source local-scripts.sh +echo "Downloaded base scripts" +echo "" + +if [[ ! -z "$1" && "$1" == "barebone" ]]; then + echo -e "Setting barebone run \n" + barebone_run=true +else + barebone_run=false +fi + +echo "Folder setup" +echo "============" + +if [ ! -d "docker-mern" ]; then + mkdir docker-mern +else + echo "Moving old docker-mern folder to docker-mern-backup folder" + + sudo chown -R ${USER}:${USER} docker-mern # fix permission with db belonging to root + if [ -d "docker-mern-backup" ]; then + echo "Deleting backup folder" + rm -rf docker-mern-backup + echo "Deleted backup folder" + fi + mv docker-mern docker-mern-backup + + mkdir docker-mern + echo "Successfully moved to docker-mern-backup folder" +fi +echo "" + +# Server configuration +echo "Configuration" +echo "=============" + +cd docker-mern + +# Download LICENSE +echo "Downloading LICENSE" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/LICENSE" -qO LICENSE +echo "Downloaded LICENSE" + +# Download env file +echo "Downloading env file" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/.env.sample" -qO .env +source .env +echo "Downloaded env file" + +# Download ignore files +echo "Downloading .*ignore files" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/.gitignore" -qO .gitignore +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/.dockerignore" -qO .dockerignore +echo "Downloaded .*ignore files" + +# Get docker-compose files +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/docker-compose.yml" -qO docker-compose.yml +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/docker-compose.prod.yml" -qO docker-compose.prod.yml +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/docker-compose.ssl.yml" -qO docker-compose.ssl.yml +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/docker-compose.override.yml" -qO docker-compose.override.yml + +if [ "$barebone_run" = true ]; then + NGINX_NAME="mern-nginx" + CLIENT_NAME="mern-client" + BACKEND_NAME="mern-backend" + DB_NAME="mern-db" + PROXY_NAME="proxy" +else + # read_with_prompt USE_EXTERNAL_REVERSE_PROXY "Do you use an external reverse proxy like nginx-proxy-automation? (y/n) " "y" + # todo: container names regex [a-zA-Z0-9][a-zA-Z0-9_.-] + read_with_prompt NGINX_NAME "Nginx container name" "mern-nginx" + read_with_prompt CLIENT_NAME "Client container name" "mern-client" + read_with_prompt BACKEND_NAME "Backend container name" "mern-backend" + read_with_prompt DB_NAME "Database container name" "mern-db" + read_with_prompt PROXY_NAME "Docker external proxy name" "proxy" +fi + +echo "NGINX_NAME=$NGINX_NAME" >> .env +echo "CLIENT_NAME=$CLIENT_NAME" >> .env +echo "BACKEND_NAME=$BACKEND_NAME" >> .env +echo "DB_NAME=$DB_NAME" >> .env +echo "PROXY_NAME=$PROXY_NAME" >> .env # assume that network exists for now +echo "" + +# Create client app +echo "Client" +echo "======" + +mkdir client + +if [ "$barebone_run" = false ]; then + read_yes_no check_create_new_react_app "Create new react app" + + if [ "$check_create_new_react_app" = true ]; then + echo "Creating new react app" + sudo docker run --rm -v $(pwd)/client:/client node:$DOCKER_NODE_VERSION npx create-react-app client --use-npm + sudo chown -R ${USER}:${USER} client + echo "Created new react app" + fi +fi + +cd client + +mkdir nginx + +echo "Downloading Dockerfile, Dockerfile.dev, .gitignore, .dockerignore, and nginx conf file" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/client/Dockerfile" -qO Dockerfile +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/client/Dockerfile.dev" -qO Dockerfile.dev +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/client/.gitignore" -qO .gitignore +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/client/.dockerignore" -qO .dockerignore +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/client/nginx/default.conf" -qO nginx/default.conf +echo "Downloaded files" +echo "" + +cd .. + +# Create backend app +echo "Backend" +echo "=======" + +mkdir backend + +if [ "$barebone_run" = false ]; then + read_yes_no check_create_new_backend_app "Create new node app" + + if [ "$check_create_new_backend_app" = true ]; then + echo "Creating new node app" + + echo "Downloading startup script" + wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/startup.sh" -qO backend-startup.sh + echo "Downloaded startup script" + + sudo docker run --rm -v $(pwd)/backend:/backend -v $(pwd)/backend-startup.sh:/backend-startup.sh \ + node:$DOCKER_NODE_VERSION /bin/sh -c "chmod +x backend-startup.sh && ./backend-startup.sh" + + echo "Deleting startup script" + rm backend-startup.sh + echo "Deleted startup script" + + echo "Downloading starter express code" + mkdir backend/src + wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/src/index.js" -qO backend/src/index.js + echo "Downloaded starter express code" + + sudo chown -R ${USER}:${USER} backend + echo "Created new node app" + fi +fi + +cd backend + +echo "Downloading Dockerfile, Dockerfile.dev, .gitignore, and .dockerignore" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/Dockerfile" -qO Dockerfile +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/Dockerfile.dev" -qO Dockerfile.dev +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/.gitignore" -qO .gitignore +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/backend/.dockerignore" -qO .dockerignore +echo "Downloaded files" +echo "" + +cd .. + +# Create db +echo "Database" +echo "========" + +mkdir db +cd db + +echo "Creating init-mongo.js file" +touch init-mongo.js +echo "Created init-mongo.js file. Please place your initial mongo configurations here." +echo "" + +cd .. + +# Create proxy +echo "Nginx Proxy" +echo "===========" + +mkdir nginx +mkdir nginx/configs +cd nginx + +echo "Downloading Dockerfile and nginx default conf" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/nginx/Dockerfile" -qO Dockerfile +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/nginx/configs/default.conf" -qO configs/default.conf +echo "Downloaded files" + +echo "Replacing conf variables with env variables" +CLIENT_NAME=$CLIENT_NAME BACKEND_NAME=$BACKEND_NAME envsubst < configs/default.conf > configs/default.conf.replaced +mv configs/default.conf.replaced configs/default.conf +echo "Replaced variables" +echo "" + +cd .. + +# Create environment folder +echo "Env" +echo "===" + +mkdir env +cd env + +echo "Downloading env files" +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/env/backend.env.sample" -qO backend.env +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/env/mongo.env.sample" -qO mongo.env +wget "https://github.com/raw/NanoCode012/docker-mern/$BRANCH/env/nginx.env.sample" -qO nginx.env +echo "Downloaded env files" + +if [ "$barebone_run" = true ]; then + MONGO_INITDB_DATABASE="app" + MONGO_INITDB_USERNAME="nanocode012" + MONGO_INITDB_PASSWORD="averysecurepassword,butpleasechangeme0" +else + read_with_prompt MONGO_INITDB_DATABASE "MongoDB Database Name" "app" + read_with_prompt MONGO_INITDB_USERNAME "MongoDB Username" "nanocode012" + read_with_prompt MONGO_INITDB_PASSWORD "MongoDB Password" "averysecurepassword,butpleasechangeme0" +fi + +echo "Replacing env file with env variables" +MONGO_INITDB_DATABASE=$MONGO_INITDB_DATABASE envsubst < backend.env > backend.env.replaced +mv backend.env.replaced backend.env + +MONGO_INITDB_DATABASE=$MONGO_INITDB_DATABASE MONGO_INITDB_USERNAME=$MONGO_INITDB_USERNAME \ + MONGO_INITDB_PASSWORD=$MONGO_INITDB_PASSWORD envsubst < mongo.env > mongo.env.replaced +mv mongo.env.replaced mongo.env +echo "Replaced variables" + +if [ "$barebone_run" = false ]; then + read_yes_no check_enable_ssl_app "Enable SSL via Nginx Proxy-LetsEncrypt" + + if [ "$check_enable_ssl_app" = true ]; then + read_with_prompt VIRTUAL_HOST "VIRTUAL_HOST/LETSENCRYPT_HOST" "" + read_with_prompt VIRTUAL_PORT "VIRTUAL_PORT" "80" + read_with_prompt LETSENCRYPT_EMAIL "LETSENCRYPT_EMAIL" "" + + echo "Replacing env file with env variables" + VIRTUAL_HOST=$VIRTUAL_HOST VIRTUAL_PORT=$VIRTUAL_PORT LETSENCRYPT_HOST=$VIRTUAL_HOST \ + LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL envsubst < nginx.env > nginx.env.replaced + mv nginx.env.replaced nginx.env + echo "Replaced variables" + fi +fi + +echo "" + +cd .. + +# Cleanup +echo "Clean up" +echo "===" + +echo "Deleting local-scripts" +rm ../local-scripts.sh +echo "Deleted local scripts" \ No newline at end of file