Skip to content

Instantly share code, notes, and snippets.

@spoonerWeb
Last active October 1, 2024 08:23
Show Gist options
  • Save spoonerWeb/0461740e9b8cef9943acce7c652a633f to your computer and use it in GitHub Desktop.
Save spoonerWeb/0461740e9b8cef9943acce7c652a633f to your computer and use it in GitHub Desktop.
GitLab CI for building and deploying TYPO3 websites with deployer
cache:
paths:
- /cache/composer
stages:
- composer
- deploy
build:
stage: composer
image: composer:1
before_script:
- composer config cache-dir /cache/composer
script:
- composer install --no-dev
artifacts:
paths:
- ./
.deploy: &deploy_template
variables:
GIT_STRATEGY: none
stage: deploy
image: composer:1
dependencies:
- build
before_script:
- apk add rsync --update
- mkdir -p /root/.ssh/
- eval $(ssh-agent -s)
- composer config cache-dir /cache/composer
- mkdir -p ~/.ssh
- echo "$STAGE_PRIVATE_KEY" | ssh-add -
- echo "$PRODUCTION_PRIVATE_KEY" | ssh-add -
- composer global require deployer/deployer
- composer global require deployer/recipes
deploy_develop:
<<: *deploy_template
environment:
name: Stage System
url: https://your.stage-server.org
script:
- ssh-keyscan your.stage-server.org >> /root/.ssh/known_hosts
- /tmp/vendor/bin/dep --file=./.deployer/deploy.php deploy your.stage-server.org
only:
- develop
deploy_master:
<<: *deploy_template
environment:
name: Production System
url: https://your.production-server.org
script:
- ssh-keyscan your.production-server.org >> /root/.ssh/known_hosts
- /tmp/vendor/bin/dep --file=./.deployer/deploy.php deploy your.production-server.org
only:
- master
<?php
namespace Deployer;
require_once '/tmp/vendor/deployer/deployer/recipe/common.php';
require_once '/tmp/vendor/deployer/recipes/recipe/rsync.php';
$sharedDirectories = [
'public/fileadmin',
'public/uploads',
'public/.well-known'
];
set('shared_dirs', $sharedDirectories);
$sharedFiles = [
'private/typo3conf/AdditionalConfiguration.php'
];
set('shared_files', $sharedFiles);
$writeableDirectories = [
'public/typo3temp/assets',
'public/fileadmin',
'public/uploads'
];
set('writable_dirs', $writeableDirectories);
$exclude = [
'.gitignore',
'.htaccess',
'.git',
'Readme.rst',
'Readme.txt',
'Upgrading.rst',
'Upgrading.txt',
'README',
'*.example',
'AdditionalConfiguration.ddev.php'
];
set('rsync', [
'exclude' => array_merge($sharedDirectories, $sharedFiles, $exclude),
'exclude-file' => false,
'include' => [],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'avz',
'options' => ['delete'],
'timeout' => 300
]);
set('rsync_src', './');
set('keep_releases', 5);
set('typo3_console', 'vendor/bin/typo3cms');
inventory('.deployer/hosts.yml');
task('typo3', function () {
run('cd {{release_path}} && {{typo3_console}} install:generatepackagestates');
run('cd {{release_path}} && {{typo3_console}} install:extensionsetupifpossible');
});
task('deploy', [
'deploy:prepare',
'deploy:release',
'rsync:warmup',
'rsync',
'deploy:shared',
'deploy:writable',
'typo3',
'deploy:symlink',
'cleanup',
]);
your.stage-server.org:
stage: develop
user: username
deploy_path: ~/your/path
identity_file: ~/.ssh/id_rsa
forward_agent: true
your.production-server.org:
stage: master
user: username
deploy_path: ~/your/path
identity_file: ~/.ssh/id_rsa
forward_agent: true

#Requirements

  • TYPO3 website project built with composer, using packages
  • AdditionalConfiguration.php is used for adjustments on the target machine
  • Variables $STAGE_PRIVATE_KEY and $PRODUCTION_PRIVATE_KEY are the generated private keys which are handled in GitLab variables, the public keys must be on the target servers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment