From 0eba6a40006e56ed6c3018772d3e074e1d22af89 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Thu, 22 Apr 2021 22:20:18 -0700 Subject: [PATCH] Create initial Dockerfile and config --- .env.local.example => .env.dev.example | 0 .env.prod.example | 2 + .gitignore | 1 + Dockerfile | 64 ++++++++++++++ docker-compose.yml => docker-compose.dev.yml | 0 docker-compose.prod.yml | 88 ++++++++++++++++++++ etc/mysql/my.cnf | 4 + etc/nginx/conf.d/app.conf | 20 +++++ etc/php/php.ini | 2 + 9 files changed, 181 insertions(+) rename .env.local.example => .env.dev.example (100%) create mode 100644 Dockerfile rename docker-compose.yml => docker-compose.dev.yml (100%) create mode 100644 docker-compose.prod.yml create mode 100644 etc/mysql/my.cnf create mode 100644 etc/nginx/conf.d/app.conf create mode 100644 etc/php/php.ini diff --git a/.env.local.example b/.env.dev.example similarity index 100% rename from .env.local.example rename to .env.dev.example diff --git a/.env.prod.example b/.env.prod.example index b093c70..ab1250c 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -3,6 +3,8 @@ APP_ENV=production APP_KEY= APP_DEBUG=false APP_URL= +APP_PORT=80 +APP_PORT_SSL=443 APP_TIMEZONE=UTC LOG_CHANNEL=stack diff --git a/.gitignore b/.gitignore index f5fb7b5..998b6b0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ /vendor Homestead.json Homestead.yaml +docker-compose.yml docker-compose.override.yml npm-debug.log yarn-error.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ffc6765 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,64 @@ +FROM php:8.0-fpm-alpine + +RUN apk add --no-cache --virtual \ + .build-deps \ + $PHPIZE_DEPS \ + bash \ + freetype-dev \ + git \ + icu-dev \ + icu-libs \ + libjpeg-turbo-dev \ + libpng-dev \ + libzip-dev \ + mysql-client \ + oniguruma-dev \ + openssh-client \ + openssl \ + postgresql-dev \ + rsync \ + zlib-dev + +# Configure php extensions. +RUN docker-php-ext-configure gd --with-freetype --with-jpeg + +# Install php extensions. +RUN docker-php-ext-install \ + bcmath \ + calendar \ + exif \ + gd \ + intl \ + pdo_mysql \ + pdo_pgsql \ + pcntl \ + zip + +# Install composer. +ENV COMPOSER_HOME /composer +ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH +ENV COMPOSER_ALLOW_SUPERUSER 1 +RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer + +# Add user and group. +RUN addgroup -S -g 1000 www +RUN adduser -S -u 1000 -s /bin/bash -G www www + +# Setup working directory. +WORKDIR /app +COPY --chown=www:www . /app + +# Install dependencies. +RUN composer install --optimize-autoloader --no-dev + +# Change current user to www. +USER www + +# Optimize application. +RUN php artisan config:cache +RUN php artisan route:cache +RUN php artisan view:cache + +# Expose port 9000 and start php-fpm server. +EXPOSE 9000 +CMD ["php-fpm"] diff --git a/docker-compose.yml b/docker-compose.dev.yml similarity index 100% rename from docker-compose.yml rename to docker-compose.dev.yml diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..9f30ac2 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,88 @@ +version: '3' +services: + app: + image: kcalapp/kcal + container_name: kcal-app + restart: unless-stopped + tty: true + working_dir: /var/www + volumes: + - ./:/var/www + - ./etc/php/php.ini:/usr/local/etc/php/conf.d/local.ini + networks: + - kcal + depends_on: + - db + - redis + - elasticsearch + webserver: + image: nginx:alpine + container_name: kcal-nginx + restart: unless-stopped + tty: true + ports: + - '${APP_PORT:-80}:80' + - '${APP_PORT_SSL:-443}:443' + volumes: + - ./:/var/www + - ./etc/nginx/conf.d/:/etc/nginx/conf.d/ + networks: + - kcal + db: + image: mysql:8.0 + container_name: kcal-db + restart: unless-stopped + tty: true + ports: + - '${DB_PORT:-3306}:3306' + environment: + MYSQL_ROOT_PASSWORD: '${DB_PASSWORD:-kcal}' + MYSQL_DATABASE: '${DB_DATABASE:-kcal}' + MYSQL_USER: '${DB_USERNAME:-kcal}' + MYSQL_PASSWORD: '${DB_PASSWORD:-kcal}' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + volumes: + - db-data:/var/lib/mysql/ + - ./etc/mysql/my.cnf:/etc/mysql/my.cnf + networks: + - kcal + elasticsearch: + image: 'elasticsearch:7.12.0' + container_name: kcal-elasticsearch + environment: + - xpack.security.enabled=false + - discovery.type=single-node + ulimits: + memlock: + soft: -1 + hard: -1 + nofile: + soft: 65536 + hard: 65536 + cap_add: + - IPC_LOCK + volumes: + - elasticsearch-data:/usr/share/elasticsearch/data + ports: + - '${ELASTIC_PORT:-9200}:9200' + networks: + - kcal + redis: + image: 'redis:alpine' + container_name: kcal-redis + ports: + - '${REDIS_PORT:-6379}:6379' + volumes: + - 'redis-data:/data' + networks: + - kcal +networks: + kcal: + driver: bridge +volumes: + db-data: + driver: local + elasticsearch-data: + driver: local + redis-data: + driver: local diff --git a/etc/mysql/my.cnf b/etc/mysql/my.cnf new file mode 100644 index 0000000..dd3354e --- /dev/null +++ b/etc/mysql/my.cnf @@ -0,0 +1,4 @@ +[mysqld] +general_log = 1 +general_log_file = /var/lib/mysql/general.log +secure-file-priv=NULL diff --git a/etc/nginx/conf.d/app.conf b/etc/nginx/conf.d/app.conf new file mode 100644 index 0000000..f397fbd --- /dev/null +++ b/etc/nginx/conf.d/app.conf @@ -0,0 +1,20 @@ +server { + listen 80; + index index.php index.html; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /var/www/public; + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass app:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + location / { + try_files $uri $uri/ /index.php?$query_string; + gzip_static on; + } +} diff --git a/etc/php/php.ini b/etc/php/php.ini new file mode 100644 index 0000000..aacea9d --- /dev/null +++ b/etc/php/php.ini @@ -0,0 +1,2 @@ +upload_max_filesize=40M +post_max_size=40M