Skip to content

Commit

Permalink
feat: prod works, dev doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybatch committed Jul 8, 2023
1 parent d9fd5b6 commit de2746f
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 11 deletions.
75 changes: 75 additions & 0 deletions docker/development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: '3.5'
services:

sqldb:
image: mysql:5.7
environment:
- MYSQL_DATABASE=${DOCKER_DB_DATABASE:-arc}
- MYSQL_USER=${DOCKER_DB_USER:-arc}
- MYSQL_PASSWORD=${DOCKER_DB_PASSWORD:-changem3please}
- MYSQL_ROOT_PASSWORD=${DOCKER_DB_ROOT:-reallychangethisplease}
# ports: # Uncomment this to expose your DB on port 3336
# - 3336:3306
# volumes:
# Any sql or sh files in this folder (e.g. db restore) are run on initialisation
# See https://hub.docker.com/_/mysql -> Initializing a fresh instance
# - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
command: --default-storage-engine innodb
restart: unless-stopped

nginx:
image: arc/nginx
ports:
- 8000:80
volumes:
- public:/opt/project/public:ro
restart: unless-stopped
depends_on:
- arc
healthcheck:
test: wget --spider http://nginx/health || exit 1
interval: 20s
start_period: 10s
timeout: 10s
retries: 3

arc:
build:
context: ../service
target: dev
image: arc:fpm-dev
environment:
APP_ENV: "local"
RUN_AS: "10001:50"
BRANCH: ${BRANCH:-develop}
DB_DATABASE: ${DOCKER_DB_DATABASE:-arc}
DB_HOST: ${DOCKER_DB_HOST:-sqldb}
DB_PASSWORD: ${DOCKER_DB_PASSWORD:-changem3please}
DB_PORT: ${DOCKER_DB_PORT:-3306}
DB_USERNAME: ${DOCKER_DB_USERNAME:-arc}
volumes:
- public:/opt/project/public
- ${APP_ROOT}/app:/opt/project/app
- ${APP_ROOT}/config:/opt/project/config
- ${APP_ROOT}/database:/opt/project/database
- ${APP_ROOT}/resources:/opt/project/resources
- ${APP_ROOT}/routes:/opt/project/routes
- ${APP_ROOT}/tests:/opt/project/tests
# .sh files in this dir will be executed on startup after migrations are run
- ./docker-entrypoint-init.d:/docker-entrypoint-init.d
# Needed if we want to save passport key
# - ./.env:/opt/arc/ # touch .env before starting
restart: unless-stopped
# entrypoint: bash
# stdin_open: true # docker run -i
# tty: true # docker run -t

mailer:
image: schickling/mailcatcher
ports:
- "${MAILER_SMTP_PORT:-1025}:1025"
- "${MAILER_ADMIN_PORT:-1080}:1080"

volumes:
public:
mysql:
5 changes: 5 additions & 0 deletions docker/development/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DOCKER_DB_DATABASE=arc
DOCKER_DB_USER=arc
DOCKER_DB_PASSWORD=changem3please
DOCKER_DB_ROOT=reallychangethisplease
APP_ROOT=/home/tobias/usr/arc/service/app
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ LABEL version="1.0"
LABEL description="Nginx alpine image built to reverse proxy requests to a PHP FPM server"

ADD nginx_default.conf /etc/nginx/conf.d/default.conf

# docker build -t arc/nginx .
File renamed without changes.
6 changes: 2 additions & 4 deletions docker/production/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ services:
restart: unless-stopped

nginx:
build:
context: .
dockerfile: Dockerfile.nginx
image: nginx-fpm-reverse-proxy
image: arc/nginx
ports:
- 8000:80
volumes:
Expand All @@ -48,6 +45,7 @@ services:
DB_PASSWORD: ${DOCKER_DB_PASSWORD:-changem3please}
DB_PORT: ${DOCKER_DB_PORT:-3306}
DB_USERNAME: ${DOCKER_DB_USERNAME:-arc}
RUN_AS: "10001:50"
volumes:
- public:/opt/project/public
# .sh files in this dir will be executed on startup after migrations are run
Expand Down
13 changes: 11 additions & 2 deletions docker/service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ RUN apk add --no-cache \
libc-dev \
libgomp \
libmagic \
linux-headers \
m4 \
make \
mpc1 \
Expand Down Expand Up @@ -68,6 +69,10 @@ RUN docker-php-ext-install -j$(nproc) xsl
FROM fpm-php-ext-base AS php-ext-opcache
RUN docker-php-ext-install -j$(nproc) opcache

