From b33474761e84bc646b22fa95207f5a7b26df33e4 Mon Sep 17 00:00:00 2001 From: alext Date: Sat, 3 Nov 2018 15:15:20 +0100 Subject: [PATCH] Moved Docker related files into the docker directory. --- .env | 19 ------------ .gitignore | 2 ++ doc/docker.md | 12 ++++--- docker-compose.prod.yml | 31 ------------------- docker-compose.yml | 27 ---------------- docker/.env.example | 17 ++++++++++ Dockerfile => docker/Dockerfile | 6 ++-- docker/docker-compose.prod.yml | 30 ++++++++++++++++++ docker/docker-compose.yml | 27 ++++++++++++++++ .../docker-entrypoint.sh | 2 -- readme.md | 11 +++++-- 11 files changed, 94 insertions(+), 90 deletions(-) delete mode 100644 .env delete mode 100644 docker-compose.prod.yml delete mode 100644 docker-compose.yml create mode 100644 docker/.env.example rename Dockerfile => docker/Dockerfile (57%) create mode 100644 docker/docker-compose.prod.yml create mode 100644 docker/docker-compose.yml rename docker-entrypoint.sh => docker/docker-entrypoint.sh (99%) diff --git a/.env b/.env deleted file mode 100644 index d38b7b00..00000000 --- a/.env +++ /dev/null @@ -1,19 +0,0 @@ -DB_USERNAME=easyapp -DB_NAME=easyapp - -# before deploying to production change to harder password, and don't commit it to git -DB_PASSWORD=veryhardpassword - -# change to your installation address -APP_URL=localhost -APP_HOST=0.0.0.0 -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/.gitignore b/.gitignore index 4384e3f1..792142d2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ /doc/apigen/html /doc/jsdoc/html /doc/plato/html +/docker/.env* +!/docker/.env.example /node_modules/ /npm-debug.log /src/config.php diff --git a/doc/docker.md b/doc/docker.md index 7f8dd398..0ce12504 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -1,8 +1,10 @@ # Docker -Run the development containers of Easy!Appointments with Docker and Docker Compose utility. Docker allows you to compose your application from microservices, without worrying about inconsistencies between development and production environments and without locking into any platform or language. +Run the development containers of Easy!Appointments with Docker and Docker Compose utility. Docker allows you to compose your application from micro-services, without worrying about inconsistencies between development and production environments and without locking into any platform or language. -Make sure that you have Docker and Docker compose installed and configured in your system and execute the following command through your terminal while being in the Git clone directory: +Copy the `.env.example` file to `.env` inside the `docker` directory and set the desired environment variables. + +Make sure that you have Docker and Docker Compose installed and configured in your system and execute the following command through your terminal while being in `docker` directory of your Git clone: `docker-compose up` @@ -22,10 +24,10 @@ class Config { // DATABASE SETTINGS // ------------------------------------------------------------------------ - const DB_HOST = 'database'; + const DB_HOST = 'database:3306'; const DB_NAME = 'easyappointments'; - const DB_USERNAME = 'root'; - const DB_PASSWORD = 'root'; + const DB_USERNAME = 'easyappointments'; + const DB_PASSWORD = 'easyappointments'; // ------------------------------------------------------------------------ // GOOGLE CALENDAR SYNC diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 712bedf4..00000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,31 +0,0 @@ -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_HOST=database:3306 - env_file: - - .env - volumes: - - easy-appointments-storage:/var/www/html/src/storage - restart: always - -volumes: - easy-appointments-data: - easy-appointments-storage: diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index cdc03837..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,27 +0,0 @@ -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:/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/.env.example b/docker/.env.example new file mode 100644 index 00000000..aeef4ea3 --- /dev/null +++ b/docker/.env.example @@ -0,0 +1,17 @@ +# Before deploying to production change to harder password, and don't commit it to git. +DB_USERNAME=easyappointments +DB_NAME=easyappointments +DB_PASSWORD=easyappointments + +# Change to your installation address. +APP_URL=localhost +APP_HOST=0.0.0.0 +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/docker/Dockerfile similarity index 57% rename from Dockerfile rename to docker/Dockerfile index fd721d9e..2052900e 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -6,11 +6,11 @@ ENV PROJECT_DIR=/var/www/html \ RUN docker-php-ext-install mysqli gettext COPY ./src $PROJECT_DIR -COPY docker-entrypoint.sh /entrypoint.sh +COPY docker-entrypoint.sh /docker-entrypoint.sh -RUN sed -i 's/\r//' /entrypoint.sh +RUN sed -i 's/\r//' /docker-entrypoint.sh VOLUME $PROJECT_DIR/storage -ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "/docker-entrypoint.sh"] CMD ["run"] diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml new file mode 100644 index 00000000..96a06824 --- /dev/null +++ b/docker/docker-compose.prod.yml @@ -0,0 +1,30 @@ +version: '2' +services: + database: + image: mysql + environment: + - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD} + - MYSQL_DATABASE=${DB_NAME} + - MYSQL_USER=${DB_USERNAME} + - MYSQL_PASSWORD=${DB_PASSWORD} + volumes: + - easyappointments-data:/var/lib/mysql + restart: always + + application: + image: easyappointments + build: + context: . + ports: + - 80:80 + environment: + - DB_HOST=database:3306 + env_file: + - .env + volumes: + - easyappointments-storage:/var/www/html/src/storage + restart: always + +volumes: + easyappointments-data: + easyappointments-storage: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..34541132 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,27 @@ +version: '2' +services: + database: + image: mysql + environment: + - MYSQL_DATABASE=${DB_NAME} + - MYSQL_USER=${DB_USERNAME} + - MYSQL_PASSWORD=${DB_PASSWORD} + - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} + + application: + image: easyappointments + build: + context: . + volumes: + - ../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/docker-entrypoint.sh similarity index 99% rename from docker-entrypoint.sh rename to docker/docker-entrypoint.sh index cf82c818..27b1b019 100644 --- a/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -20,7 +20,6 @@ createAppSettings() { chown -R www-data $PROJECT_DIR } - if [ "$1" = "run" ]; then echo "Preparing Easy!Appointments production configuration.." @@ -35,7 +34,6 @@ elif [ "$1" = "dev" ]; then echo "Preparing Easy!Appointments development configuration.." - createAppSettings sed -i "s/DEBUG_MODE = FALSE/DEBUG_MODE = TRUE/g" $PROJECT_DIR/config.php diff --git a/readme.md b/readme.md index bb165a12..dcf87364 100644 --- a/readme.md +++ b/readme.md @@ -47,20 +47,25 @@ 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, copy the `docker/.env.example` file to `docker/.env` and run: + ``` docker-compose up ``` +inside the `docker` directory. + +**Important: once the containers are set up, the `src/config.php` file will be overwritten. In some host environments you might need to manually change the BASE_URL value, if Docker cannot map the container to `http://localhost`. + 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 `easyappointments_easy-appointments-data`, and app storage (logs, cache, uploads) in `easyappointments_easy-appointments-storage`. +Database data will be stored in named volume `easyappointments_easyappointments-data`, and app storage (logs, cache, uploads) in `easyappointments_easyappointments-storage`. To find where exactly they are stored, you can run ``` -docker volume inspect easyappointments_easy-appointments-storage +docker volume inspect easyappointments_easyappointments-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.