simplified deployment with docker (#639)

* updated Dockerfile and docker-compose.yml, replaced cron with ofelia and setup.sh with automatically executed startup.sh

* fixed permissions by setting them in setup-script
This commit is contained in:
LU-386
2022-03-16 13:59:21 +01:00
committed by GitHub
parent 18507ddb6f
commit e03320d27b
6 changed files with 46 additions and 54 deletions

28
Dockerfile Normal file → Executable file
View File

@ -1,8 +1,9 @@
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
WORKDIR /var/www
COPY ./docker-compose/php/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
# Install system dependencies
RUN apt-get update && apt-get install -y \
@ -15,26 +16,21 @@ RUN apt-get update && apt-get install -y \
unzip \
libzip-dev \
libmagickwand-dev \
mariadb-client
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
mariadb-client \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pecl install imagick \
&& docker-php-ext-enable imagick
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl bcmath gd
RUN rmdir html && docker-php-ext-install pdo_mysql mbstring zip exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
RUN useradd -G www-data,root -u 1000 -d /home/crater crater && chmod 777 /var/www/ && chown 1000:1000 /var/www/
USER 0
# Set working directory
WORKDIR /var/www
USER $user
COPY ./docker-compose/startup.sh /startup.sh
CMD ["/startup.sh"]

View File

@ -1,25 +1,22 @@
version: '3'
services:
app:
build:
args:
user: crater-user
uid: 1000
context: ./
dockerfile: Dockerfile
image: crater-php
build: .
image: craterapp/crater
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
- ./docker-compose/php/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:rw,delegated
- ./:/var/www:z
labels:
ofelia.enabled: "true"
ofelia.job-exec.somecron.schedule: "@every 60s"
ofelia.job-exec.somecron.command: "php artisan schedule:run"
networks:
- crater
db:
image: mariadb
restart: always
restart: unless-stopped
volumes:
- db:/var/lib/mysql
# If you want to persist data on the host, comment the line above this one...
@ -41,19 +38,19 @@ services:
ports:
- 80:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
- ./:/var/www:z
- ./docker-compose/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
networks:
- crater
cron:
build:
context: ./
dockerfile: ./docker-compose/cron.dockerfile
ofelia:
image: mcuadros/ofelia
restart: unless-stopped
command: daemon --docker
volumes:
- ./:/var/www
networks:
- crater
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
- app
volumes:
db:

View File

@ -1,10 +0,0 @@
FROM php:7.4-fpm-alpine
RUN apk add --no-cache \
php7-bcmath
RUN docker-php-ext-install pdo pdo_mysql bcmath
COPY docker-compose/crontab /etc/crontabs/root
CMD ["crond", "-f"]

View File

@ -1 +0,0 @@
* * * * * cd /var/www && php artisan schedule:run >> /dev/stdout 2>&1

View File

@ -1,6 +0,0 @@
#!/bin/sh
docker-compose exec app composer install --no-interaction --prefer-dist --optimize-autoloader
docker-compose exec app php artisan storage:link || true
docker-compose exec app php artisan key:generate

16
docker-compose/startup.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
chmod 775 /var/www/ -R
chown 1000:33 /var/www -R
if [ ! -f ".env" ]; then
cp .env.example .env
echo "created .env from .env.example"
fi
composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan storage:link || true
php artisan key:generate
php-fpm