Skip to content

Commit

Permalink
Setup for Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
rubuy-74 committed Oct 9, 2024
1 parent 8c2504f commit 351a791
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bootstrap/cache/services.php
bootstrap/cache/*

storage/app/*
storage/framework/cache/*
Expand Down
35 changes: 0 additions & 35 deletions .env

This file was deleted.

79 changes: 28 additions & 51 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,58 +1,35 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_NAME=SINF
APP_ENV=local # Use "maintenance" to enable the maitenance page
APP_KEY=base64:AVegBkyjHs2QQsx53M9Kt9GbnrDLc6yG4cRg+WMJrbA=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://localhost:8000
APP_PORT=8000

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
LOCALE=pt
FAKER_LOCALE=pt_PT

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
DB_HOST=pgsql
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=sinf-website-2023
DB_CONNECTION=pgsql

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120
MAIL_HOST=mailpit
MAIL_PORT=1025

MEMCACHED_HOST=127.0.0.1
REDIS_HOST=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAINTENANCE_DRIVER=cache

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
CACHE_DRIVER=redis

QUEUE_CONNECTION=redis

SCOUT_QUEUE=true
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700

MEILISEARCH_NO_ANALYTICS=false

LOG_CHANNEL="sinfWebsite"
1 change: 1 addition & 0 deletions .env.production.encrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJpdiI6ImJUWUIwOUZHUkxpSHVvR3ZEQXFWd1E9PSIsInZhbHVlIjoiWkpwd0ZlUFRueXl5Rjg5TjdFTTF5dz09IiwibWFjIjoiYzIwYTdjNThmOTEwYmU4YWM0ZmUwMzRkZTNhZDMzY2E1NDFkODEzOWQ4NjRiYTdlOGQ5YTUzNTlhMmFjMGQ2MyIsInRhZyI6IiJ9
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/public/storage
/storage/*.key
/vendor
.env.backup
.env.prod
.env*
!.env*.example
!.env*.encrypted
.phpunit.result.cache
Homestead.json
Homestead.yaml
Expand Down
76 changes: 0 additions & 76 deletions Dockerfile

This file was deleted.

17 changes: 11 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ services:
prod:
build:
context: .
dockerfile: Dockerfile
target: production
dockerfile: ./dockerfiles/Dockerfile.website
target: deploy-nocache
args:
- LARAVEL_ENV=${APP_ENV:-local}
- LARAVEL_ENV_FILE=.env
ports:
- '80:80'
networks:
Expand All @@ -40,15 +43,17 @@ services:
- pgsql
- redis
- meilisearch
environment:
- APP_URL=http://localhost
pgsql:
image: 'postgres:15'
image: 'postgres:16'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
PGPASSWORD: '${DB_PASSWORD}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_PASSWORD: '${DB_PASSWORD}'
volumes:
- 'sail-pgsql:/var/lib/postgresql/data'
- './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
Expand Down Expand Up @@ -115,4 +120,4 @@ volumes:
sail-redis:
driver: local
sail-meilisearch:
driver: local
driver: local
35 changes: 35 additions & 0 deletions dockerfiles/Dockerfile.seeder
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# dependencies
FROM composer:2 AS dependencies
WORKDIR /app

COPY composer.json composer.lock artisan ./
COPY app/ ./app/
COPY bootstrap/ ./bootstrap/
COPY config/ ./config/
COPY database/ ./database/
COPY resources/ ./resources/
COPY routes/ ./routes/

RUN composer install --no-interaction

# migrate
FROM composer:2 AS migrate
WORKDIR /app

RUN install-php-extensions pdo_pgsql pgsql redis iconv zip

COPY --from=dependencies /app ./

ARG LARAVEL_ENV=production
ARG LARAVEL_ENV_FILE=.env.${LARAVEL_ENV}
ARG LARAVEL_ENV_FILE_KEY=""

ENV APP_ENV=${LARAVEL_ENV}

COPY --chown=nobody ${LARAVEL_ENV_FILE} ./.env.${LARAVEL_ENV}
RUN [ -z "${LARAVEL_ENV_FILE_KEY}" ] || ( mv .env.${LARAVEL_ENV} .env.${LARAVEL_ENV}.encrypted && php artisan env:decrypt -n --env=${LARAVEL_ENV} --key=${LARAVEL_ENV_FILE_KEY} )

COPY public/ ./public/
COPY storage/ ./storage/

CMD [ "php", "artisan", "migrate", "-n", "--seed"]
87 changes: 87 additions & 0 deletions dockerfiles/Dockerfile.website
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# dev-dependencies
FROM composer:2 AS dev-dependencies
WORKDIR /app

COPY composer.json composer.lock ./
RUN composer install --no-interaction --no-autoloader

# assets-build
FROM node:20-alpine AS assets-build
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm install

COPY ./resources/ ./resources
COPY ./vite.config.ts ./tsconfig.json ./tsconfig.app.json ./tsconfig.node.json ./tailwind.config.js ./postcss.config.js ./
COPY --from=dev-dependencies /app/vendor ./vendor

RUN npm run build

# laravel-build
FROM composer:2 AS laravel-build
WORKDIR /app

COPY composer.json composer.lock artisan ./
COPY app/ ./app/
COPY bootstrap/ ./bootstrap/
COPY config/ ./config/
COPY database/ ./database/
COPY resources/ ./resources/
COPY routes/ ./routes/

RUN composer install --no-interaction --optimize-autoloader --no-dev --prefer-dist

# deploy-nocache
FROM trafex/php-nginx:3.6.0 AS deploy-nocache
WORKDIR /var/www/html

USER root
RUN apk add --no-cache php83-pdo_pgsql php83-pgsql php83-pecl-redis php83-iconv php83-zip

## Install supercronic (cron alternative)
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.26/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
SUPERCRONIC_SHA1SUM=7a79496cf8ad899b99a719355d4db27422396735

RUN curl -fsSLO "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

COPY ./etc/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY ./etc/php/php.ini ${PHP_INI_DIR}/conf.d/php.ini
COPY --chown=nobody ./etc/crontab ./crontab
COPY --chown=nobody ./etc/supervisord.conf ./supervisord.conf
RUN cat ./supervisord.conf >> /etc/supervisor/conf.d/supervisord.conf
RUN rm ./supervisord.conf

USER nobody

ARG LARAVEL_ENV=production
ARG LARAVEL_ENV_FILE=.env.${LARAVEL_ENV}
ARG LARAVEL_ENV_FILE_KEY=""

COPY --chown=nobody ${LARAVEL_ENV_FILE} ./.env.${LARAVEL_ENV}
COPY --chown=nobody public/ ./public/
COPY --chown=nobody storage/ ./storage/
COPY --chown=nobody --from=laravel-build /app/ ./
COPY --chown=nobody --from=assets-build /app/public/ ./public/

ENV APP_ENV=${LARAVEL_ENV}

RUN [ -z "${LARAVEL_ENV_FILE_KEY}" ] || ( mv .env.${LARAVEL_ENV} .env.${LARAVEL_ENV}.encrypted && php artisan env:decrypt -n --env=${LARAVEL_ENV} --key=${LARAVEL_ENV_FILE_KEY} )

COPY --chown=nobody ./etc/entrypoint.nocache.sh /entrypoint.sh
CMD [ "/entrypoint.sh" ]

# deploy
FROM deploy-nocache AS deploy

RUN php artisan storage:link -n
RUN php artisan event:cache -n
RUN php artisan route:cache -n
RUN php artisan view:cache -n

COPY --chown=nobody ./etc/entrypoint.sh /entrypoint.sh
5 changes: 5 additions & 0 deletions etc/entrypoint.nocache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
Loading

0 comments on commit 351a791

Please sign in to comment.