Skip to content

Commit

Permalink
#172 - app deployment details (#278)
Browse files Browse the repository at this point in the history
* Add deployment details, improve environment

* node linter fixes

* formatting

* fix deploy-to-beta-manually.yml workflow
  • Loading branch information
mtracz authored Dec 14, 2022
1 parent 3786847 commit 3cdb394
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 231 deletions.
54 changes: 0 additions & 54 deletions .env.beta.example

This file was deleted.

6 changes: 0 additions & 6 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ SESSION_DRIVER=array
SESSION_LIFETIME=120
FILESYSTEM_DISK=local
MAIL_MAILER=array

HEROKU_RELEASE_VERSION=v01
HEROKU_SLUG_DESCRIPTION="Dev 643f546"
HEROKU_RELEASE_CREATED_AT=2022-07-04T18:05:46Z
HEROKU_SLUG_COMMIT=643f546142b8a2db342f0ae46f01e61dce03e97c
GITHUB_REPO_URL=https://github.com/blumilksoftware/toby/
6 changes: 0 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,3 @@ SLACK_ENABLED=true
SLACK_CLIENT_TOKEN=
SLACK_SIGNING_SECRET=
SLACK_DEFAULT_CHANNEL="#general"

HEROKU_RELEASE_VERSION=v01
HEROKU_SLUG_DESCRIPTION="Dev 643f546"
HEROKU_RELEASE_CREATED_AT=2022-07-04T18:05:46Z
HEROKU_SLUG_COMMIT=643f546142b8a2db342f0ae46f01e61dce03e97c
GITHUB_REPO_URL=https://github.com/blumilksoftware/toby/
5 changes: 3 additions & 2 deletions .github/workflows/deploy-to-beta-manually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ jobs:
environment: beta
name: Deploy to beta
runs-on: ubuntu-22.04
env:
BRANCH_NAME: $GITHUB_REF_NAME
steps:
- name: set branch name
run: echo "BRANCH_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV

- name: run deployment script over ssh
uses: appleboy/ssh-action@v0.1.5
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ yarn-error.log
google-credentials.json
.idea/
.composer
.deployment
42 changes: 34 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
DOCKER_COMPOSE_BETA_FILENAME=docker-compose.beta.yml
BETA_DOCKER_EXEC=docker compose --file ${DOCKER_COMPOSE_BETA_FILENAME} exec --workdir /application/environment/scripts
DOCKER_COMPOSE_BETA_FILENAME = docker-compose.beta.yml
BETA_DOCKER_EXEC = docker compose --file ${DOCKER_COMPOSE_BETA_FILENAME} exec --workdir /application/environment/scripts

DOCKER_COMPOSE_PROD_FILENAME=docker-compose.prod.yml
PROD_DOCKER_EXEC=docker compose --file ${DOCKER_COMPOSE_PROD_FILENAME} exec --workdir /application/environment/scripts
DOCKER_COMPOSE_PROD_FILENAME = docker-compose.prod.yml
PROD_DOCKER_EXEC = docker compose --file ${DOCKER_COMPOSE_PROD_FILENAME} exec --workdir /application/environment/scripts

export COMPOSE_DOCKER_CLI_BUILD = 1
export DOCKER_BUILDKIT = 1

.PHONY: beta-deploy
beta-deploy:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose --file ${DOCKER_COMPOSE_BETA_FILENAME} build --pull && \
beta-deploy: create-deployment-file
docker compose --file ${DOCKER_COMPOSE_BETA_FILENAME} build --pull && \
docker compose --file ${DOCKER_COMPOSE_BETA_FILENAME} up --detach && \
echo "App post deploy actions" && \
${BETA_DOCKER_EXEC} toby-beta-php bash post-deploy-actions.sh && \
echo "Worker post deploy actions" && \
${BETA_DOCKER_EXEC} toby-beta-worker bash post-deploy-actions.sh && \
echo "Scheduler post deploy actions" && \
${BETA_DOCKER_EXEC} toby-beta-scheduler bash post-deploy-actions.sh

.PHONY: beta-reload-config
beta-reload-config:
echo "App config reload" && \
${BETA_DOCKER_EXEC} toby-beta-php bash reload-config.sh && \
echo "Worker config reload" && \
${BETA_DOCKER_EXEC} toby-beta-worker bash reload-config.sh && \
echo "Scheduler config reload" && \
${BETA_DOCKER_EXEC} toby-beta-scheduler bash reload-config.sh

.PHONY: prod-deploy
prod-deploy:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose --file ${DOCKER_COMPOSE_PROD_FILENAME} build --pull && \
prod-deploy: create-deployment-file
docker compose --file ${DOCKER_COMPOSE_PROD_FILENAME} build --pull && \
docker compose --file ${DOCKER_COMPOSE_PROD_FILENAME} up --detach && \
echo "App post deploy actions" && \
${PROD_DOCKER_EXEC} toby-prod-php bash post-deploy-actions.sh && \
echo "Worker post deploy actions" && \
${PROD_DOCKER_EXEC} toby-prod-worker bash post-deploy-actions.sh && \
echo "Scheduler post deploy actions" && \
${PROD_DOCKER_EXEC} toby-prod-scheduler bash post-deploy-actions.sh

.PHONY: prod-reload-config
prod-reload-config:
echo "App config reload" && \
${PROD_DOCKER_EXEC} toby-prod-php bash reload-config.sh && \
echo "Worker config reload" && \
${PROD_DOCKER_EXEC} toby-prod-worker bash reload-config.sh && \
echo "Scheduler config reload" && \
${PROD_DOCKER_EXEC} toby-prod-scheduler bash reload-config.sh


DEPLOYMENT_PROJECT_VERSION = $(shell ./environment/scripts/version.sh --long)
DEPLOYMENT_DATETIME = $(shell date --rfc-3339=seconds)

.PHONY: create-deployment-file
create-deployment-file:
@echo "\
DEPLOY_DATE='${DEPLOYMENT_DATETIME}'\n\
DEPLOY_VERSION='${DEPLOYMENT_PROJECT_VERSION}'\
" > .deployment
7 changes: 2 additions & 5 deletions app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ protected function getVacationRequestsCount(Request $request): Closure
protected function getDeployInformation(): Closure
{
return fn(): array => [
"release_version" => config("heroku.release_version"),
"slug_description" => config("heroku.slug_description"),
"release_created_at" => config("heroku.release_created_at"),
"slug_commit" => config("heroku.slug_commit"),
"github_url" => config("heroku.github_url", ""),
"version" => config("deploy.version"),
"date" => config("deploy.date"),
];
}
}
8 changes: 8 additions & 0 deletions config/deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

return [
"version" => env("DEPLOY_VERSION", default: "---"),
"date" => env("DEPLOY_DATE", default: "---"),
];
11 changes: 0 additions & 11 deletions config/heroku.php

This file was deleted.

26 changes: 14 additions & 12 deletions docker-compose.beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ volumes:
name: toby-beta-pgsql-data
toby-beta-redis-data:
name: toby-beta-redis-data
toby-beta-static-assets:
name: toby-beta-static-assets

# extension fields
x-toby-app-shared: &app
image: toby-beta-app:latest
container_name: toby-beta-php
working_dir: /application
volumes:
- toby-beta-static-assets:/application/public
- ./environment/prod/php/php.ini:/usr/local/etc/php/conf.d/99-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/php/php.ini:/usr/local/etc/php/conf.d/99-toby-php.ini:ro
- ./.env:/application/.env:ro
networks:
- toby-beta
restart: unless-stopped
env_file:
- .deployment

services:
toby-beta-web:
image: nginx:1.23-alpine
build:
context: .
dockerfile: environment/prod/nginx/Dockerfile
target: webserver
image: toby-beta-web:latest
container_name: toby-beta-web
volumes:
- toby-beta-static-assets:/application/public
- ./environment/prod/nginx/templates:/etc/nginx/templates/
- ./environment/prod/nginx/templates:/etc/nginx/templates/:ro
environment:
- SERVER_NAME=toby-beta-nginx
- FASTCGI_PASS_NAME=toby-beta-php
Expand Down Expand Up @@ -63,17 +65,17 @@ services:
<<: *app
container_name: toby-beta-worker
volumes:
- ./environment/prod/worker/php.ini:/usr/local/etc/php/conf.d/99-worker-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/worker/php.ini:/usr/local/etc/php/conf.d/99-worker-toby-php.ini:ro
- ./.env:/application/.env:ro
user: root
entrypoint: [ "./environment/prod/worker/entrypoint.sh" ]

toby-beta-scheduler:
<<: *app
container_name: toby-beta-scheduler
volumes:
- ./environment/prod/scheduler/php.ini:/usr/local/etc/php/conf.d/99-scheduler-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/scheduler/php.ini:/usr/local/etc/php/conf.d/99-scheduler-toby-php.ini:ro
- ./.env:/application/.env:ro
user: root
entrypoint: [ "./environment/prod/scheduler/entrypoint.sh" ]

Expand Down
26 changes: 14 additions & 12 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ volumes:
name: toby-prod-pgsql-data
toby-prod-redis-data:
name: toby-prod-redis-data
toby-prod-static-assets:
name: toby-prod-static-assets
duplicati-source:
name: duplicati-source
external: true
Expand All @@ -24,20 +22,24 @@ x-toby-app-shared: &app
working_dir: /application
volumes:
- duplicati-source:/backup
- toby-prod-static-assets:/application/public
- ./environment/prod/php/php.ini:/usr/local/etc/php/conf.d/99-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/php/php.ini:/usr/local/etc/php/conf.d/99-toby-php.ini:ro
- ./.env:/application/.env:ro
networks:
- toby-prod
restart: unless-stopped
env_file:
- .deployment

services:
toby-prod-web:
image: nginx:1.23-alpine
build:
context: .
dockerfile: environment/prod/nginx/Dockerfile
target: webserver
image: toby-prod-web:latest
container_name: toby-prod-web
volumes:
- toby-prod-static-assets:/application/public
- ./environment/prod/nginx/templates:/etc/nginx/templates/
- ./environment/prod/nginx/templates:/etc/nginx/templates/:ro
environment:
- SERVER_NAME=toby-prod-nginx
- FASTCGI_PASS_NAME=toby-prod-php
Expand Down Expand Up @@ -67,8 +69,8 @@ services:
<<: *app
container_name: toby-prod-worker
volumes:
- ./environment/prod/worker/php.ini:/usr/local/etc/php/conf.d/99-worker-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/worker/php.ini:/usr/local/etc/php/conf.d/99-worker-toby-php.ini:ro
- ./.env:/application/.env:ro
user: root
entrypoint: [ "./environment/prod/worker/entrypoint.sh" ]

Expand All @@ -77,8 +79,8 @@ services:
container_name: toby-prod-scheduler
volumes:
- duplicati-source:/backup
- ./environment/prod/scheduler/php.ini:/usr/local/etc/php/conf.d/99-scheduler-toby-php.ini
- ./.env:/application/.env
- ./environment/prod/scheduler/php.ini:/usr/local/etc/php/conf.d/99-scheduler-toby-php.ini:ro
- ./.env:/application/.env:ro
user: root
entrypoint: [ "./environment/prod/scheduler/entrypoint.sh" ]

Expand Down
2 changes: 1 addition & 1 deletion environment/dev/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=8.1.12-fpm
ARG PHP_VERSION=8.1.13-fpm
ARG COMPOSER_VERSION=2.4

FROM composer:${COMPOSER_VERSION} as composer
Expand Down
25 changes: 25 additions & 0 deletions environment/prod/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG NGINX_VERSION=1.23-alpine
ARG NODE_VERSION=19-alpine3.16

### FRONTEND ###
FROM node:${NODE_VERSION} as frontend

WORKDIR /app_frontend_dependencies

COPY package.json package-lock.json postcss.config.js tailwind.config.js vite.config.js webpack.config.js webpack.mix.js ./

RUN npm clean-install

COPY resources/js ./resources/js/
COPY resources/css ./resources/css/

RUN npm run build

### WEB SERVER ###
FROM nginx:${NGINX_VERSION} as webserver

WORKDIR /application

COPY --from=frontend /app_frontend_dependencies/public/build ./public/build/
COPY /public/favicon.ico /public/robots.txt /public/index.php ./public/
COPY /public/img ./public/img/
12 changes: 6 additions & 6 deletions environment/prod/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG PHP_VERSION=8.1.12-fpm
ARG NODE_VERSION=19-alpine3.15
ARG PHP_VERSION=8.1.13-fpm
ARG NODE_VERSION=19-alpine3.16
ARG COMPOSER_VERSION=2.4

### PHP DEPENDENCIES ###
Expand All @@ -24,7 +24,7 @@ WORKDIR /app_frontend_dependencies

COPY package.json package-lock.json postcss.config.js tailwind.config.js vite.config.js webpack.config.js webpack.mix.js ./

RUN npm install clean-install
RUN npm clean-install

COPY resources/js ./resources/js/
COPY resources/css ./resources/css/
Expand Down Expand Up @@ -69,11 +69,11 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmour --o
&& apt-get install --assume-yes postgresql-client-${POSTGRESQL_CLIENT_VERSION}

# Copy Frontend build
COPY --from=frontend /app_frontend_dependencies/node_modules ./node_modules/
COPY --from=frontend /app_frontend_dependencies/public/build ./public/build/
COPY --chown=www-data:www-data --from=frontend /app_frontend_dependencies/node_modules ./node_modules/
COPY --chown=www-data:www-data --from=frontend /app_frontend_dependencies/public/build ./public/build/

# Copy Composer dependencies
COPY --from=vendor /app_composer_dependencies/vendor ./vendor/
COPY --chown=www-data:www-data --from=vendor /app_composer_dependencies/vendor ./vendor/

# Copy App files
COPY --chown=www-data:www-data . .
Expand Down
Loading

0 comments on commit 3cdb394

Please sign in to comment.