summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-10-27 12:20:30 +0100
committerGitHub <noreply@github.com>2019-10-27 12:20:30 +0100
commit360a27016184bce3039fdbbb45b8f7b6bf02da3a (patch)
treedf2a3794ae4248b8efee23d01981b2451ca4fa2e
parent9b08b951a2f7036519a9711ff4aa32a8709e261d (diff)
parent545eb291b6d32c613f814eefc8e80e39899b1e90 (diff)
Merge pull request #662 from weeman1337/feature/660-docker-dev
Improves the docker workflow
-rw-r--r--.gitignore4
-rw-r--r--.gitlab-ci.yml4
-rw-r--r--README.md72
-rw-r--r--docker/.env (renamed from contrib/.env)0
-rw-r--r--docker/Dockerfile (renamed from contrib/Dockerfile)0
-rw-r--r--docker/dev/.env3
-rw-r--r--docker/dev/Dockerfile19
-rw-r--r--docker/dev/docker-compose.yml80
-rw-r--r--docker/docker-compose.yml (renamed from contrib/docker-compose.yml)20
-rw-r--r--docker/nginx/Dockerfile (renamed from contrib/nginx/Dockerfile)8
-rw-r--r--docker/nginx/nginx.conf (renamed from contrib/nginx/nginx.conf)2
11 files changed, 178 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index cda5cf92..6089cc32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,10 @@ _vimrc_local.vim
/.idea/
/.phpstorm.meta.php
+# Docker .env files
+/docker/.env
+/docker/dev/.env
+
# Project files
/config/config.php
/test/coverage
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e14b1841..2590a0b3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -36,7 +36,7 @@ build-image.nginx:
paths:
- ./public/assets
script:
- - docker build --pull -t "${TEST_IMAGE}-nginx" -f contrib/nginx/Dockerfile .
+ - docker build --pull -t "${TEST_IMAGE}-nginx" -f docker/nginx/Dockerfile .
- docker push "${TEST_IMAGE}-nginx"
- instance=$(docker create "${TEST_IMAGE}-nginx")
- docker cp "${instance}:/var/www/public/assets" public/
@@ -48,7 +48,7 @@ build-image:
script:
- apk -q add git
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
- - docker build --pull --build-arg VERSION="${VERSION}" -t "${TEST_IMAGE}" -f contrib/Dockerfile .
+ - docker build --pull --build-arg VERSION="${VERSION}" -t "${TEST_IMAGE}" -f docker/Dockerfile .
- docker push "${TEST_IMAGE}"
test:
diff --git a/README.md b/README.md
index 9b4a3aaf..a1470e32 100644
--- a/README.md
+++ b/README.md
@@ -114,39 +114,75 @@ PRODUCTION_REMOTE # Same as STAGING_REMOTE but for the production environm
PRODUCTION_REMOTE_PATH # Same as STAGING_REMOTE_PATH but for the production environment
```
-### Docker container
-To build the `engelsystem` and the `engelsystem-nginx` container:
+### Docker
+
+#### Production
+
+To build the `es_nginx` and the `es_php_fpm` containers:
```bash
-cd contrib
+cd docker
docker-compose build
```
or to build the containers separately
```bash
-docker build -f contrib/nginx/Dockerfile . -t engelsystem-nginx
-docker build -f contrib/Dockerfile . -t engelsystem
+docker build -f docker/nginx/Dockerfile . -t es_nginx
+docker build -f docker/Dockerfile . -t es_php_fpm
```
Import database
```bash
-docker exec -it engelsystem bin/migrate
+docker exec -it engelsystem_es_php_fpm_1 bin/migrate
+```
+
+#### Development
+
+This repo [ships a docker setup](docker/dev) for a quick development start.
+
+If you use another uid/gid than 1000 on your machine you have to adjust it in [docker/dev/.env](docker/dev/.env).
+
+Run this once
+
+```bash
+cd docker/dev
+docker-compose up
+```
+
+Run these commands once initially and then as required after changes
+
```
+# Install composer dependencies
+docker exec -it engelsystem_dev_es_workspace_1 composer i
+
+# Install node packages
+docker exec -it engelsystem_dev_es_workspace_1 yarn install
+
+# Run a front-end build
+docker exec -it engelsystem_dev_es_workspace_1 yarn build
-#### Local development
-To use the working directory in the container the docker-compose file has to be changed:
-```yaml
-[...]
- nginx:
- volumes:
- - ../public/assets:/var/www/public/assets
-[...]
- engelsystem:
- volumes:
- - ../:/var/www
-[...]
+# Update the translation files
+docker exec -it engelsystem_dev_es_workspace_1 find /var/www/resources/lang -type f -name '*.po' -exec sh -c 'file="{}"; msgfmt "${file%.*}.po" -o "${file%.*}.mo"' \;
+
+# Run the migrations
+docker exec -it engelsystem_dev_es_workspace_1 bin/migrate
```
+While developing you may use the watch mode to rebuild the system on changes
+
+```
+# Run a front-end build
+docker exec -it engelsystem_dev_es_workspace_1 yarn build:watch
+```
+
+##### Hint for using Xdebug with *PhpStorm*
+
+For some reason *PhpStorm* is unable to detect the server name.
+But without a server name it's impossible to set up path mappings.
+Because of that the docker setup sets the server name *engelsystem*.
+To get Xdebug working you have to create a server with the name *engelsystem* manually.
+
#### Scripts
+
##### bin/deploy.sh
The `bin/deploy.sh` script can be used to deploy the engelsystem. It uses rsync to deploy the application to a server over ssh.
diff --git a/contrib/.env b/docker/.env
index 5f8d43b8..5f8d43b8 100644
--- a/contrib/.env
+++ b/docker/.env
diff --git a/contrib/Dockerfile b/docker/Dockerfile
index 013ccf1d..013ccf1d 100644
--- a/contrib/Dockerfile
+++ b/docker/Dockerfile
diff --git a/docker/dev/.env b/docker/dev/.env
new file mode 100644
index 00000000..f1622708
--- /dev/null
+++ b/docker/dev/.env
@@ -0,0 +1,3 @@
+COMPOSE_PROJECT_NAME="engelsystem_dev"
+UID=1000
+GID=1000
diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile
new file mode 100644
index 00000000..ef514102
--- /dev/null
+++ b/docker/dev/Dockerfile
@@ -0,0 +1,19 @@
+# Engelsystem PHP FPM development image including Xdebug
+FROM php:7-fpm-alpine AS es_php_fpm
+WORKDIR /var/www
+RUN apk add --no-cache icu-dev $PHPIZE_DEPS && \
+ pecl install xdebug && \
+ docker-php-ext-install intl pdo_mysql && \
+ docker-php-ext-enable xdebug
+RUN echo -e "xdebug.remote_enable=1\nxdebug.remote_connect_back=1\n" >> /usr/local/etc/php/conf.d/xdebug.ini
+
+ENV TRUSTED_PROXIES 10.0.0.0/8,::ffff:10.0.0.0/8,\
+ 127.0.0.0/8,::ffff:127.0.0.0/8,\
+ 172.16.0.0/12,::ffff:172.16.0.0/12,\
+ 192.168.0.0/16,::ffff:192.168.0.0/16,\
+ ::1/128,fc00::/7,fec0::/10
+
+# Engelsystem development workspace
+# Contains all tools required to build / manage the system
+FROM es_php_fpm AS es_workspace
+RUN apk add --no-cache composer gettext nodejs npm yarn
diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml
new file mode 100644
index 00000000..858d6232
--- /dev/null
+++ b/docker/dev/docker-compose.yml
@@ -0,0 +1,80 @@
+version: "3.6"
+services:
+ es_nginx:
+ image: es_dev_nginx
+ build:
+ context: ./../..
+ dockerfile: docker/nginx/Dockerfile
+ target: es_nginx
+ volumes:
+ - ./../..:/var/www
+ ports:
+ - 5000:80
+ networks:
+ - internal
+ depends_on:
+ - es_php_fpm
+ es_php_fpm:
+ image: es_dev_php_fpm
+ build:
+ context: ./../..
+ dockerfile: docker/dev/Dockerfile
+ target: es_php_fpm
+ user: "${UID}:${GID}"
+ volumes:
+ - ./../..:/var/www
+ environment:
+ MYSQL_HOST: es_database
+ MYSQL_USER: engelsystem
+ MYSQL_PASSWORD: engelsystem
+ MYSQL_DATABASE: engelsystem
+ PHP_IDE_CONFIG: serverName=engelsystem
+ ENVIRONMENT: development
+ MAIL_DRIVER: log
+ APP_NAME: Engelsystem DEV
+ networks:
+ - internal
+ - database
+ depends_on:
+ - es_database
+ es_workspace:
+ image: es_dev_workspace
+ build:
+ context: ./../..
+ dockerfile: docker/dev/Dockerfile
+ target: es_workspace
+ user: "${UID}:${GID}"
+ volumes:
+ - ./../..:/var/www
+ environment:
+ HOME: /tmp
+ MYSQL_HOST: es_database
+ MYSQL_USER: engelsystem
+ MYSQL_PASSWORD: engelsystem
+ MYSQL_DATABASE: engelsystem
+ ENVIRONMENT: development
+ MAIL_DRIVER: log
+ APP_NAME: Engelsystem DEV
+ networks:
+ - internal
+ - database
+ depends_on:
+ - es_database
+ es_database:
+ image: mariadb:10.2
+ environment:
+ MYSQL_DATABASE: engelsystem
+ MYSQL_USER: engelsystem
+ MYSQL_PASSWORD: engelsystem
+ MYSQL_RANDOM_ROOT_PASSWORD: 1
+ MYSQL_INITDB_SKIP_TZINFO: "yes"
+ volumes:
+ - db:/var/lib/mysql
+ networks:
+ - database
+volumes:
+ db: {}
+
+networks:
+ internal:
+ database:
diff --git a/contrib/docker-compose.yml b/docker/docker-compose.yml
index 4624cce4..47b85d56 100644
--- a/contrib/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -1,23 +1,23 @@
version: "3.6"
services:
- nginx:
- image: engelsystem-nginx
+ es_nginx:
+ image: es_nginx
build:
context: ..
- dockerfile: contrib/nginx/Dockerfile
+ dockerfile: docker/nginx/Dockerfile
ports:
- 5000:80
networks:
- internal
depends_on:
- - engelsystem
- engelsystem:
- image: engelsystem
+ - es_php_fpm
+ es_php_fpm:
+ image: es_php_fpm
build:
context: ..
- dockerfile: contrib/Dockerfile
+ dockerfile: docker/Dockerfile
environment:
- MYSQL_HOST: database
+ MYSQL_HOST: es_database
MYSQL_USER: engelsystem
MYSQL_PASSWORD: engelsystem
MYSQL_DATABASE: engelsystem
@@ -25,8 +25,8 @@ services:
- internal
- database
depends_on:
- - database
- database:
+ - es_database
+ es_database:
image: mariadb:10.2
environment:
MYSQL_DATABASE: engelsystem
diff --git a/contrib/nginx/Dockerfile b/docker/nginx/Dockerfile
index 9f5dcb3b..f4355af9 100644
--- a/contrib/nginx/Dockerfile
+++ b/docker/nginx/Dockerfile
@@ -1,3 +1,7 @@
+FROM nginx:alpine as es_nginx
+RUN mkdir -p /var/www/public/ && touch /var/www/public/index.php
+COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
+
FROM node:10-alpine as themes
WORKDIR /app
COPY .babelrc .browserslistrc package.json webpack.config.js yarn.lock /app/
@@ -5,7 +9,5 @@ RUN yarn install
COPY resources/assets/ /app/resources/assets
RUN yarn build
-FROM nginx:alpine
-RUN mkdir -p /var/www/public/ && touch /var/www/public/index.php
-COPY contrib/nginx/nginx.conf /etc/nginx/nginx.conf
+FROM es_nginx
COPY --from=themes /app/public/assets /var/www/public/assets/
diff --git a/contrib/nginx/nginx.conf b/docker/nginx/nginx.conf
index d95c18e2..63e934bc 100644
--- a/contrib/nginx/nginx.conf
+++ b/docker/nginx/nginx.conf
@@ -33,7 +33,7 @@ http {
}
location ~ \.php$ {
- fastcgi_pass engelsystem:9000;
+ fastcgi_pass es_php_fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;