Skip to content

Instantly share code, notes, and snippets.

@ramytamer
Created October 18, 2020 20:03
Show Gist options
  • Save ramytamer/c0864cdd6fd2cc489736d313a9603517 to your computer and use it in GitHub Desktop.
Save ramytamer/c0864cdd6fd2cc489736d313a9603517 to your computer and use it in GitHub Desktop.
Laravel Docker Alpine
version: '3.8'
services:
database:
image: mysql:5.7
volumes:
- mysqldata:/var/lib/mysql
ports:
- "${MYSQL_PORT:-13306}:3306"
env_file:
- .env
redis:
image: redis:5.0-alpine
command: redis-server --appendonly yes
volumes:
- redisdata:/data
web:
image: 025585334644.dkr.ecr.eu-central-1.amazonaws.com/soa/web:${IMAGE_TAG:-latest}
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- publicassets:/app/public:ro
ports:
- "${NGINX_PORT:-4000}:80"
depends_on:
- app
app:
image: image:tag
volumes:
- publicassets:/app/public
env_file:
- .env
depends_on:
- database
- redis
worker:
image: image:tag
command: php artisan horizon
env_file:
- .env
restart: on-failure
depends_on:
- app
websockets:
image: image:tag
command: php artisan websockets:serve
env_file:
- .env
restart: on-failure
depends_on:
- app
ports:
- "${WEBSOCKETS_PORT:-4001}:6001"
volumes:
mysqldata: {}
redisdata: {}
publicassets: {}
version: '3.8'
services:
database:
image: mysql:5.7
volumes:
- mysqldata:/var/lib/mysql
ports:
- "${MYSQL_PORT:-13306}:3306"
env_file:
- .env
redis:
image: redis:5.0-alpine
command: redis-server --appendonly yes
volumes:
- redisdata:/data
ports:
- "${REDIS_PORT:-16379}:6379"
web:
build:
context: .
target: Web
volumes:
- ./public:/app/public
- ./config/nginx/local.conf:/etc/nginx/conf.d/default.conf
ports:
- "${NGINX_PORT:-4000}:80"
depends_on:
- app
app:
build:
context: .
target: App
volumes:
- .:/app
env_file:
- .env
depends_on:
- database
- redis
worker:
build:
context: .
target: App
command: php artisan horizon
volumes:
- .:/app
env_file:
- .env
restart: always
depends_on:
- app
websockets:
build:
context: .
target: App
command: php artisan websockets:serve
volumes:
- .:/app
env_file:
- .env
restart: always
depends_on:
- app
ports:
- "${WEBSOCKETS_PORT:-6001}:6001"
volumes:
mysqldata: {}
redisdata: {}
FROM php:7.4-fpm-alpine as App
ARG BUILD_ENV=development
ARG MIX_ENV_FILE=.env.development
ENV BUILD_ENV=${BUILD_ENV}
WORKDIR /app
RUN apk add --no-cache --update \
&& apk add build-base \
git grep curl bash \
zlib-dev libzip-dev \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libxml2-dev \
bzip2-dev \
libmcrypt-dev \
zip unzip \
autoconf pcre-dev
RUN docker-php-ext-install mysqli pdo pdo_mysql tokenizer zip exif pcntl xml bcmath
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
RUN pecl channel-update pecl.php.net \
&& pecl install mcrypt-1.0.3 \
&& pecl install redis \
&& docker-php-ext-enable mcrypt bcmath
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY config/php.ini /usr/local/etc/php/conf.d/php.ini
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN set -eux; \
composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer clear-cache
ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}"
COPY . .
RUN set -eux; \
mkdir -p storage/logs storage/framework bootstrap/cache; \
composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader; \
composer clear-cache
COPY --from=node:10.20.1-alpine /usr/local/bin/node /usr/local/bin/
COPY --from=node:10.20.1-alpine /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node:10.20.1-alpine /opt/ /opt/
RUN ln -sf /usr/local/bin/node /usr/local/bin/nodejs \
&& ln -sf ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -sf ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
&& ln -sf /opt/yarn*/bin/yarn /usr/local/bin/yarn \
&& ln -sf /opt/yarn*/bin/yarnpkg /usr/local/bin/yarnpkg
ENV PATH="/usr/local/bin:${PATH}"
RUN npm install
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["php-fpm"]
# Web NGINX Stage
FROM nginx:stable-alpine AS Web
COPY config/nginx/production.conf /etc/nginx/conf.d/default.conf
WORKDIR /app
COPY --from=App /app/public public/
#!/bin/sh
set -xe
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi
if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
php artisan config:clear
chmod -R 777 storage/ bootstrap/cache
if [ "$APP_ENV" != 'production' ]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction
npm install
npm run dev
else
npm run production
fi
if [ "$(ls -A database/migrations/*.php 2> /dev/null)" ]; then
echo "[+] Running Migrations..."
php artisan migrate --force
fi
php artisan livewire:configure-s3-upload-cleanup
php artisan storage:link
php artisan config:cache
fi
exec docker-php-entrypoint "$@"
server {
listen 80;
index index.php index.html;
charset utf-8;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
client_max_body_size 20M;
root /app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ \.php$ {
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;
}
}
server {
listen 80;
index index.php index.html;
charset utf-8;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
client_max_body_size 20M;
root /app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment