Skip to content

Commit

Permalink
Add IONOS Deploy Now workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ionos-deploy-now[bot] authored Dec 26, 2023
1 parent 2f3cdae commit 676147f
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .deploy-now/car_sales/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=env
APP_SECRET=570f5c470c29162d144ca6adca561839
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://$IONOS_DB_USERNAME:${IONOS_DB_PASSWORD.urlEncoded()}@$IONOS_DB_HOST:3306/$IONOS_DB_NAME?serverVersion=mariadb-10.5&charset=utf8mb4"
#DATABASE_URL="mysql://root:root@localhost:8889/car_sales?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
#DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=15&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###< symfony/messenger ###

###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###

###> symfony/mailgun-mailer ###
#MAILER_DSN=mailgun+smtp://mailgun://KEY:DOMAIN@default?region=us
MAILER_DSN="smtp://$IONOS_MAIL_USERNAME:${IONOS_MAIL_PASSWORD.urlEncoded()}@$IONOS_MAIL_HOST:$IONOS_MAIL_PORT"
###< symfony/mailgun-mailer ###

#> symfony/google-mailer
#Gmail SHOULD NOT be used on production, use it in development only.
#MAILER_DSN=gmail://queenshopbiz@gmail.com:jvdesbqhbplcizjl@default
#<symfony/google-mailer
25 changes: 25 additions & 0 deletions .deploy-now/car_sales/.htaccess.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# enable gzip compressing for the following mime-types
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/shtml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

### IMPORTANT ###
### Because we can't change the webroot folder to a subfolder of the document root, we need this rewrite rules ###

RewriteEngine on

# serve existing files in the /public folder as if they were in /
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

# route everything else to /public/index.php
RewriteRule ^ /public/index.php [L]
51 changes: 51 additions & 0 deletions .deploy-now/car_sales/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 1.0

deploy:
# configuration part, which is taken at the FIRST deployment of each branch
bootstrap:
# folders that are not copied to IONOS webspace
excludes:
- tests
- node_modules
- DOCKER_ENV
- docker_tag
- output.log
# commands that are executed at the real webspace NOT at build servers AFTER copying new files
post-deployment-remote-commands:
- find $(pwd) -type f -not -path "$(pwd)/logs/*" -exec chmod 664 {} \;
- find $(pwd) -type d -not -name "logs" -exec chmod 775 {} \;
- chmod -R o+w var
- APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
- php bin/console doctrine:database:create
- php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
- php bin/console assets:install
- APP_ENV=prod APP_DEBUG=0 php bin/console cache:warmup

# configuration part, which is taken at ALL FURTHER deployments of this branch
recurring:
# folders that are not copied to IONOS webspace
excludes:
- tests
- node_modules
- DOCKER_ENV
- docker_tag
- output.log
- var
# commands that are executed at the real webspace NOT at build servers BEFORE copying new files
pre-deployment-remote-commands:
- echo "here you could enter maintenance mode..."
# commands that are executed at the real webspace NOT at build servers AFTER copying new files
post-deployment-remote-commands:
- find $(pwd) -type f -not -path "$(pwd)/logs/*" -exec chmod 664 {} \;
- find $(pwd) -type d -not -name "logs" -exec chmod 775 {} \;
- chmod -R o+w var
- APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
- php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
- php bin/console assets:install
- APP_ENV=prod APP_DEBUG=0 php bin/console cache:warmup

# uncomment the following lines to configure cron jobs
#runtime:
# cron-jobs:
# - command: my-cron-job-command # the deployment is located at $HOME/htdocs/ to execute a deployed script just prefix it accordingly
# schedule: 0 5 * * * # run every day at 5:00
77 changes: 77 additions & 0 deletions .github/workflows/car_sales-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# To better understand this file read this:
# https://docs.ionos.space/docs/github-actions-customization/

name: "Deploy Now: Execute Build"

on:
workflow_call:
inputs:
site-url:
required: true
type: string
branch-id:
required: true
type: string

env:
DEPLOYMENT_FOLDER: ./

jobs:
# Please do not rename this job
build-project:
name: build car_sales
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# if you add permissions here this needs to be done in the car_sales-orchestration.yaml as well
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Render templates
uses: ionos-deploy-now/template-renderer-action@v2
id: template
with:
input-directory: .deploy-now/car_sales
output-directory: ${{ env.DEPLOYMENT_FOLDER }}
intermediate-data-file: ${{ env.DEPLOYMENT_FOLDER }}/.template-renderer-data

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: v16.x

- name: Build Node assets
env:
CI: true
SITE_URL: ${{ inputs.site-url }}
run: |
npm ci
npm run build
- name: Setup composer
uses: php-actions/composer@v6
# uncomment the following lines if you want to add environment variables for this step
# env:
# MY_ENV_VAR: value-for-my-env-var
# MY_SECRET_ENV_VAR: ${{ secrets.MY_SECRET }} # here you can find information how to create secrets: https://docs.github.com/en/actions/security-guides/encrypted-secrets
with:
php_version: '8.2.5'
version: '2.5.8'
args: --optimize-autoloader --no-dev

# Please do not touch the following action
- name: Store deployment content
uses: ionos-deploy-now/artifact-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-eu.ionos.space
project-id: e4b7f2a3-1084-4dd4-bb02-3018d29c7042
branch-id: ${{ inputs.branch-id }}
version: ${{ github.sha }}
folder: ${{ env.DEPLOYMENT_FOLDER }}
config-file: .deploy-now/car_sales/config.yaml
action: upload
58 changes: 58 additions & 0 deletions .github/workflows/car_sales-orchestration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Please do not edit this file.
# Build steps can be customized in the car_sales-build.yaml.
# More information under https://docs.ionos.space/docs/github-actions-customization/
# version: 2022-07-21

name: "Deploy Now: Orchestration"
run-name: "Deploy Now: Build car_sales · ${{ github.event.head_commit.message || format('Triggered by {0}', github.triggering_actor) }}"

on:
- push
- workflow_dispatch

jobs:
retrieve-project:
name: check readiness
runs-on: ubuntu-latest
outputs:
deployment-enabled: ${{ fromJson(steps.project.outputs.info).deployment-enabled }}
branch-id: ${{ fromJson(steps.project.outputs.info).branch-id }}
steps:
- name: Fetch project data
uses: ionos-deploy-now/project-action@v1
id: project
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-eu.ionos.space
project-id: e4b7f2a3-1084-4dd4-bb02-3018d29c7042
action: retrieve-info


build:
name: build
needs: retrieve-project
permissions:
contents: read
packages: write
if: ${{ needs.retrieve-project.outputs.deployment-enabled == 'true' }}
uses: ./.github/workflows/car_sales-build.yaml
with:
site-url: https://IONOS_DEPLOY_NOW_SITE_URL
branch-id: ${{ needs.retrieve-project.outputs.branch-id }}
secrets: inherit

deploy:
name: trigger deployment
needs:
- retrieve-project
- build
runs-on: ubuntu-latest
steps:
- name: Dispatch deployment(s)
uses: ionos-deploy-now/project-action@v1
with:
api-key: ${{ secrets.IONOS_API_KEY }}
service-host: api-eu.ionos.space
project-id: e4b7f2a3-1084-4dd4-bb02-3018d29c7042
branch-id: ${{ needs.retrieve-project.outputs.branch-id }}
action: dispatch-deployments

0 comments on commit 676147f

Please sign in to comment.