Enhancing README.md using docker

This commit is contained in:
Ricardo Paes
2022-02-15 14:17:05 -03:00
parent f7f4e97aed
commit d986710a3b
3 changed files with 61 additions and 12 deletions

View File

@@ -1,20 +1,24 @@
# MYSQL # MYSQL
MYSQL_ROOT_PASSWORD=strongpassword MYSQL_ENGINE=
MYSQL_VERSION=
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=whaticket MYSQL_DATABASE=whaticket
TZ=America/Fortaleza MYSQL_PORT=
TZ=
# BACKEND # BACKEND
BACKEND_PORT=8080 BACKEND_PORT=
BACKEND_SERVER_NAME=api.mydomain.com BACKEND_SERVER_NAME=api.mydomain.com
BACKEND_URL=https://api.mydomain.com BACKEND_URL=https://api.mydomain.com
PROXY_PORT=443 PROXY_PORT=443
JWT_SECRET=3123123213123 JWT_SECRET=
JWT_REFRESH_SECRET=75756756756 JWT_REFRESH_SECRET=
# FRONTEND # FRONTEND
FRONTEND_PORT=3000 FRONTEND_PORT=80
FRONTEND_SSL_PORT=443
FRONTEND_SERVER_NAME=myapp.mydomain.com FRONTEND_SERVER_NAME=myapp.mydomain.com
FRONTEND_URL=https://myapp.mydomain.com FRONTEND_URL=https://myapp.mydomain.com
# BROWSERLESS # BROWSERLESS
MAX_CONCURRENT_SESSIONS=1 MAX_CONCURRENT_SESSIONS=

View File

@@ -45,6 +45,10 @@ _Note_: change MYSQL_DATABASE, MYSQL_PASSWORD, MYSQL_USER and MYSQL_ROOT_PASSWOR
```bash ```bash
docker run --name whaticketdb -e MYSQL_ROOT_PASSWORD=strongpassword -e MYSQL_DATABASE=whaticket -e MYSQL_USER=whaticket -e MYSQL_PASSWORD=whaticket --restart always -p 3306:3306 -d mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_bin docker run --name whaticketdb -e MYSQL_ROOT_PASSWORD=strongpassword -e MYSQL_DATABASE=whaticket -e MYSQL_USER=whaticket -e MYSQL_PASSWORD=whaticket --restart always -p 3306:3306 -d mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
# Or run using `docker-compose` as below
# Before copy .env-example to .env first and set the variables in the file.
docker-compose up -d mysql
``` ```
Install puppeteer dependencies: Install puppeteer dependencies:
@@ -171,6 +175,10 @@ _Note_: change MYSQL_DATABASE, MYSQL_PASSWORD, MYSQL_USER and MYSQL_ROOT_PASSWOR
```bash ```bash
docker run --name whaticketdb -e MYSQL_ROOT_PASSWORD=strongpassword -e MYSQL_DATABASE=whaticket -e MYSQL_USER=whaticket -e MYSQL_PASSWORD=whaticket --restart always -p 3306:3306 -d mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_bin docker run --name whaticketdb -e MYSQL_ROOT_PASSWORD=strongpassword -e MYSQL_DATABASE=whaticket -e MYSQL_USER=whaticket -e MYSQL_PASSWORD=whaticket --restart always -p 3306:3306 -d mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
# Or run using `docker-compose` as below
# Before copy .env-example to .env first and set the variables in the file.
docker-compose up -d mysql
``` ```
Clone this repository: Clone this repository:
@@ -383,7 +391,42 @@ To run WhaTicket using docker you must perform the following steps:
cp .env.example .env cp .env.example .env
``` ```
Now it will be necessary to configure the .env using its information, the variables are the same as those mentioned in the deployment using ubuntu, with the exception of mysql settings that were not in the .env. Now it will be necessary to configure the .env using its information, the variables are the same as those mentioned in the deployment using ubuntu, with the exception of mysql settings that were not in the .env.
```bash
# MYSQL
MYSQL_ENGINE= # default: mariadb
MYSQL_VERSION= # default: 10.6
MYSQL_ROOT_PASSWORD=strongpassword # change it please
MYSQL_DATABASE=whaticket
MYSQL_PORT=3306 # default: 3306; Use this port to expose mysql server
TZ=America/Fortaleza # default: America/Fortaleza; Timezone for mysql
# BACKEND
BACKEND_PORT= # default: 8080; but access by host not use this port
BACKEND_SERVER_NAME=api.mydomain.com
BACKEND_URL=https://api.mydomain.com
PROXY_PORT=443
JWT_SECRET=3123123213123 # change it please
JWT_REFRESH_SECRET=75756756756 # change it please
# FRONTEND
FRONTEND_PORT=80 # default: 3000; Use port 80 to expose in production
FRONTEND_SSL_PORT=443 # default: 3001; Use port 443 to expose in production
FRONTEND_SERVER_NAME=myapp.mydomain.com
FRONTEND_URL=https://myapp.mydomain.com
# BROWSERLESS
MAX_CONCURRENT_SESSIONS= # default: 1; Use only if using browserless
```
After defining the variables, run the following command:
```bash
docker-compose up -d --build
```
#### SSL Certificate
To deploy the ssl certificate, add it to the `ssl/certs` folder. Inside it there should be a `backend` and a `frontend` folder, and each of them should contain the files `fullchain.pem` and `privkey.pem`, as in the structure below: To deploy the ssl certificate, add it to the `ssl/certs` folder. Inside it there should be a `backend` and a `frontend` folder, and each of them should contain the files `fullchain.pem` and `privkey.pem`, as in the structure below:
@@ -401,6 +444,8 @@ To deploy the ssl certificate, add it to the `ssl/certs` folder. Inside it there
To generate the certificate files use `certbot` which can be installed using snap, I used the following command: To generate the certificate files use `certbot` which can be installed using snap, I used the following command:
Note: The frontend container that runs nginx is already prepared to receive the request made by certboot to validate the certificate.
```bash ```bash
# FRONTEND # FRONTEND
certbot certonly --cert-name backend --webroot --webroot-path ./ssl/www/ -d api.mydomain.com certbot certonly --cert-name backend --webroot --webroot-path ./ssl/www/ -d api.mydomain.com

View File

@@ -28,13 +28,13 @@ services:
frontend: frontend:
ports: ports:
- ${FRONTEND_PORT:-3000}:80 - ${FRONTEND_PORT:-3000}:80
- 443:443 - ${FRONTEND_SSL_PORT:-3001}:443
build: build:
context: ./frontend context: ./frontend
dockerfile: ./Dockerfile dockerfile: ./Dockerfile
environment: environment:
- URL_BACKEND=backend:3000 - URL_BACKEND=backend:3000
- REACT_APP_BACKEND_URL=${BACKEND_URL:-http://localhost:8080/} - REACT_APP_BACKEND_URL=${BACKEND_URL:-http://localhost}:${PROXY_PORT:-8080}/
- FRONTEND_SERVER_NAME=${FRONTEND_SERVER_NAME} - FRONTEND_SERVER_NAME=${FRONTEND_SERVER_NAME}
- BACKEND_SERVER_NAME=${BACKEND_SERVER_NAME} - BACKEND_SERVER_NAME=${BACKEND_SERVER_NAME}
volumes: volumes:
@@ -44,7 +44,7 @@ services:
- whaticket - whaticket
mysql: mysql:
image: mariadb:latest image: ${MYSQL_ENGINE:-mariadb}:${MYSQL_VERSION:-10.6}
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
volumes: volumes:
- ./.docker/data/:/var/lib/mysql - ./.docker/data/:/var/lib/mysql
@@ -53,7 +53,7 @@ services:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-strongpassword} - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-strongpassword}
- TZ=${TZ:-America/Fortaleza} - TZ=${TZ:-America/Fortaleza}
ports: ports:
- 3306:3306 - ${MYSQL_PORT:-3306}:3306
restart: always restart: always
networks: networks:
- whaticket - whaticket