From: Nik Okuntseff Date: Sun, 30 Dec 2018 17:29:05 +0000 (+0000) Subject: Added database creation step to docker composition. X-Git-Tag: timetracker_1.19-1~368 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c3feccfa60f8970ea2c2891d22549b2913a9561f;p=timetracker.git Added database creation step to docker composition. --- diff --git a/.gitignore b/.gitignore index d73d8553..e346fd3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config.php +populate.sql WEB-INF/templates_c/*.* WEB-INF/templates_c/import_* WEB-INF/templates_c/tt* diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4b86f2a2..00000000 --- a/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -# This file is for development work. Not suitable for production. -FROM php:7.2-apache - -# Use the default production configuration. -RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" - -# Override with custom settings. -# COPY config/php_tt.ini $PHP_INI_DIR/conf.d/ - -# Install mysqli extension. -RUN docker-php-ext-install mysqli - -# Install gd extension. -RUN apt-get update && apt-get install libpng-dev -y \ - && docker-php-ext-install gd - -# Install ldap extension. -RUN apt-get install libldap2-dev -y \ - && docker-php-ext-install ldap -# TODO: check if ldap works, as the above is missing this step: -# && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - -# Cleanup. The intention was to keep image size down. -# RUN rm -rf /var/lib/apt/lists/* -# -# The above does not work. Files are removed, but -# image files (zipped or not) are not getting smaller. Why? - -# Copy application source code to /var/www/html/. -COPY . /var/www/html/ -# Create configuration file. -RUN cp /var/www/html/WEB-INF/config.php.dist /var/www/html/WEB-INF/config.php -# Replace DSN value to something connectable to a Docker container running mariadb. -RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_sql/timetracker|g" /var/www/html/WEB-INF/config.php -# Note that db is defined as anuko_sql/timetracker where anuko_sql is service name and timetracker is db name. -# See docker-compose.yml for details. diff --git a/docker-compose.yml b/docker-compose.yml index 0182a95a..b4f3b4b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,29 +4,34 @@ version: '3.7' services: # anuko_tt is a web application built as per Dockerfile specification. anuko_tt: - build: . + build: + context: . + dockerfile: dockerfile-tt image: anuko_timetracker:dev container_name: anuko-timetracker # Use localhost:8080 to connect to timetracker via browser. ports: - "8080:80" - # anuko_sql is a mariadb instance to which timetracker connects. + # anuko_db is a mariadb instance to which timetracker connects. # Connect parameters are also specified in timetracker Dockerfile after # creation of its configuration file. Specifically, we replace # user name, password, service name (aka resolvable to IP server name # where mariadb runs), and database name there from the defaults. # These two sets of credentials must match for a successful connect. - anuko_sql: - image: "mariadb:latest" - container_name: anuko-sql + anuko_db: + build: + context: . + dockerfile: dockerfile-db + image: "anuko_database:dev" + container_name: anuko-database environment: MYSQL_RANDOM_ROOT_PASSWORD: "yes" MYSQL_DATABASE: timetracker MYSQL_USER: anuko_user MYSQL_PASSWORD: anuko_pw volumes: - - db-data:/var/lib/mysql + - database:/var/lib/mysql volumes: - db-data: \ No newline at end of file + database: \ No newline at end of file diff --git a/dockerfile-db b/dockerfile-db new file mode 100644 index 00000000..b1367395 --- /dev/null +++ b/dockerfile-db @@ -0,0 +1,9 @@ +# This file is for development work. Not suitable for production. +FROM mariadb:latest + +# Copy database creation script. +COPY mysql.sql /docker-entrypoint-initdb.d/ + +# Copy database population script, if available. +# TODO: design a better directory structure. +COPY populate.sql /docker-entrypoint-initdb.d/ diff --git a/dockerfile-tt b/dockerfile-tt new file mode 100644 index 00000000..8902cbf7 --- /dev/null +++ b/dockerfile-tt @@ -0,0 +1,36 @@ +# This file is for development work. Not suitable for production. +FROM php:7.2-apache + +# Use the default production configuration. +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +# Override with custom settings. +# COPY config/php_tt.ini $PHP_INI_DIR/conf.d/ + +# Install mysqli extension. +RUN docker-php-ext-install mysqli + +# Install gd extension. +RUN apt-get update && apt-get install libpng-dev -y \ + && docker-php-ext-install gd + +# Install ldap extension. +RUN apt-get install libldap2-dev -y \ + && docker-php-ext-install ldap +# TODO: check if ldap works, as the above is missing this step: +# && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ + +# Cleanup. The intention was to keep image size down. +# RUN rm -rf /var/lib/apt/lists/* +# +# The above does not work. Files are removed, but +# image files (zipped or not) are not getting smaller. Why? + +# Copy application source code to /var/www/html/. +COPY . /var/www/html/ +# Create configuration file. +RUN cp /var/www/html/WEB-INF/config.php.dist /var/www/html/WEB-INF/config.php +# Replace DSN value to something connectable to a Docker container running mariadb. +RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" /var/www/html/WEB-INF/config.php +# Note that db is defined as anuko_db/timetracker where anuko_db is service name and timetracker is db name. +# See docker-compose.yml for details.