Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Update docker provisioning #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM php:7.1-fpm

ARG DOCKER_USER="devops"
ARG DOCKER_USER_ID=1001
ARG GIT_USER_NAME="John Doe"
ARG GIT_USER_EMAIL="[email protected]"

Expand All @@ -25,9 +26,17 @@ RUN apt-get update \
&& chmod +x /usr/local/bin/composer


# Install xdebug extention
# Install & configure xdebug extention
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
&& docker-php-ext-enable xdebug \
&& echo 'xdebug.remote_enable=on' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_autostart=on' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_connect_back=off' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_handler=dbgp' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.profiler_enable=0' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.profiler_output_dir="/var/www/html"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_port=9000' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.extended_info = 1' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini


# Install PhpMetrics
Expand All @@ -36,10 +45,11 @@ RUN chmod +x /phpmetrics.phar
RUN mv /phpmetrics.phar /usr/local/bin/phpmetrics


# Add user DOCKER_USER defined in .env & give sudo privilege
RUN adduser --disabled-password --gecos '' ${DOCKER_USER}
RUN adduser ${DOCKER_USER} sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Add local user & give sudo privilege
RUN useradd --shell /bin/bash -u ${DOCKER_USER_ID} -o -c "" -m ${DOCKER_USER} \
&& adduser ${DOCKER_USER} sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& export HOME=/home/${DOCKER_USER}


# Override default bash config
Expand Down
16 changes: 16 additions & 0 deletions .docker/hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#

GIT_USER=$(git config user.name)
GIT_EMAIL=$(git config user.email)
COMMIT_MSG_FILE=$1

# Fetch the GIT diff and format it as command input:
DIFF=$(git diff -r -p -m -M --full-index --staged | cat)

# Run GrumPHP
(cd "${HOOK_EXEC_PATH}" && printf "%s\n" "${DIFF}" | docker-compose run --rm symfony php $(HOOK_COMMAND) "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE")
12 changes: 12 additions & 0 deletions .docker/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#

# Fetch the GIT diff and format it as command input:
DIFF=$(git diff -r -p -m -M --full-index --staged | cat)

# Run GrumPHP
(cd "${HOOK_EXEC_PATH}" && printf "%s\n" "${DIFF}" | docker-compose run --rm symfony php $(HOOK_COMMAND) '--skip-success-output')
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ RESTART_POLICIES=no
# User used to run cmd inside Symfony container
DOCKER_USER=devops

# Need to be the same UUID than local user (use "id -u $USER" to get current user uuid)
DOCKER_USER_ID=1001

# Your host local IP for Xdebug usage
REMOTE_HOST=192.168.1.74

#####################
# MySql #
Expand Down
35 changes: 23 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,34 @@ services:
restart: "${RESTART_POLICIES}"
ports:
- "${NGINX_PORT}:80"
links:
- "symfony:symfony"
volumes:
- ".:/home/docker"
- "./.docker/dev/dev.conf:/etc/nginx/conf.d/default.conf:ro"
- "$PWD:/home/docker"
- "$PWD/.docker/dev/dev.conf:/etc/nginx/conf.d/default.conf:ro"
networks:
- "symfony"

symfony:
build:
context: ./.docker/dev/
args:
- "DOCKER_USER=${DOCKER_USER}"
- "DOCKER_USER_ID=${DOCKER_USER_ID}"
- "GIT_USER_NAME=${GIT_USER_NAME}"
- "GIT_USER_EMAIL=${GIT_USER_EMAIL}"
image: symfony3_docker:dev
restart: "${RESTART_POLICIES}"
links:
- "db:db"
environment:
- "XDEBUG_CONFIG=remote_host=${REMOTE_HOST}"
volumes:
- ".:/home/docker"
- "./.docker/dev/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
- "$PWD:/home/docker"
- "$PWD/.docker/dev/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
working_dir: "/home/docker"
user: "${DOCKER_USER}"
networks:
- "symfony"

db:
image: mysql
image: mysql:5.6
restart: "${RESTART_POLICIES}"
environment:
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
Expand All @@ -49,7 +52,9 @@ services:
ports:
- "${MYSQL_PORT}:3306"
volumes:
- "./.data/db:/var/lib/mysql:Z"
- "$PWD/.data/db:/var/lib/mysql:Z"
networks:
- "symfony"

phpmyadmin:
image: phpmyadmin/phpmyadmin
Expand All @@ -62,12 +67,18 @@ services:
- "${PMA_PORT}:80"
depends_on:
- "db"
networks:
- "symfony"

mailhog:
image: mailhog/mailhog
restart: "${RESTART_POLICIES}"
ports:
- "${MAILHOG_PORT}:8025"
- "1025:1025"
links:
- "symfony:symfony"
networks:
- "symfony"

networks:
symfony:
driver: bridge
6 changes: 3 additions & 3 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## Grumphp configuration file
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
hooks_dir: ./.docker/hooks
ascii:
failed: ~
succeeded: ~
tasks:
jsonlint: ~
yamllint: ~
phpcsfixer2:
allow_risky: true
cache_file: .php_cs.cache
config: .php_cs
rules: []
using_cache: true
verbose: true
diff: true
Expand Down