FROM fpm-php-ext-base AS php-ext-xdebug
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug

FROM php:${PHP_VER}-fpm-alpine AS fpm-base
ARG BRANCH
Expand Down Expand Up @@ -165,21 +170,25 @@ ENV MAIL_TO_ADMIN_ADDRESS=to@example.com
ENV MAIL_TO_ADMIN_NAME='Admin Name'
ENV MAIL_TO_DEVELOPER_TEAM=arc@neontribe.co.uk
ENV MAIL_TO_DEVELOPER_NAME='User Support'
ENV RUN_AS=""
VOLUME [ "/opt/project/storage" ]
ENTRYPOINT /entry-point.sh

# developement build
FROM base AS dev
# copy kimai develop source
COPY --from=git-dev --chown=www-data:www-data /opt/project /opt/project
RUN echo \$PATH
COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
COPY --from=php-ext-xdebug /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY --from=php-ext-xdebug /usr/local/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so
RUN \
export COMPOSER_HOME=/composer && \
composer --no-ansi install --working-dir=/opt/project --optimize-autoloader && \
composer --no-ansi clearcache && \
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
chown -R www-data:www-data /opt/project /usr/local/etc/php/php.ini && \
chown -R www-data:www-data /opt/project /usr/local/etc/php/php.ini
chown -R www-data:www-data /opt/project /usr/local/etc/php/php.ini && \
echo "error_reporting=E_ALL" > /usr/local/etc/php/conf.d/error_reporting.ini
ENV APP_ENV=dev
ENV memory_limit=256M

Expand Down
35 changes: 30 additions & 5 deletions docker/service/entry-point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ function handleStartup() {
# in production we will have a .env mounted into the container, this will have (at least) a
# APP_KEY, if we don't have a .env we will create one
if [ ! -e /opt/project/.env ]; then
if [ "$APP_ENV" == "prod" ]; then
if [ "$APP_ENV" == "production" ]; then
echo "No .env file present."
echo "Your are running a prod environment version but there is no .env file present"
echo "You need to mount one into this container or the system cannot proceed."
exit 1
fi
fi

grep APP_KEY .env
# shellcheck disable=SC2181
if [ "$?" != 0 ]; then
echo "APP_KEY=''" > .env
php /opt/project/artisan key:generate
fi

# These are idempotent, run them anyway
php /opt/project/artisan migrate
chmod 600 /opt/project/storage/*.key
if [ "$APP_ENV" == "local" ] || [ "$APP_ENV" == "dev" ] || [ "$APP_ENV" == "development" ] ; then
php /opt/project/artisan migrate:refresh --seed --force
else
# These are idempotent, run them anyway
php /opt/project/artisan migrate
chmod 600 /opt/project/storage/*.key
fi

php /passport-install.php

Expand All @@ -48,5 +52,26 @@ function handleStartup() {

checkDatabase
handleStartup

if [ -n "$RUN_AS" ]; then
GROUP_ID=${RUN_AS#*:}
USER_ID=${RUN_AS%:*} # drops substring from last occurrence of `SubStr` to end of string

GROUP_NAME=$(id -ng "$GROUP_ID")
if [ -z "$GROUP_NAME" ]; then
addgroup --gid "$GROUP_ID" arcuser
GROUP_NAME=arcuser
fi

USER_NAME=$(id -n "$USER_ID")
if [ -z "$USER_NAME" ]; then
adduser -G "$GROUP_NAME" -u "$USER_ID" arcuser
USER_NAME=arcuser
fi
sed -i "s/user = www-data/user = $USER_NAME/g" /usr/local/etc/php-fpm.d/www.conf
sed -i "s/group = www-data/group = $GROUP_NAME/g" /usr/local/etc/php-fpm.d/www.conf
fi

exec php-fpm

exit
6 changes: 6 additions & 0 deletions docker/service/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes

0 comments on commit de2746f

Please sign in to comment.