Skip to content
Snippets Groups Projects
Commit 9dda3e4a authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

CI: move deployment to a separate repo

parent 17c25465
No related branches found
No related tags found
No related merge requests found
Pipeline #189150 passed
...@@ -12,11 +12,6 @@ cache: ...@@ -12,11 +12,6 @@ cache:
paths: paths:
- _composer_cache - _composer_cache
stages:
- test
- deploy
- e2e
.test_defaults: &test_defaults .test_defaults: &test_defaults
script: script:
- sudo update-alternatives --set php "/usr/bin/${PHP}" - sudo update-alternatives --set php "/usr/bin/${PHP}"
...@@ -25,25 +20,21 @@ stages: ...@@ -25,25 +20,21 @@ stages:
- composer test - composer test
test-php7.3: test-php7.3:
stage: test
variables: variables:
PHP: "php7.3" PHP: "php7.3"
<<: *test_defaults <<: *test_defaults
test-php7.4: test-php7.4:
stage: test
variables: variables:
PHP: "php7.4" PHP: "php7.4"
<<: *test_defaults <<: *test_defaults
test-php8.0: test-php8.0:
stage: test
variables: variables:
PHP: "php8.0" PHP: "php8.0"
<<: *test_defaults <<: *test_defaults
linting: linting:
stage: test
allow_failure: true allow_failure: true
script: script:
- sudo update-alternatives --set php /usr/bin/php7.4 - sudo update-alternatives --set php /usr/bin/php7.4
...@@ -54,43 +45,19 @@ linting: ...@@ -54,43 +45,19 @@ linting:
- composer run psalm || result=1 - composer run psalm || result=1
- exit $result - exit $result
.deploy_defaults: &deploy_defaults deploy:
needs: ["test-php7.3", "test-php7.4"] needs: ["test-php7.3", "test-php7.4"]
except: except:
- schedules - schedules
stage: deploy
script:
- sudo update-alternatives --set php /usr/bin/php7.3
# Add ssh key
- mkdir -p ~/.ssh
- echo "${DEPLOY_KEY}" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -t rsa "${DEPLOY_HOST}" >> ~/.ssh/known_hosts
# Deploy
- dep deploy --file ./.gitlab-ci/deploy.php "${CI_ENVIRONMENT_NAME}"
- echo "Deployed to ${CI_ENVIRONMENT_URL}"
# Simple health check
- curl --max-time 10 --retry 3 --output /dev/null --silent --show-error --fail --location "${CI_ENVIRONMENT_URL}"
deploy_development:
only:
refs:
- main
environment:
name: development
url: https://api-template-dev.tugraz.at/
variables:
DEPLOY_HOST: mw01-dev.tugraz.at
DEPLOY_KEY: "$DEPLOY_SSH_KEY"
<<: *deploy_defaults
e2e_tests:
only: only:
refs: refs:
- main - main
inherit:
variables: false
variables: variables:
E2E_PROJECT: rest UPSTREAM_PROJECT_PATH: ${CI_PROJECT_PATH}
stage: e2e UPSTREAM_COMMIT_BRANCH: ${CI_COMMIT_BRANCH}
UPSTREAM_COMMIT_SHA: ${CI_COMMIT_SHA}
trigger: trigger:
project: dbp/e2e-tests project: dbp/deployer
strategy: depend strategy: depend
/vendor
\ No newline at end of file
{
"require": {
"symfony/process": " ^5.0",
"symfony/console": " ^5.0",
"symfony/yaml": " ^5.0",
"deployer/deployer": " ^6.4",
"deployer/recipes": " ^6.2"
},
"config": {
"platform": {
"php": "7.3"
}
}
}
This diff is collapsed.
<?php
declare(strict_types=1);
namespace Deployer;
require 'recipe/common.php';
require 'recipe/rsync.php';
require 'recipe/cachetool.php';
// Global config
set('allow_anonymous_stats', false);
$rsync_config = [
'exclude' => [
'.git',
'deploy.php',
'_composer_cache',
],
'exclude-file' => false,
'include' => [],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'rz',
'options' => ['delete', 'links'],
'timeout' => 60,
];
// Hosts
host('development')
->stage('development')
->hostname('mw@mw01-dev.tugraz.at')
->set('deploy_path', '/home/mw/dev01/deploy/api-server-template')
->set('shared_dirs', ['var/log', 'var/sessions'])
->set('APP_ENV', 'prod')
->set('APP_DEBUG', '0')
->set('AUTH_SERVER_URL', 'https://auth-dev.tugraz.at/auth/realms/tugraz-vpu')
->set('AUTH_APIDOCS_KEYCLOAK_SERVER', 'https://auth-dev.tugraz.at/auth')
->set('AUTH_APIDOCS_KEYCLOAK_REALM', 'tugraz-vpu')
->set('AUTH_APIDOCS_KEYCLOAK_CLIENT_ID', 'dbp-api-template-frontend')
->set('rsync', $rsync_config)
->set('rsync_src', __DIR__.'/../')
->set('rsync_dest', '{{release_path}}')
->set('cachetool', '127.0.0.1:9001')
->set('bin/cachetool', '/home/mw/bin/cachetool');
// Build task
task('build-custom', function () {
$APP_ENV = get('APP_ENV');
$vars = [
'APP_ENV' => $APP_ENV,
'APP_DEBUG' => get('APP_DEBUG'),
'AUTH_SERVER_URL' => get('AUTH_SERVER_URL'),
'AUTH_APIDOCS_KEYCLOAK_SERVER' => get('AUTH_APIDOCS_KEYCLOAK_SERVER'),
'AUTH_APIDOCS_KEYCLOAK_REALM' => get('AUTH_APIDOCS_KEYCLOAK_REALM'),
'AUTH_APIDOCS_KEYCLOAK_CLIENT_ID' => get('AUTH_APIDOCS_KEYCLOAK_CLIENT_ID'),
];
// build .env.local file
runLocally('rm -f .env.local');
foreach ($vars as $key => $value) {
if (!isset($value) || $value === '') {
throw new \Exception("'${key}' is not set");
}
runLocally("echo '${key}=${value}' >> .env.local");
}
// Add build commit
$commit = runLocally('git rev-parse --short HEAD');
runLocally("echo \"CORE_API_BUILDINFO=${commit}\" >> .env.local");
// Add commit url to gitlab
$remote = runLocally('git config --get remote.origin.url');
$parts = parse_url($remote);
$parts['path'] = substr($parts['path'], 0, (strrpos($parts['path'], '.')));
$base_url = $parts['scheme'].'://'.$parts['host'].$parts['path'];
$build_url = $base_url.'/'.rawurlencode('commit').'/'.rawurlencode($commit);
runLocally("echo \"CORE_API_BUILDINFO_URL=${build_url}\" >> .env.local");
// composer install and optimize
runLocally('composer install --no-dev --classmap-authoritative');
// build .env.local.php file
runLocally('rm -f .env.local.php');
runLocally("composer dump-env '$APP_ENV'");
runLocally('rm -f .env.local');
// Cache clear/warmup
runLocally('php bin/console cache:clear');
});
// Deploy task
task('deploy', [
'deploy:info',
'build-custom',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'rsync',
'deploy:shared',
'deploy:symlink',
'deploy:unlock',
'cleanup',
'success',
]);
after('deploy:failed', 'deploy:unlock');
// Clear opcache
after('deploy:symlink', 'cachetool:clear:opcache');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment