Last active
March 13, 2023 11:55
-
-
Save lakuapik/36d85b8a7b98855e4375139ab6ea971b to your computer and use it in GitHub Desktop.
Laravel Sail example config using alpine:edge image with PHP 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /laravel-project/.env.example | |
APP_NAME=Laravel | |
APP_ENV=local | |
APP_KEY= | |
APP_DEBUG=true | |
APP_URL=http://localhost | |
APP_SERVICE=laravel.test | |
APP_PORT=8000 | |
LOG_CHANNEL=stack | |
LOG_LEVEL=debug | |
DB_CONNECTION=mysql | |
DB_HOST=127.0.0.1 | |
DB_PORT=3306 | |
DB_DATABASE=laravel | |
DB_USERNAME=root | |
DB_PASSWORD= | |
BROADCAST_DRIVER=log | |
CACHE_DRIVER=file | |
QUEUE_CONNECTION=sync | |
SESSION_DRIVER=file | |
SESSION_LIFETIME=120 | |
MEMCACHED_HOST=127.0.0.1 | |
REDIS_HOST=127.0.0.1 | |
REDIS_PASSWORD=null | |
REDIS_PORT=6379 | |
MAIL_MAILER=smtp | |
MAIL_HOST=mailhog | |
MAIL_PORT=1025 | |
MAIL_USERNAME=null | |
MAIL_PASSWORD=null | |
MAIL_ENCRYPTION=null | |
MAIL_FROM_ADDRESS=null | |
MAIL_FROM_NAME="${APP_NAME}" | |
AWS_ACCESS_KEY_ID= | |
AWS_SECRET_ACCESS_KEY= | |
AWS_DEFAULT_REGION=us-east-1 | |
AWS_BUCKET= | |
PUSHER_APP_ID= | |
PUSHER_APP_KEY= | |
PUSHER_APP_SECRET= | |
PUSHER_APP_CLUSTER=mt1 | |
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | |
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /laravel-project/docker-compose.yml | |
# For more information: https://laravel.com/docs/sail | |
version: '3' | |
services: | |
laravel.test: | |
build: | |
context: ./docker/8.0-alpine | |
dockerfile: Dockerfile | |
args: | |
WWWGROUP: '${WWWGROUP}' | |
image: sail-8.0-alpine | |
ports: | |
- '${APP_PORT:-8000}:80' | |
environment: | |
WWWUSER: '${WWWUSER}' | |
LARAVEL_SAIL: 1 | |
volumes: | |
- '.:/var/www/html' | |
networks: | |
- sail | |
depends_on: | |
- pgsql | |
- redis | |
pgsql: | |
image: postgres:13 | |
ports: | |
- '${FORWARD_DB_PORT:-5432}:5432' | |
environment: | |
PGPASSWORD: '${DB_PASSWORD:-secret}' | |
POSTGRES_DB: '${DB_DATABASE}' | |
POSTGRES_USER: '${DB_USERNAME}' | |
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}' | |
volumes: | |
- 'sailpgsql:/var/lib/postgresql/data' | |
networks: | |
- sail | |
healthcheck: | |
test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"] | |
redis: | |
image: 'redis:alpine' | |
ports: | |
- '${FORWARD_REDIS_PORT:-6379}:6379' | |
volumes: | |
- 'sailredis:/data' | |
networks: | |
- sail | |
healthcheck: | |
test: ["CMD", "redis-cli", "ping"] | |
mailhog: | |
image: 'mailhog/mailhog:latest' | |
ports: | |
- '${FORWARD_MAILHOG_PORT:-1025}:1025' | |
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025' | |
networks: | |
- sail | |
networks: | |
sail: | |
driver: bridge | |
volumes: | |
sailpgsql: | |
driver: local | |
sailredis: | |
driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /laravel-project/docker/8.0-alpine/Dockerfile | |
FROM alpine:edge | |
WORKDIR /var/www/html | |
# Set environment variables | |
ENV WWWUSER=sail \ | |
WWWGROUP=sail | |
# Install basic packages | |
RUN apk update \ | |
&& apk --no-cache add \ | |
py3-setuptools \ | |
supervisor | |
# https://wiki.alpinelinux.org/wiki/Setting_the_timezone | |
RUN apk --no-cache add tzdata \ | |
&& cp /usr/share/zoneinfo/Asia/Jakarta /etc/localtime \ | |
&& echo "Asia/Jakarta" > /etc/timezone \ | |
&& echo date | |
# Install and configure bash | |
RUN apk --no-cache add bash \ | |
&& sed -i 's/bin\/ash/bin\/bash/g' /etc/passwd | |
# Install and configure PHP | |
RUN apk --no-cache add \ | |
php8 \ | |
php8-common \ | |
php8-fpm \ | |
php8-pdo \ | |
php8-opcache \ | |
php8-zip \ | |
php8-phar \ | |
php8-iconv \ | |
php8-cli \ | |
php8-curl \ | |
php8-openssl \ | |
php8-mbstring \ | |
php8-tokenizer \ | |
php8-fileinfo \ | |
php8-json \ | |
php8-xml \ | |
php8-xmlwriter \ | |
php8-simplexml \ | |
php8-dom \ | |
php8-pdo_sqlite \ | |
php8-pdo_pgsql \ | |
php8-pgsql \ | |
php8-tokenizer \ | |
php8-pecl-redis \ | |
php8-ctype \ | |
php8-gd \ | |
php8-xmlreader \ | |
&& ln -s /usr/bin/php8 /usr/bin/php | |
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini | |
# Configure supervisord | |
RUN touch /var/run/supervisord.pid \ | |
&& mkdir -p /etc/supervisor.d/conf.d \ | |
&& mkdir -p /var/log/supervisor \ | |
&& touch /var/log/supervisor/supervisord.log | |
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf | |
# Configure container startup script | |
COPY start-container /usr/local/bin/start-container | |
RUN chmod +x /usr/local/bin/start-container | |
# Configure user for sail | |
RUN addgroup sail \ | |
&& adduser -h /var/www/html -s /bin/bash -G sail -D sail | |
EXPOSE 80 | |
ENTRYPOINT ["start-container"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; file: /laravel-project/docker/8.0-alpine/php.ini | |
[PHP] | |
post_max_size = 100M | |
upload_max_filesize = 100M | |
variables_order = EGPCS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /laravel-project/docker/8.0-alpine/start-container | |
#!/usr/bin/env bash | |
if [ ! -z "$WWWUSER" ]; then | |
usermod -u $WWWUSER sail | |
fi | |
if [ ! -d /.composer ]; then | |
mkdir /.composer | |
fi | |
chmod -R ugo+rw /.composer | |
if [ $# -gt 0 ];then | |
exec gosu $WWWUSER "$@" | |
else | |
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /laravel-project/docker/8.0-alpine/supervisord.conf | |
[supervisord] | |
nodaemon=true | |
user=root | |
logfile=/var/log/supervisor/supervisord.log | |
pidfile=/var/run/supervisord.pid | |
[program:php] | |
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80 | |
user=sail | |
environment=LARAVEL_SAIL="1" | |
stdout_logfile=/dev/stdout | |
stdout_logfile_maxbytes=0 | |
stderr_logfile=/dev/stderr | |
stderr_logfile_maxbytes=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Those above configs use:
Laravel app are available in http://localhost:8000