diff --git a/.env.example b/.env.example index 25f3fe3..033e99f 100644 --- a/.env.example +++ b/.env.example @@ -1,20 +1,24 @@ # MYSQL -MYSQL_ROOT_PASSWORD=strongpassword +MYSQL_ENGINE= +MYSQL_VERSION= +MYSQL_ROOT_PASSWORD= MYSQL_DATABASE=whaticket -TZ=America/Fortaleza +MYSQL_PORT= +TZ= # BACKEND -BACKEND_PORT=8080 +BACKEND_PORT= BACKEND_SERVER_NAME=api.mydomain.com BACKEND_URL=https://api.mydomain.com PROXY_PORT=443 -JWT_SECRET=3123123213123 -JWT_REFRESH_SECRET=75756756756 +JWT_SECRET= +JWT_REFRESH_SECRET= # FRONTEND -FRONTEND_PORT=3000 +FRONTEND_PORT=80 +FRONTEND_SSL_PORT=443 FRONTEND_SERVER_NAME=myapp.mydomain.com FRONTEND_URL=https://myapp.mydomain.com # BROWSERLESS -MAX_CONCURRENT_SESSIONS=1 \ No newline at end of file +MAX_CONCURRENT_SESSIONS= \ No newline at end of file diff --git a/README.md b/README.md index a717589..18a4f44 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ _Note_: change MYSQL_DATABASE, MYSQL_PASSWORD, MYSQL_USER and MYSQL_ROOT_PASSWOR ```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 + +# 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: @@ -171,6 +175,10 @@ _Note_: change MYSQL_DATABASE, MYSQL_PASSWORD, MYSQL_USER and MYSQL_ROOT_PASSWOR ```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 + +# 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: @@ -383,7 +391,42 @@ To run WhaTicket using docker you must perform the following steps: 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: @@ -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: +Note: The frontend container that runs nginx is already prepared to receive the request made by certboot to validate the certificate. + ```bash # FRONTEND certbot certonly --cert-name backend --webroot --webroot-path ./ssl/www/ -d api.mydomain.com diff --git a/docker-compose.yaml b/docker-compose.yaml index e3c8949..c16c3c0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -28,13 +28,13 @@ services: frontend: ports: - ${FRONTEND_PORT:-3000}:80 - - 443:443 + - ${FRONTEND_SSL_PORT:-3001}:443 build: context: ./frontend dockerfile: ./Dockerfile environment: - 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} - BACKEND_SERVER_NAME=${BACKEND_SERVER_NAME} volumes: @@ -44,7 +44,7 @@ services: - whaticket mysql: - image: mariadb:latest + image: ${MYSQL_ENGINE:-mariadb}:${MYSQL_VERSION:-10.6} command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin volumes: - ./.docker/data/:/var/lib/mysql @@ -53,7 +53,7 @@ services: - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-strongpassword} - TZ=${TZ:-America/Fortaleza} ports: - - 3306:3306 + - ${MYSQL_PORT:-3306}:3306 restart: always networks: - whaticket \ No newline at end of file