Skip to content

Commit a743883

Browse files
committed
docker: deploy development and test databases on same service
1 parent e205f73 commit a743883

File tree

7 files changed

+21
-34
lines changed

7 files changed

+21
-34
lines changed

Docker.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ To simplify set up of a developement environment, LinuxFr.org can be
55
run on Docker with `docker-compose up`.
66

77
To init the SQL database schema, you need to wait upto the `database`
8-
and `database-test` containers are ready to listen MySQL connections.
8+
container to be ready to listen MySQL connections.
99

1010
For example, you should see in the logs:
1111

12-
> database-test_1 | 2020-09-21 16:03:12 140126029907968 [Note] mysqld: ready for connections.
13-
>
14-
> database-test_1 | Version: '10.1.46-MariaDB-1\~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
15-
>
1612
> database_1 | 2020-09-21 16:03:12 139820938893312 [Note] mysqld: ready for connections.
1713
>
1814
> database_1 | Version: '10.1.46-MariaDB-1\~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution

deployment/database-test/entrypoint.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

deployment/database/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM mariadb:10.1
2+
3+
COPY ./docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
mysql -uroot -hlocalhost -p"${MYSQL_ROOT_PASSWORD}" <<EOSQL
6+
CREATE USER IF NOT EXISTS '${MYSQL_TEST_USER}'@'%' IDENTIFIED BY '${MYSQL_TEST_PASSWORD}';
7+
CREATE DATABASE IF NOT EXISTS ${MYSQL_TEST_DATABASE};
8+
GRANT ALL PRIVILEGES ON ${MYSQL_TEST_DATABASE}.* TO '${MYSQL_TEST_USER}'@'%';
9+
EOSQL
10+

deployment/default.env

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ REDIS_HOST=redis
88
REDIS_PORT=6379
99
REDIS_URL=redis://redis:6379/0
1010

11-
# For the mariadb docker image configuration, see: https://hub.docker.com/_/mariadb
12-
MYSQL_RANDOM_ROOT_PASSWORD=true
11+
# Fixed mysql root user password to be able to run entrypoint
12+
MYSQL_ROOT_PASSWORD=linuxfr_root_pwd
1313

1414
# Developement environment
1515
MYSQL_HOST=database
@@ -21,7 +21,6 @@ MYSQL_PASSWORD=linuxfr_rails
2121
# Warning: The database defined as "test" will be erased and
2222
# re-generated from your development database when you run "rake".
2323
# Do not set this db to the same as development or production.
24-
MYSQL_TEST_HOST=database-test
2524
MYSQL_TEST_DATABASE=linuxfr_test
2625
MYSQL_TEST_USER=linuxfr_test
2726
MYSQL_TEST_PASSWORD=linuxfr_test

deployment/linuxfr.org/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ development:
1414
# re-generated from your development database when you run "rake".
1515
# Do not set this db to the same as development or production.
1616
test:
17-
host: <%= ENV['MYSQL_TEST_HOST'] %>
17+
host: <%= ENV['MYSQL_HOST'] %>
1818
database: <%= ENV['MYSQL_TEST_DATABASE'] %>
1919
username: <%= ENV['MYSQL_TEST_USER'] %>
2020
password: <%= ENV['MYSQL_TEST_PASSWORD'] %>

docker-compose.yaml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ services:
2020
- /linuxfr.org/public/tmp:size=100M
2121
depends_on:
2222
- database
23-
- database-test
2423
- redis
2524

2625
linuxfr-board:
@@ -57,24 +56,16 @@ services:
5756
- linuxfr-img
5857

5958
database:
60-
image: mariadb:10.1
59+
build:
60+
context: deployment/database
6161
env_file:
6262
- deployment/default.env
6363
restart: unless-stopped
64+
ports:
65+
- "3306:3306"
6466
volumes:
6567
- data-database:/var/lib/mysql
6668

67-
database-test:
68-
image: mariadb:10.1
69-
env_file:
70-
- deployment/default.env
71-
entrypoint: ["/linuxfr-entrypoint.sh"]
72-
command: ["mysqld"]
73-
restart: unless-stopped
74-
volumes:
75-
- data-database-test:/var/lib/mysql
76-
- ./deployment/database-test/entrypoint.sh:/linuxfr-entrypoint.sh
77-
7869
redis:
7970
image: redis:5
8071
restart: unless-stopped
@@ -84,8 +75,6 @@ services:
8475
volumes:
8576
data-database:
8677
driver: local
87-
data-database-test:
88-
driver: local
8978
data-redis:
9079
driver: local
9180
data-uploads:

0 commit comments

Comments
 (0)