Skip to content

Commit 18ac2c1

Browse files
authored
Merge pull request #350 from Trim/docker-avatar-mysql
Docker improve mysql and image services
2 parents e205f73 + de82bdc commit 18ac2c1

File tree

9 files changed

+43
-37
lines changed

9 files changed

+43
-37
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

INSTALL.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,24 @@ server {
176176
177177
listen 0.0.0.0:80;
178178
179-
location ~ ^/(avatars|medias)/ {
179+
location ~ ^/medias/ {
180180
root /home/linuxfr/linuxfr.org/uploads;
181181
}
182182
183-
# To install the LinuxFr img service, see: https://github.com/linuxfrorg/img-LinuxFr.org
183+
# Avatars files uploaded on linuxfr server are stored in partitions
184+
# with folder name containing 3 digits
185+
location ~ ^/avatars/\d\d\d/ {
186+
root /home/linuxfr/linuxfr.org/uploads;
187+
}
188+
189+
# Avatars URLs has to be served by the image service
190+
location ~ ^/avatars/ {
191+
# To install the LinuxFr img service, see: https://github.com/linuxfrorg/img-LinuxFr.org
192+
proxy_pass http://localhost:8000;
193+
}
194+
184195
location /img/ {
196+
# To install the LinuxFr img service, see: https://github.com/linuxfrorg/img-LinuxFr.org
185197
proxy_pass http://localhost:8000;
186198
}
187199

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'] %>

deployment/nginx/templates/image.dlfp.conf.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ server {
44

55
server_name ${IMAGE_DOMAIN};
66

7-
location ~ ^/(avatars|medias)/ {
7+
location ~ ^/medias/ {
88
root /var/linuxfr/uploads;
99
}
1010

11+
# Avatars files uploaded on linuxfr server are stored in partitions
12+
# with folder name containing 3 digits
13+
location ~ ^/avatars/\d\d\d/ {
14+
root /var/linuxfr/uploads;
15+
}
16+
17+
# All other images (avatars URLs and /img) pass by the image service
1118
location / {
1219
proxy_pass http://linuxfr-img:8000;
1320
}

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)