Adds a docker dev setup
This commit is contained in:
parent
53ce83a272
commit
545eb291b6
|
@ -18,6 +18,10 @@ _vimrc_local.vim
|
||||||
/.idea/
|
/.idea/
|
||||||
/.phpstorm.meta.php
|
/.phpstorm.meta.php
|
||||||
|
|
||||||
|
# Docker .env files
|
||||||
|
/docker/.env
|
||||||
|
/docker/dev/.env
|
||||||
|
|
||||||
# Project files
|
# Project files
|
||||||
/config/config.php
|
/config/config.php
|
||||||
/test/coverage
|
/test/coverage
|
||||||
|
|
|
@ -36,7 +36,7 @@ build-image.nginx:
|
||||||
paths:
|
paths:
|
||||||
- ./public/assets
|
- ./public/assets
|
||||||
script:
|
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"
|
- docker push "${TEST_IMAGE}-nginx"
|
||||||
- instance=$(docker create "${TEST_IMAGE}-nginx")
|
- instance=$(docker create "${TEST_IMAGE}-nginx")
|
||||||
- docker cp "${instance}:/var/www/public/assets" public/
|
- docker cp "${instance}:/var/www/public/assets" public/
|
||||||
|
@ -48,7 +48,7 @@ build-image:
|
||||||
script:
|
script:
|
||||||
- apk -q add git
|
- apk -q add git
|
||||||
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
|
- 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}"
|
- docker push "${TEST_IMAGE}"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|
70
README.md
70
README.md
|
@ -114,8 +114,11 @@ PRODUCTION_REMOTE # Same as STAGING_REMOTE but for the production environm
|
||||||
PRODUCTION_REMOTE_PATH # Same as STAGING_REMOTE_PATH but for the production environment
|
PRODUCTION_REMOTE_PATH # Same as STAGING_REMOTE_PATH but for the production environment
|
||||||
```
|
```
|
||||||
|
|
||||||
### Docker container
|
### Docker
|
||||||
To build the `engelsystem` and the `engelsystem-nginx` container:
|
|
||||||
|
#### Production
|
||||||
|
|
||||||
|
To build the `es_nginx` and the `es_php_fpm` containers:
|
||||||
```bash
|
```bash
|
||||||
cd docker
|
cd docker
|
||||||
docker-compose build
|
docker-compose build
|
||||||
|
@ -123,30 +126,63 @@ docker-compose build
|
||||||
|
|
||||||
or to build the containers separately
|
or to build the containers separately
|
||||||
```bash
|
```bash
|
||||||
docker build -f docker/nginx/Dockerfile . -t engelsystem-nginx
|
docker build -f docker/nginx/Dockerfile . -t es_nginx
|
||||||
docker build -f docker/Dockerfile . -t engelsystem
|
docker build -f docker/Dockerfile . -t es_php_fpm
|
||||||
```
|
```
|
||||||
|
|
||||||
Import database
|
Import database
|
||||||
```bash
|
```bash
|
||||||
docker exec -it engelsystem bin/migrate
|
docker exec -it engelsystem_es_php_fpm_1 bin/migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Local development
|
#### Development
|
||||||
To use the working directory in the container the docker-compose file has to be changed:
|
|
||||||
```yaml
|
This repo [ships a docker setup](docker/dev) for a quick development start.
|
||||||
[...]
|
|
||||||
nginx:
|
If you use another uid/gid than 1000 on your machine you have to adjust it in [docker/dev/.env](docker/dev/.env).
|
||||||
volumes:
|
|
||||||
- ../public/assets:/var/www/public/assets
|
Run this once
|
||||||
[...]
|
|
||||||
engelsystem:
|
```bash
|
||||||
volumes:
|
cd docker/dev
|
||||||
- ../:/var/www
|
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
|
||||||
|
|
||||||
|
# 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
|
#### Scripts
|
||||||
|
|
||||||
##### bin/deploy.sh
|
##### 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.
|
The `bin/deploy.sh` script can be used to deploy the engelsystem. It uses rsync to deploy the application to a server over ssh.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
COMPOSE_PROJECT_NAME="engelsystem_dev"
|
||||||
|
UID=1000
|
||||||
|
GID=1000
|
|
@ -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
|
|
@ -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:
|
|
@ -1,23 +1,23 @@
|
||||||
version: "3.6"
|
version: "3.6"
|
||||||
services:
|
services:
|
||||||
nginx:
|
es_nginx:
|
||||||
image: engelsystem-nginx
|
image: es_nginx
|
||||||
build:
|
build:
|
||||||
context: ..
|
context: ..
|
||||||
dockerfile: ""
|
dockerfile: docker/nginx/Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- 5000:80
|
- 5000:80
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
depends_on:
|
depends_on:
|
||||||
- engelsystem
|
- es_php_fpm
|
||||||
engelsystem:
|
es_php_fpm:
|
||||||
image: engelsystem
|
image: es_php_fpm
|
||||||
build:
|
build:
|
||||||
context: ..
|
context: ..
|
||||||
dockerfile: ""
|
dockerfile: docker/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
MYSQL_HOST: database
|
MYSQL_HOST: es_database
|
||||||
MYSQL_USER: engelsystem
|
MYSQL_USER: engelsystem
|
||||||
MYSQL_PASSWORD: engelsystem
|
MYSQL_PASSWORD: engelsystem
|
||||||
MYSQL_DATABASE: engelsystem
|
MYSQL_DATABASE: engelsystem
|
||||||
|
@ -25,8 +25,8 @@ services:
|
||||||
- internal
|
- internal
|
||||||
- database
|
- database
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- es_database
|
||||||
database:
|
es_database:
|
||||||
image: mariadb:10.2
|
image: mariadb:10.2
|
||||||
environment:
|
environment:
|
||||||
MYSQL_DATABASE: engelsystem
|
MYSQL_DATABASE: engelsystem
|
||||||
|
|
|
@ -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
|
FROM node:10-alpine as themes
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY .babelrc .browserslistrc package.json webpack.config.js yarn.lock /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
|
COPY resources/assets/ /app/resources/assets
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
FROM nginx:alpine
|
FROM es_nginx
|
||||||
RUN mkdir -p /var/www/public/ && touch /var/www/public/index.php
|
|
||||||
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
|
|
||||||
COPY --from=themes /app/public/assets /var/www/public/assets/
|
COPY --from=themes /app/public/assets /var/www/public/assets/
|
||||||
|
|
|
@ -33,7 +33,7 @@ http {
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass engelsystem:9000;
|
fastcgi_pass es_php_fpm:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
|
|
Loading…
Reference in New Issue