From 6ad3f92a1adc8782ff9a588c8b73fb7aedfb7803 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Mon, 2 Dec 2024 12:55:09 +0100 Subject: [PATCH] feat: renaming, add pipeline --- .ddev/config.yaml | 2 +- .gitea/workflows/build.yaml | 37 +++++++++ .gitea/workflows/deploy.yaml | 120 +++++++++++++++++++++++++++++ .gitea/workflows/release.yaml | 41 ++++++++++ build/deploy.php | 140 ++++++++++++++++++++++++++++++++++ build/servers.yaml | 17 +++++ 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build.yaml create mode 100644 .gitea/workflows/deploy.yaml create mode 100644 .gitea/workflows/release.yaml create mode 100644 build/deploy.php create mode 100644 build/servers.yaml diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 3badc08..070b7f3 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -1,4 +1,4 @@ -name: typo3-basic +name: lena-schilling type: typo3 docroot: public php_version: "8.3" diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..4babc7c --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,37 @@ +name: Build + +on: + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +env: + PHP_VERSION: '8.3' # set this to the PHP version to use + COMPOSER_ALLOW_SUPERUSER: 1 + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + with: + php-version: ${{ env.PHP_VERSION }} + + - name: Check if composer.json exists + id: check_files + uses: andstor/file-existence-action@87d74d4732ddb824259d80c8a508c0124bf1c673 + with: + files: 'composer.json' + + - name: Run composer install if composer.json exists + if: steps.check_files.outputs.files_exists == 'true' + run: | + rm composer.lock + composer validate --no-check-publish diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..67e4951 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,120 @@ +name: Build + +on: + push: + branches: [ 'main' ] + paths-ignore: + - '**.md' + - '.gitea/workflows/release.yml' + - 'renovate.json' + workflow_dispatch: + +env: + PHP_VERSION: '8.3' # set this to the PHP version to use + COMPOSER_ALLOW_SUPERUSER: 1 + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + with: + php-version: ${{ env.PHP_VERSION }} + + - name: Check if composer.json exists + id: check_files + uses: andstor/file-existence-action@87d74d4732ddb824259d80c8a508c0124bf1c673 + with: + files: 'composer.json' + + - name: Run composer install if composer.json exists + if: steps.check_files.outputs.files_exists == 'true' + run: | + composer validate --no-check-publish && composer install --prefer-dist --no-progress --ignore-platform-reqs + tar -czf typo3.tar.gz bin public packages config vendor build composer.json composer.lock + + - uses: actions/upload-artifact@v3 + with: + name: typo3 + path: typo3.tar.gz + + deploy-stage: + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + with: + php-version: ${{ env.PHP_VERSION }} + - uses: actions/download-artifact@v3 + with: + name: typo3 + - name: Extract artifact + run: | + tar xf typo3.tar.gz + rm typo3.tar.gz + - name: Install ssh agent and rsync + run: | + apt update + apt install -y openssh-client rsync + - name: Upload release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: --file=./build/deploy.php release:create stage + private-key: ${{secrets.STAGE_KEY}} + switch-stage: + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + with: + php-version: ${{ env.PHP_VERSION }} + - uses: actions/download-artifact@v3 + with: + name: typo3 + - name: Extract artifact + run: | + tar xf typo3.tar.gz + rm typo3.tar.gz + - name: Install ssh agent and rsync + run: | + apt update + apt install -y openssh-client rsync + - name: Switch to release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: --file=./build/deploy.php release:switch stage + private-key: ${{secrets.STAGE_KEY}} + + # deploy-production: + # runs-on: ubuntu-latest + # steps: + # - name: Setup PHP + # uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + # with: + # php-version: ${{ env.PHP_VERSION }} + # - uses: actions/download-artifact@v3 + # with: + # name: typo3 + # - name: Extract artifact + # run: | + # tar xf typo3.tar.gz + # rm typo3.tar.gz + # - name: Install ssh agent and rsync + # run: | + # apt update + # apt install -y openssh-client rsync + # - name: Deploy + # uses: deployphp/action@v1 + # with: + # deployer-binary: "./bin/dep" + # dep: --file=./build/deploy.php release:create production + # private-key: ${{secrets.PROD_KEY}} diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..ae7a70d --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,41 @@ +name: Release + +on: + release: + types: [published] + +env: + PHP_VERSION: '8.3' # set this to the PHP version to use + COMPOSER_ALLOW_SUPERUSER: 1 + +permissions: + contents: read + +jobs: + switch-production: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup PHP + uses: shivammathur/setup-php@7c0b4c8c8ebed23eca9ec2802474895d105b11bc + with: + php-version: ${{ env.PHP_VERSION }} + - name: Check if composer.json exists + id: check_files + uses: andstor/file-existence-action@87d74d4732ddb824259d80c8a508c0124bf1c673 + with: + files: 'composer.json' + - name: Run composer install if composer.json exists + if: steps.check_files.outputs.files_exists == 'true' + run: | + composer validate --no-check-publish && composer install --prefer-dist --no-progress --ignore-platform-reqs + - name: Install ssh agent, rsync + run: | + apt update + apt install -y openssh-client rsync + - name: Switch to release + uses: deployphp/action@v1 + with: + deployer-binary: "./bin/dep" + dep: --file=./build/deploy.php release:switch production + private-key: ${{secrets.PROD_KEY}} diff --git a/build/deploy.php b/build/deploy.php new file mode 100644 index 0000000..b364c55 --- /dev/null +++ b/build/deploy.php @@ -0,0 +1,140 @@ + array_merge($sharedDirectories, $sharedFiles, $exclude), + 'exclude-file' => false, + 'include' => [], + 'include-file' => false, + 'filter' => ['dir-merge,-n /.gitignore'], + 'filter-file' => false, + 'filter-perdir' => false, + 'flags' => 'avz', + 'options' => ['delete'], + 'timeout' => 300 +]); + +task('typo3:extension:setup', function () { + cd('{{release_path}}'); + run('{{bin/php}} bin/typo3 extension:setup'); +}); + +task('typo3:cache:flush', function() { + cd('current'); + run('{{bin/php}} bin/typo3 cache:flush'); +}); + +task('typo3:cache:warmup', function() { + cd('current'); + run('{{bin/php}} bin/typo3 cache:warmup'); +}); + +task('typo3:language:update', function() { + cd('current'); + run('{{bin/php}} bin/typo3 language:update'); +}); + +// needed for t3o infrastructure +task('php:reload', function() { + run('php-reload'); +})->select('stage=contentmaster'); + +task('php:reload-prod', function() { + run('php-reload'); +})->select('stage=production'); + +// Because we are using rsync, this task is disabled +// to avoid to trigger git +task('deploy:update_code')->hidden()->disable(); + +task('release:create', [ + 'deploy:prepare', + 'rsync', + 'deploy:vendors', + 'deploy:shared', + 'deploy:writable', + 'typo3:extension:setup', + 'deploy:unlock', + 'deploy:success' +]); + +task('release:switch', [ + 'deploy:symlink', + 'php:reload', + 'php:reload-prod', + 'typo3:cache:flush', + 'typo3:language:update', + 'typo3:cache:warmup', + 'deploy:unlock', + 'deploy:cleanup', + 'deploy:success' +]); + +task('deploy', [ + 'deploy:prepare', + 'rsync', + 'deploy:vendors', + 'deploy:shared', + 'deploy:writable', + 'typo3:extension:setup', + 'deploy:symlink', + 'php:reload', + 'php:reload-prod', + 'typo3:cache:flush', + 'typo3:language:update', + 'typo3:cache:warmup', + 'deploy:unlock', + 'deploy:cleanup', + 'deploy:success' +]); + +host('stage') + ->set('cachetool', '/var/run/phpfpm/gbv-aktuell.cloonar.dev.sock'); + +host('production') + ->set('cachetool', '/var/run/phpfpm/gbv-aktuell.at.sock'); + +after('deploy:symlink', 'cachetool:clear:opcache'); +// unlock after failure +after('deploy:failed', 'deploy:unlock'); diff --git a/build/servers.yaml b/build/servers.yaml new file mode 100644 index 0000000..b82b2ad --- /dev/null +++ b/build/servers.yaml @@ -0,0 +1,17 @@ +hosts: + production: + stage: production + hostname: web-arm.cloonar.com + remote_user: gbv_aktuell_at + writable_mode: chmod + forward_agent: true + deploy_path: ~/ + keep_releases: 5 + stage: + stage: staging + hostname: web-arm.cloonar.com + remote_user: lena_schilling_cloonar_dev + writable_mode: chmod + forward_agent: true + deploy_path: ~/ + keep_releases: 1