chore: Switch to mariadb

This commit is contained in:
Gerardo Navarro 2022-08-21 16:47:06 +02:00
parent 6172ae47db
commit 6f9e730a7c
2 changed files with 51 additions and 25 deletions

View file

@ -4,10 +4,9 @@
# Always ensure to load the env variables in every terminal session. # Always ensure to load the env variables in every terminal session.
# Otherwise the env variables will not be available # Otherwise the env variables will not be available
DOCKER_COMPOSE_APP_PROD_PORT_PUBLISHED=9001 DOCKER_COMPOSE_APP_PROD_PORT_PUBLISHED=9001
DOCKER_COMPOSE_APP_PROD_PORT_TARGET=9001 DOCKER_COMPOSE_APP_PROD_PORT_TARGET=9001
DOCKER_COMPOSE_POSTGRES_PROD_DB= DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_DATABASE=
DOCKER_COMPOSE_POSTGRES_PROD_PASSWORD= DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_PASSWORD=
DOCKER_COMPOSE_POSTGRES_PROD_USER= DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_USER=

View file

@ -9,28 +9,26 @@ services:
build: build:
context: . context: .
environment: environment:
DB_HOST: postgres_prod DB_HOST: mariadb_prod
DB_NAME: ${DOCKER_COMPOSE_POSTGRES_PROD_DB:?} DB_NAME: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_DATABASE:?}
DB_PASS: ${DOCKER_COMPOSE_POSTGRES_PROD_PASSWORD:?} DB_PASS: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_PASSWORD:?}
DB_PORT: ${DOCKER_COMPOSE_POSTGRES_PROD_PORT:-5432} DB_PORT: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_PORT:-3306}
DB_TYPE: "postgres" DB_TYPE: "mysql"
DB_USER: ${DOCKER_COMPOSE_POSTGRES_PROD_USER:?} DB_USER: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_USER:?}
ports: ports:
- "${DOCKER_COMPOSE_APP_PROD_PORT_PUBLISHED:-9001}:${DOCKER_COMPOSE_APP_PROD_PORT_TARGET:-9001}" - "${DOCKER_COMPOSE_APP_PROD_PORT_PUBLISHED:-9001}:${DOCKER_COMPOSE_APP_PROD_PORT_TARGET:-9001}"
# If you do not have another postgres database service in this docker-compose, you can add this postgres service. mariadb_prod:
# Note: Please use other credentials when using this in production. image: mariadb
postgres_prod:
image: postgres:12-alpine
# Pass config parameters to the postgres server. # Pass config parameters to the postgres server.
# Find more information below when you need to generate the ssl-relevant file your self # Find more information below when you need to generate the ssl-relevant file your self
command: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key # command: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
environment: environment:
PGDATA: /var/lib/postgresql/data/pgdata MARIADB_DATABASE: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_DATABASE:?}
POSTGRES_DB: ${DOCKER_COMPOSE_POSTGRES_PROD_DB:?} MARIADB_PASSWORD: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_PASSWORD:?}
POSTGRES_PASSWORD: ${DOCKER_COMPOSE_POSTGRES_PROD_PASSWORD:?} MARIADB_PORT: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_PORT:-3306}
POSTGRES_PORT: ${DOCKER_COMPOSE_POSTGRES_PROD_PORT:-5432} MARIADB_RANDOM_ROOT_PASSWORD: 'yes'
POSTGRES_USER: ${DOCKER_COMPOSE_POSTGRES_PROD_USER:?} MARIADB_USER: ${DOCKER_COMPOSE_MARIADB_PROD_ENV_MARIADB_USER:?}
volumes: volumes:
# To setup an ssl-enabled postgres server locally, you need to generate a self-signed ssl certificate. # To setup an ssl-enabled postgres server locally, you need to generate a self-signed ssl certificate.
# ```bash # ```bash
@ -43,9 +41,38 @@ services:
# ``` # ```
# #
# Afterwards, the ssl_cert_file and ssl_key_file are mounted into the docker container, see below # Afterwards, the ssl_cert_file and ssl_key_file are mounted into the docker container, see below
- ./ca/server.crt:/var/lib/postgresql/server.crt # - ./ca/server.crt:/var/lib/postgresql/server.crt
- ./ca/server.key:/var/lib/postgresql/server.key # - ./ca/server.key:/var/lib/postgresql/server.key
- postgres_prod_data:/var/lib/postgresql/data/pgdata - mariadb_prod_data:/var/lib/postgresql/data/pgdata
# # If you do not have another postgres database service in this docker-compose, you can add this postgres service.
# # Note: Please use other credentials when using this in production.
# postgres_prod:
# image: postgres:12-alpine
# # Pass config parameters to the postgres server.
# # Find more information below when you need to generate the ssl-relevant file your self
# command: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
# environment:
# PGDATA: /var/lib/postgresql/data/pgdata
# POSTGRES_DB: ${DOCKER_COMPOSE_POSTGRES_PROD_DB:?}
# POSTGRES_PASSWORD: ${DOCKER_COMPOSE_POSTGRES_PROD_PASSWORD:?}
# POSTGRES_PORT: ${DOCKER_COMPOSE_POSTGRES_PROD_PORT:-5432}
# POSTGRES_USER: ${DOCKER_COMPOSE_POSTGRES_PROD_USER:?}
# volumes:
# # To setup an ssl-enabled postgres server locally, you need to generate a self-signed ssl certificate.
# # ```bash
# # mkdir -p ./ca
# # openssl req -new -text -passout pass:abcd -subj /CN=localhost -out ./ca/server.req -keyout ./ca/privkey.pem
# # openssl rsa -in ./ca/privkey.pem -passin pass:abcd -out ./ca/server.key
# # openssl req -x509 -in ./ca/server.req -text -key ./ca/server.key -out ./ca/server.crt
# # chmod 600 ./ca/server.key
# # test $(uname -s) = Linux && chown 70 ./ca/server.key
# # ```
# #
# # Afterwards, the ssl_cert_file and ssl_key_file are mounted into the docker container, see below
# - ./ca/server.crt:/var/lib/postgresql/server.crt
# - ./ca/server.key:/var/lib/postgresql/server.key
# - postgres_prod_data:/var/lib/postgresql/data/pgdata
volumes: volumes:
postgres_prod_data: mariadb_prod_data: