Fix MySQL compatibility in the docker images. (#140)

* Fix MySQL compatibility in the docker images.

* Test the containers with MySQL containers too!
This commit is contained in:
Abhilash Raj
2017-09-30 20:38:33 -07:00
committed by GitHub
parent 035e694152
commit afb8f09eff
7 changed files with 137 additions and 19 deletions

View File

@@ -5,6 +5,10 @@ services:
language: python
env:
- DB=postgres
- DB=mysql
install:
- docker --version
- ./build.sh
@@ -13,14 +17,6 @@ install:
before_script:
- sh tests/generate_tests.sh
- docker-compose -f docker-compose.yaml -f docker-test.yaml up -d
- docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mailman-core
- docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mailman-web
- docker-compose ps
- sleep 30
- docker ps
- docker logs mailman-web
- docker logs mailman-core
script:
- sh tests/test.sh

View File

@@ -7,10 +7,12 @@ COPY docker-entrypoint.sh /usr/local/bin/
#Install all required packages, add user for executing mailman and set execution rights for startup script
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev bash su-exec postgresql-client \
&& pip install psycopg2 mailman==3.1.0 mailman-hyperkitty==1.1.0 \
&& pip install pymysql \
&& apk add --virtual build-deps gcc python3-dev musl-dev postgresql-dev \
&& apk add bash su-exec postgresql-client mysql-client \
&& pip install psycopg2 \
mailman==3.1.0 \
mailman-hyperkitty==1.1.0 \
pymysql \
&& apk del build-deps \
&& adduser -S mailman

View File

@@ -22,6 +22,16 @@ function wait_for_postgres () {
>&2 echo "Postgres is up - continuing"
}
function wait_for_mysql () {
# Check if MySQL is up and accepting connections.
HOSTNAME=$(python3 -c "from urllib.parse import urlparse; o = urlparse('$DATABASE_URL'); print(o.hostname);")
until mysqladmin ping --host "$HOSTNAME" --silent; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 1
done
>&2 echo "MySQL is up - continuing"
}
# Empty the config file.
echo "# This file is autogenerated at container startup." > /etc/mailman.cfg
@@ -76,6 +86,9 @@ fi
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
elif [[ "$DATABASE_TYPE" = 'mysql' ]]
then
wait_for_mysql
fi
# Generate a basic mailman.cfg.

65
docker-compose-mysql.yaml Normal file
View File

@@ -0,0 +1,65 @@
version: '2'
services:
mailman-core:
image: maxking/mailman-core:latest
container_name: mailman-core
hostname: mailman-core
volumes:
- /opt/mailman/core:/opt/mailman/
links:
- database:database
depends_on:
- database
environment:
- DATABASE_URL=mysql+pymysql://mailman:mailmanpass@database/mailmandb
- DATABASE_TYPE=mysql
- DATABASE_CLASS=mailman.database.mysql.MySQLDatabase
- HYPERKITTY_API_KEY=someapikey
networks:
mailman:
ipv4_address: 172.19.199.2
mailman-web:
image: maxking/mailman-web:latest
container_name: mailman-web
hostname: mailman-web
depends_on:
- database
links:
- mailman-core:mailman-core
- database:database
volumes:
- /opt/mailman/web:/opt/mailman-web-data
environment:
- DATABASE_URL=mysql://mailman:mailmanpass@database/mailmandb
- DATABASE_TYPE=mysql
- HYPERKITTY_API_KEY=someapikey
- SECRET_KEY=thisisaverysecretkey
- DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
networks:
mailman:
ipv4_address: 172.19.199.3
database:
environment:
MYSQL_DATABASE: mailmandb
MYSQL_USER: mailman
MYSQL_PASSWORD: mailmanpass
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
restart: always
image: mariadb:10.3
volumes:
- /opt/mailman/database:/var/lib/mysql
networks:
mailman:
ipv4_address: 172.19.199.4
networks:
mailman:
driver: bridge
ipam:
driver: default
config:
-
subnet: 172.19.199.0/24

View File

@@ -1,7 +1,31 @@
#!/bin/bash
set -e
# Check to see if the core is up.
if [ "$DB" = "postgres" ]
then
docker-compose -f docker-compose.yaml -f docker-test.yaml up -d
elif [ "$DB" = "mysql" ]
then
docker-compose -f docker-compose-mysql.yaml -f docker-test.yaml up -d
fi
# Print the IP Addresses of the Containers.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mailman-core
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mailman-web
# Make sure all the containers are running.
docker-compose ps
# Sleep for a while and check again if the containers are up.
sleep 30
docker ps
# Check if there is anything interesting in the logs.
docker logs mailman-web
docker logs mailman-core
# Check to see if the core is working as expected.
curl -u restadmin:restpass http://172.19.199.2:8001/3.1/system
# Check to see if postorius is working.

View File

@@ -7,11 +7,14 @@ COPY mailman-web /opt/mailman-web
# Add startup script to container
COPY docker-entrypoint.sh /usr/local/bin/
# Install packages and dependencies for postorius and hyperkitty
# Add user for executing apps, change ownership for uwsgi+django files and set execution rights for management script
# Install packages and dependencies for postorius and hyperkitty Add user for
# executing apps, change ownership for uwsgi+django files and set execution
# rights for management script
RUN set -ex \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers postgresql-dev \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc postgresql-client \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers \
postgresql-dev mariadb-dev \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc \
postgresql-client mysql-client py-mysqldb \
&& pip install -U mailmanclient==3.1.0 \
postorius==1.1.0 \
hyperkitty==1.1.1 \
@@ -20,7 +23,7 @@ RUN set -ex \
uwsgi \
psycopg2 \
dj-database-url \
pymysql \
mysqlclient \
&& pip install -U django==1.10 \
&& apk del --no-cache .build-deps \
&& addgroup -S mailman \

View File

@@ -14,6 +14,17 @@ function wait_for_postgres () {
>&2 echo "Postgres is up - continuing"
}
function wait_for_mysql () {
# Check if MySQL is up and accepting connections.
HOSTNAME=$(python -c "from urlparse import urlparse; o = urlparse('$DATABASE_URL'); print(o.hostname);")
until mysqladmin ping --host "$HOSTNAME" --silent; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 1
done
>&2 echo "MySQL is up - continuing"
}
function check_or_create () {
# Check if the path exists, if not, create the directory.
if [[ ! -e dir ]]; then
@@ -57,8 +68,12 @@ if [[ ! -v DATABASE_URL ]]; then
export DATABASE_TYPE='sqlite'
fi
if [[ "$DATABASE_TYPE" = 'postgres' ]]; then
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
elif [[ "$DATABASE_TYPE" = 'mysql' ]]
then
wait_for_mysql
fi
# Check if we are in the correct directory before running commands.