From 2a6188d79d243b8c2acca5bd214acd54ce60c7ac Mon Sep 17 00:00:00 2001 From: Valian Date: Fri, 21 Apr 2017 12:07:45 +0200 Subject: [PATCH 1/4] Development and production docker configuration --- .env | 10 +++++++++ Dockerfile | 15 ++++++++++--- docker-compose.prod.yml | 34 ++++++++++++++++++++++++++++ docker-compose.yml | 49 +++++++++++++++++++++------------------- docker-entrypoint.sh | 50 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 .env create mode 100644 docker-compose.prod.yml create mode 100644 docker-entrypoint.sh diff --git a/.env b/.env new file mode 100644 index 00000000..6022dd2f --- /dev/null +++ b/.env @@ -0,0 +1,10 @@ +DB_USERNAME=easyappointments +DB_NAME=easyappointments + +# before deploying to production change to harder password +DB_PASSWORD=change-that-password + +# change to you installation address +APP_URL=localhost +APP_HOST=0.0.0.0 +APP_PORT=80 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2545f434..786aa408 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,14 @@ -FROM tutum/apache-php +FROM wichon/alpine-apache-php -MAINTAINER Alex Tselegidis +ENV PROJECT_DIR=/app \ + APP_URL=localhost -EXPOSE 80 +RUN apk --no-cache add php-zlib php-mysqli php-gettext + +COPY ./src $PROJECT_DIR +COPY docker-entrypoint.sh /entrypoint.sh + +VOLUME $PROJECT_DIR/storage + +ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] +CMD ["run"] \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 00000000..6dfe9387 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,34 @@ +version: '2' +services: + database: + image: mysql + environment: + - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} + - MYSQL_DATABASE=${DB_NAME} + - MYSQL_USER=${DB_USERNAME} + - MYSQL_PASSWORD=${DB_PASSWORD} + volumes: + - easy-appointments-data:/var/lib/mysql + restart: always + + + application: + image: easyappointments + build: + context: . + ports: + - 80:80 + environment: + - DB_NAME=${DB_NAME} + - DB_USERNAME=${DB_USERNAME} + - DB_PASSWORD=${DB_PASSWORD} + - DB_HOST=database:3306 + - APP_URL=${APP_URL} + - APP_HOST=${APP_HOST} + volumes: + - easy-appointments-storage:/app/src/storage + restart: always + +volumes: + easy-appointments-data: + easy-appointments-storage: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7a63f0f1..4f7f8dd7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,26 @@ -storage: - image: 'busybox:latest' - volumes: - - /var/lib/mysql - - ./src:/app - command: sleep 3153600000 -database: - image: mysql:5.7 - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: easyappointments - volumes_from: - - storage - restart: always - mem_limit: 200m -app: - build: ./ - ports: - - 80:80 - links: - - database:database - volumes_from: - - storage +version: '2' +services: + database: + image: mysql + environment: + - MYSQL_ROOT_PASSWORD=veryhardpassword + - MYSQL_DATABASE=easyapp + - MYSQL_USER=easyapp + - MYSQL_PASSWORD=veryhardpassword + + application: + image: easyappointments + build: + context: . + volumes: + - ./src:/app + command: dev + ports: + - ${APP_HOST}:80:80 + environment: + - DB_NAME=easyapp + - DB_USERNAME=easyapp + - DB_PASSWORD=veryhardpassword + - DB_HOST=database:3306 + - APP_URL=localhost + restart: always \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..f2c0d9da --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env sh +if [ "$1" == "run" ]; then + + echo "Preparing Easy!Appointments production configuration.." + + cp $PROJECT_DIR/config-sample.php $PROJECT_DIR/config.php + sed -i "s/DB_HOST = ''/DB_HOST = '$DB_HOST'/g" $PROJECT_DIR/config.php + sed -i "s/DB_USERNAME = ''/DB_USERNAME = '$DB_USERNAME'/g" $PROJECT_DIR/config.php + sed -i "s/DB_PASSWORD = ''/DB_PASSWORD = '$DB_PASSWORD'/g" $PROJECT_DIR/config.php + sed -i "s/DB_NAME = ''/DB_NAME = '$DB_NAME'/g" $PROJECT_DIR/config.php + sed -i "s/url-to-easyappointments-directory/$APP_URL/g" $PROJECT_DIR/config.php + + sed -i "s#^DocumentRoot \".*#DocumentRoot \"$PROJECT_DIR\"#g" /etc/apache2/httpd.conf + sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf + printf "\n\n\tAllowOverride All\n\n" >> /etc/apache2/httpd.conf + + chown -R apache:apache $PROJECT_DIR + chmod -R 777 $PROJECT_DIR/storage/uploads + + echo "Starting Easy!Appointments server.." + + exec httpd -D FOREGROUND + +elif [ "$1" == "dev" ]; then + + echo "Preparing Easy!Appointments development configuration.." + + if [ ! -e "$PROJECT_DIR/config.php" ]; then + cp $PROJECT_DIR/config-sample.php $PROJECT_DIR/config.php + sed -i "s/DB_HOST = ''/DB_HOST = '$DB_HOST'/g" $PROJECT_DIR/config.php + sed -i "s/DB_USERNAME = ''/DB_USERNAME = '$DB_USERNAME'/g" $PROJECT_DIR/config.php + sed -i "s/DB_PASSWORD = ''/DB_PASSWORD = '$DB_PASSWORD'/g" $PROJECT_DIR/config.php + sed -i "s/DB_NAME = ''/DB_NAME = '$DB_NAME'/g" $PROJECT_DIR/config.php + sed -i "s/DEBUG_MODE = FALSE/DEBUG_MODE = TRUE/g" $PROJECT_DIR/config.php + sed -i "s/url-to-easyappointments-directory/$APP_URL/g" $PROJECT_DIR/config.php + fi + + sed -i "s#^DocumentRoot \".*#DocumentRoot \"$PROJECT_DIR\"#g" /etc/apache2/httpd.conf + sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf + printf "\n\n\tAllowOverride All\n\n" >> /etc/apache2/httpd.conf + + chown -R apache:apache $PROJECT_DIR + chmod -R 777 $PROJECT_DIR/storage/uploads + + echo "Starting Easy!Appointments server.." + + exec httpd -D FOREGROUND +fi + +exec $@ \ No newline at end of file From 4bebdf4beca324a2fe6ca6048b5a10ac06330502 Mon Sep 17 00:00:00 2001 From: Valian Date: Fri, 21 Apr 2017 12:13:03 +0200 Subject: [PATCH 2/4] updated readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 15f925a5..34053f81 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,18 @@ If you have problems installing or configuring the application take a look on th You can also report problems on the [issues page](https://github.com/alextselegidis/easyappointments/issues) and help the development progress. +### Docker +To start Easy!Appointments using Docker in development configuration with source files mounted into container, run: +``` +docker-compose up +``` + +Production deployment can be made by changing required values in .env file (DB_PASSWORD, APP_URL, APP_PORT) and running: +``` +docker-compose -f docker-compose.prod.yml up -d +``` +Database data will be stored in named volume "easy-appointments-data", and app storage (logs, cache, uploads) in "easy-appointments-data". + ### User Feedback Whether it is new ideas or defects, your feedback is highly appreciated and will be taken into consideration for the following releases of the project. Share your experience and discuss your From 547bad01f1b07db8b7780c2c0d583ca48ac99bce Mon Sep 17 00:00:00 2001 From: Valian Date: Sun, 23 Apr 2017 13:22:09 +0200 Subject: [PATCH 3/4] email settings as ENV variables inside Docker containers --- .env | 17 ++++++++++---- Dockerfile | 2 +- docker-compose.prod.yml | 9 +++----- docker-compose.yml | 7 +++--- docker-entrypoint.sh | 50 ++++++++++++++++++++++++----------------- 5 files changed, 49 insertions(+), 36 deletions(-) diff --git a/.env b/.env index 6022dd2f..e22bd892 100644 --- a/.env +++ b/.env @@ -1,10 +1,19 @@ -DB_USERNAME=easyappointments -DB_NAME=easyappointments +DB_USERNAME=easyapp +DB_NAME=easyapp # before deploying to production change to harder password -DB_PASSWORD=change-that-password +DB_PASSWORD=veryhardpassword # change to you installation address APP_URL=localhost APP_HOST=0.0.0.0 -APP_PORT=80 \ No newline at end of file +APP_PORT=80 + +# email settings - set to 'smtp' and provide SMTP settings if you want to send emails +EMAIL_PROTOCOL=mail +SMTP_HOST=smtp.gmail.com +SMTP_USER=user +SMTP_PASS=password +SMTP_CRYPTO=ssl +SMTP_PORT=25 + diff --git a/Dockerfile b/Dockerfile index 786aa408..a9d9b1d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,4 @@ COPY docker-entrypoint.sh /entrypoint.sh VOLUME $PROJECT_DIR/storage ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] -CMD ["run"] \ No newline at end of file +CMD ["run"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 6dfe9387..bdf04318 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -19,16 +19,13 @@ services: ports: - 80:80 environment: - - DB_NAME=${DB_NAME} - - DB_USERNAME=${DB_USERNAME} - - DB_PASSWORD=${DB_PASSWORD} - DB_HOST=database:3306 - - APP_URL=${APP_URL} - - APP_HOST=${APP_HOST} + env_file: + - .env volumes: - easy-appointments-storage:/app/src/storage restart: always volumes: easy-appointments-data: - easy-appointments-storage: \ No newline at end of file + easy-appointments-storage: diff --git a/docker-compose.yml b/docker-compose.yml index 4f7f8dd7..f3d914df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,9 +18,8 @@ services: ports: - ${APP_HOST}:80:80 environment: - - DB_NAME=easyapp - - DB_USERNAME=easyapp - - DB_PASSWORD=veryhardpassword - DB_HOST=database:3306 - APP_URL=localhost - restart: always \ No newline at end of file + env_file: + - .env + restart: always diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f2c0d9da..f6981a31 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,23 +1,42 @@ #!/usr/bin/env sh -if [ "$1" == "run" ]; then - - echo "Preparing Easy!Appointments production configuration.." +createAppSettings() { cp $PROJECT_DIR/config-sample.php $PROJECT_DIR/config.php sed -i "s/DB_HOST = ''/DB_HOST = '$DB_HOST'/g" $PROJECT_DIR/config.php sed -i "s/DB_USERNAME = ''/DB_USERNAME = '$DB_USERNAME'/g" $PROJECT_DIR/config.php sed -i "s/DB_PASSWORD = ''/DB_PASSWORD = '$DB_PASSWORD'/g" $PROJECT_DIR/config.php sed -i "s/DB_NAME = ''/DB_NAME = '$DB_NAME'/g" $PROJECT_DIR/config.php + if [ "$EMAIL_PROTOCOL" == "smtp" ]; then + echo "Setting up email..." + sed -i "s/\$config\['protocol'\] = 'mail'/\$config['protocol'] = 'smtp'/g" $PROJECT_DIR/application/config/email.php + sed -i "s#// \$config\['smtp_host'\] = ''#\$config['smtp_host'] = '$SMTP_HOST'#g" $PROJECT_DIR/application/config/email.php + sed -i "s#// \$config\['smtp_user'\] = ''#\$config['smtp_user'] = '$SMTP_USER'#g" $PROJECT_DIR/application/config/email.php + sed -i "s#// \$config\['smtp_pass'\] = ''#\$config['smtp_pass'] = '$SMTP_PASS'#g" $PROJECT_DIR/application/config/email.php + sed -i "s#// \$config\['smtp_crypto'\] = 'ssl'#\$config['smtp_crypto'] = '$SMTP_CRYPTO'#g" $PROJECT_DIR/application/config/email.php + sed -i "s#// \$config\['smtp_port'\] = 25#\$config['smtp_port'] = $SMTP_PORT#g" $PROJECT_DIR/application/config/email.php + fi sed -i "s/url-to-easyappointments-directory/$APP_URL/g" $PROJECT_DIR/config.php +} +updateApacheSettings() { sed -i "s#^DocumentRoot \".*#DocumentRoot \"$PROJECT_DIR\"#g" /etc/apache2/httpd.conf - sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf + sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf printf "\n\n\tAllowOverride All\n\n" >> /etc/apache2/httpd.conf chown -R apache:apache $PROJECT_DIR chmod -R 777 $PROJECT_DIR/storage/uploads +} - echo "Starting Easy!Appointments server.." + +if [ "$1" == "run" ]; then + + echo "Preparing Easy!Appointments production configuration.." + + createAppSettings + + updateApacheSettings + + echo "Starting Easy!Appointments development server.." exec httpd -D FOREGROUND @@ -25,26 +44,15 @@ elif [ "$1" == "dev" ]; then echo "Preparing Easy!Appointments development configuration.." - if [ ! -e "$PROJECT_DIR/config.php" ]; then - cp $PROJECT_DIR/config-sample.php $PROJECT_DIR/config.php - sed -i "s/DB_HOST = ''/DB_HOST = '$DB_HOST'/g" $PROJECT_DIR/config.php - sed -i "s/DB_USERNAME = ''/DB_USERNAME = '$DB_USERNAME'/g" $PROJECT_DIR/config.php - sed -i "s/DB_PASSWORD = ''/DB_PASSWORD = '$DB_PASSWORD'/g" $PROJECT_DIR/config.php - sed -i "s/DB_NAME = ''/DB_NAME = '$DB_NAME'/g" $PROJECT_DIR/config.php - sed -i "s/DEBUG_MODE = FALSE/DEBUG_MODE = TRUE/g" $PROJECT_DIR/config.php - sed -i "s/url-to-easyappointments-directory/$APP_URL/g" $PROJECT_DIR/config.php - fi - sed -i "s#^DocumentRoot \".*#DocumentRoot \"$PROJECT_DIR\"#g" /etc/apache2/httpd.conf - sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf - printf "\n\n\tAllowOverride All\n\n" >> /etc/apache2/httpd.conf + createAppSettings + sed -i "s/DEBUG_MODE = FALSE/DEBUG_MODE = TRUE/g" $PROJECT_DIR/config.php - chown -R apache:apache $PROJECT_DIR - chmod -R 777 $PROJECT_DIR/storage/uploads + updateApacheSettings - echo "Starting Easy!Appointments server.." + echo "Starting Easy!Appointments production server.." exec httpd -D FOREGROUND fi -exec $@ \ No newline at end of file +exec $@ From 2d3e03f54c086041fa64d76980fd446e45b8febf Mon Sep 17 00:00:00 2001 From: Valian Date: Sun, 21 May 2017 13:53:14 +0200 Subject: [PATCH 4/4] Docker image based on official PHP-apache distribution. Some configuration tweaks to support it --- .env | 4 ++-- Dockerfile | 8 ++++---- README.md | 11 +++++++++-- docker-compose.prod.yml | 2 +- docker-compose.yml | 4 +++- docker-entrypoint.sh | 25 +++++++------------------ 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/.env b/.env index e22bd892..d38b7b00 100644 --- a/.env +++ b/.env @@ -1,10 +1,10 @@ DB_USERNAME=easyapp DB_NAME=easyapp -# before deploying to production change to harder password +# before deploying to production change to harder password, and don't commit it to git DB_PASSWORD=veryhardpassword -# change to you installation address +# change to your installation address APP_URL=localhost APP_HOST=0.0.0.0 APP_PORT=80 diff --git a/Dockerfile b/Dockerfile index a9d9b1d2..4c4b60f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ -FROM wichon/alpine-apache-php +FROM php:7.0-apache -ENV PROJECT_DIR=/app \ +ENV PROJECT_DIR=/var/www/html \ APP_URL=localhost -RUN apk --no-cache add php-zlib php-mysqli php-gettext +RUN docker-php-ext-install mysqli gettext COPY ./src $PROJECT_DIR COPY docker-entrypoint.sh /entrypoint.sh VOLUME $PROJECT_DIR/storage -ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] CMD ["run"] diff --git a/README.md b/README.md index 34053f81..3ac9d5f3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ You can also report problems on the [issues page](https://github.com/alextselegi and help the development progress. ### Docker -To start Easy!Appointments using Docker in development configuration with source files mounted into container, run: +To start Easy!Appointments using Docker in development configuration, with source files mounted into container, run: ``` docker-compose up ``` @@ -53,7 +53,14 @@ Production deployment can be made by changing required values in .env file (DB_P ``` docker-compose -f docker-compose.prod.yml up -d ``` -Database data will be stored in named volume "easy-appointments-data", and app storage (logs, cache, uploads) in "easy-appointments-data". + +Database data will be stored in named volume `easyappointments_easy-appointments-data`, and app storage (logs, cache, uploads) in `easyappointments_easy-appointments-storage`. +To find where exactly they are stored, you can run +``` +docker volume inspect easyappointments_easy-appointments-storage +``` + +Production containers will automatically be restarted in case of crash / server reboot. For more info, take a look into `docker-compose.prod.yml` file. ### User Feedback Whether it is new ideas or defects, your feedback is highly appreciated and will be taken into diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index bdf04318..712bedf4 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -23,7 +23,7 @@ services: env_file: - .env volumes: - - easy-appointments-storage:/app/src/storage + - easy-appointments-storage:/var/www/html/src/storage restart: always volumes: diff --git a/docker-compose.yml b/docker-compose.yml index f3d914df..cdc03837 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,13 +13,15 @@ services: build: context: . volumes: - - ./src:/app + - ./src:/var/www/html command: dev ports: - ${APP_HOST}:80:80 environment: - DB_HOST=database:3306 - APP_URL=localhost + depends_on: + - database env_file: - .env restart: always diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f6981a31..cf82c818 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,7 +6,7 @@ createAppSettings() { sed -i "s/DB_USERNAME = ''/DB_USERNAME = '$DB_USERNAME'/g" $PROJECT_DIR/config.php sed -i "s/DB_PASSWORD = ''/DB_PASSWORD = '$DB_PASSWORD'/g" $PROJECT_DIR/config.php sed -i "s/DB_NAME = ''/DB_NAME = '$DB_NAME'/g" $PROJECT_DIR/config.php - if [ "$EMAIL_PROTOCOL" == "smtp" ]; then + if [ "$EMAIL_PROTOCOL" = "smtp" ]; then echo "Setting up email..." sed -i "s/\$config\['protocol'\] = 'mail'/\$config['protocol'] = 'smtp'/g" $PROJECT_DIR/application/config/email.php sed -i "s#// \$config\['smtp_host'\] = ''#\$config['smtp_host'] = '$SMTP_HOST'#g" $PROJECT_DIR/application/config/email.php @@ -16,31 +16,22 @@ createAppSettings() { sed -i "s#// \$config\['smtp_port'\] = 25#\$config['smtp_port'] = $SMTP_PORT#g" $PROJECT_DIR/application/config/email.php fi sed -i "s/url-to-easyappointments-directory/$APP_URL/g" $PROJECT_DIR/config.php -} -updateApacheSettings() { - sed -i "s#^DocumentRoot \".*#DocumentRoot \"$PROJECT_DIR\"#g" /etc/apache2/httpd.conf - sed -i "s#/var/www/localhost/htdocs#$PROJECT_DIR#" /etc/apache2/httpd.conf - printf "\n\n\tAllowOverride All\n\n" >> /etc/apache2/httpd.conf - - chown -R apache:apache $PROJECT_DIR - chmod -R 777 $PROJECT_DIR/storage/uploads + chown -R www-data $PROJECT_DIR } -if [ "$1" == "run" ]; then +if [ "$1" = "run" ]; then echo "Preparing Easy!Appointments production configuration.." createAppSettings - updateApacheSettings + echo "Starting Easy!Appointments production server.." - echo "Starting Easy!Appointments development server.." + exec docker-php-entrypoint apache2-foreground - exec httpd -D FOREGROUND - -elif [ "$1" == "dev" ]; then +elif [ "$1" = "dev" ]; then echo "Preparing Easy!Appointments development configuration.." @@ -48,11 +39,9 @@ elif [ "$1" == "dev" ]; then createAppSettings sed -i "s/DEBUG_MODE = FALSE/DEBUG_MODE = TRUE/g" $PROJECT_DIR/config.php - updateApacheSettings - echo "Starting Easy!Appointments production server.." - exec httpd -D FOREGROUND + exec docker-php-entrypoint apache2-foreground fi exec $@