Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • A0F5D531834BDC1F/api-server-template
1 result
Show changes
Commits on Source (2)
......@@ -33,6 +33,9 @@ KEYCLOAK_CLIENT_SECRET=
APP_BUILDINFO=unknown # a git hash or something identifying the build
APP_BUILDINFO_URL='#'
# Defines the deployment environment
APP_DEPLOYMENT_ENV='local'
# Secret token for the starter bundle example
# This is just a defaule.
# Create a ".env.local" file which is excluded from git to set it
......
image: registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v1
image: registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v2
before_script:
- 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:"'
......@@ -14,6 +14,7 @@ cache:
stages:
- test
- deploy
.test_defaults: &test_defaults
script:
......@@ -62,3 +63,33 @@ cs-fixer:
- sudo update-alternatives --set php /usr/bin/php7.4
- composer install
- composer run cs
.deploy_defaults: &deploy_defaults
needs: ["test-php7.3", "test-php7.4"]
except:
- 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 "${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://mw-dev.tugraz.at
variables:
DEPLOY_HOST: mw01-dev.tugraz.at
DEPLOY_KEY: "$DEPLOY_SSH_KEY"
<<: *deploy_defaults
......@@ -71,6 +71,14 @@ RUN useradd -u 1000 -ms /bin/bash user
RUN echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER user
# Install deployer globally and add it to PATH
ENV COMPOSER_HOME="/home/user/.composer"
RUN mkdir -p "${COMPOSER_HOME}"
ADD composer.lock "${COMPOSER_HOME}"
ADD composer.json "${COMPOSER_HOME}"
RUN composer global install
ENV PATH "${COMPOSER_HOME}/vendor/bin:${PATH}"
# Install a newer composer
RUN mkdir -p /home/user/.local/bin
WORKDIR /home/user/.local/bin
......
* In case of an incompatible change increase the tag version number in build.sh
* ./build.sh
* (first time) sudo docker login registry.gitlab.tugraz.at
* sudo docker push registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v1
\ No newline at end of file
* sudo docker push registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v2
\ No newline at end of file
#!/bin/bash
set -e
TAG="registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v1"
TAG="registry.gitlab.tugraz.at/dbp/dbp-api/api-server-template/main:v2"
sudo docker build --tag "${TAG}" --file "Dockerfile" .
sudo docker run --rm --security-opt label=disable \
--volume "$(pwd)/..:/home/user/app" --workdir "/home/user/app" \
......
{
"require": {
"symfony/process": " ^5.0",
"symfony/console": " ^5.0",
"symfony/yaml": " ^5.0",
"deployer/deployer": " ^6.4",
"deployer/recipes": " ^6.2"
}
}
This diff is collapsed.
zend.assertions = 1
\ No newline at end of file
zend.assertions = 1
date.timezone = "Europe/Vienna"
......@@ -99,6 +99,8 @@
}
},
"require-dev": {
"deployer/deployer": "^6.4",
"deployer/recipes": "^6.2",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^0.12.7",
"phpstan/phpstan-phpunit": "^0.12.6",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "476cd1928ae3abc56e6d385dad2a6879",
"content-hash": "2955f60ebbab9e69237b65101d513a5f",
"packages": [
{
"name": "api-platform/core",
......@@ -6935,6 +6935,196 @@
],
"time": "2021-05-05T19:37:51+00:00"
},
{
"name": "deployer/deployer",
"version": "v6.8.0",
"source": {
"type": "git",
"url": "https://github.com/deployphp/deployer.git",
"reference": "4e243a64ed61e779fbb31c5a74e258a8e52fdaff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/deployphp/deployer/zipball/4e243a64ed61e779fbb31c5a74e258a8e52fdaff",
"reference": "4e243a64ed61e779fbb31c5a74e258a8e52fdaff",
"shasum": ""
},
"require": {
"deployer/phar-update": "~2.2",
"php": "^7.2",
"pimple/pimple": "~3.0",
"symfony/console": "~2.7|~3.0|~4.0|~5.0",
"symfony/process": "~2.7|~3.0|~4.0|~5.0",
"symfony/yaml": "~2.7|~3.0|~4.0|~5.0"
},
"require-dev": {
"phpunit/phpunit": "^8"
},
"bin": [
"bin/dep"
],
"type": "library",
"autoload": {
"psr-4": {
"Deployer\\": "src/"
},
"files": [
"src/Support/helpers.php",
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anton Medvedev",
"email": "anton@medv.io"
}
],
"description": "Deployment Tool",
"homepage": "https://deployer.org",
"support": {
"docs": "https://deployer.org/docs",
"issues": "https://github.com/deployphp/deployer/issues",
"source": "https://github.com/deployphp/deployer"
},
"funding": [
{
"url": "https://github.com/antonmedv",
"type": "github"
},
{
"url": "https://www.patreon.com/deployer",
"type": "patreon"
}
],
"time": "2020-04-25T16:05:31+00:00"
},
{
"name": "deployer/phar-update",
"version": "v2.2.0",
"source": {
"type": "git",
"url": "https://github.com/deployphp/phar-update.git",
"reference": "9ad07422f2cd43a1382ee8e134bdcd3a374848e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/deployphp/phar-update/zipball/9ad07422f2cd43a1382ee8e134bdcd3a374848e3",
"reference": "9ad07422f2cd43a1382ee8e134bdcd3a374848e3",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/console": "~2.7|~3.0|~4.0|~5.0"
},
"require-dev": {
"mikey179/vfsstream": "1.1.0",
"phpunit/phpunit": "3.7.*",
"symfony/process": "~2.7|~3.0|~4.0|~5.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Deployer\\Component\\PharUpdate\\": "src/",
"Deployer\\Component\\PHPUnit\\": "src/PHPUnit/",
"Deployer\\Component\\Version\\": "src/Version/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kevin Herrera",
"email": "kevin@herrera.io",
"homepage": "http://kevin.herrera.io"
},
{
"name": "Anton Medvedev",
"email": "anton@medv.io",
"homepage": "https://medv.io"
}
],
"description": "Integrates Phar Update to Symfony Console.",
"homepage": "https://github.com/deployphp/phar-update",
"keywords": [
"console",
"phar",
"update"
],
"support": {
"issues": "https://github.com/deployphp/phar-update/issues",
"source": "https://github.com/deployphp/phar-update/tree/v2.2.0"
},
"abandoned": true,
"time": "2019-12-12T13:45:57+00:00"
},
{
"name": "deployer/recipes",
"version": "6.2.2",
"source": {
"type": "git",
"url": "https://github.com/deployphp/recipes.git",
"reference": "84b3229c518c094a950e1fe785b7b8f9598770fe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/deployphp/recipes/zipball/84b3229c518c094a950e1fe785b7b8f9598770fe",
"reference": "84b3229c518c094a950e1fe785b7b8f9598770fe",
"shasum": ""
},
"require": {
"php": "~7.0"
},
"replace": {
"deployer/recipes": "self.version"
},
"require-dev": {
"deployer/deployer": "^6.3"
},
"type": "library",
"autoload": {
"files": [
"autoload.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anton Medvedev",
"email": "anton@medv.io"
}
],
"description": "3rd party deployer recipes",
"homepage": "https://github.com/deployphp/recipes",
"keywords": [
"cachetool",
"cloudflare",
"deploy",
"deployer",
"deployment",
"hipchat",
"newrelic",
"rabbit",
"recipes",
"sentry",
"slack",
"yarn"
],
"support": {
"issues": "https://github.com/deployphp/recipes/issues",
"source": "https://github.com/deployphp/recipes"
},
"abandoned": true,
"time": "2019-06-27T06:47:18+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "v0.1.1",
......@@ -7491,6 +7681,59 @@
},
"time": "2021-06-17T08:28:30+00:00"
},
{
"name": "pimple/pimple",
"version": "v3.4.0",
"source": {
"type": "git",
"url": "https://github.com/silexphp/Pimple.git",
"reference": "86406047271859ffc13424a048541f4531f53601"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/silexphp/Pimple/zipball/86406047271859ffc13424a048541f4531f53601",
"reference": "86406047271859ffc13424a048541f4531f53601",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"psr/container": "^1.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Pimple": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Pimple, a simple Dependency Injection Container",
"homepage": "https://pimple.symfony.com",
"keywords": [
"container",
"dependency injection"
],
"support": {
"source": "https://github.com/silexphp/Pimple/tree/v3.4.0"
},
"time": "2021-03-06T08:28:00+00:00"
},
{
"name": "sebastian/diff",
"version": "4.0.4",
......@@ -8511,5 +8754,5 @@
"platform-overrides": {
"php": "7.3"
},
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.0.0"
}
<?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',
],
'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('APP_DEPLOYMENT_ENV', 'development')
->set('KEYCLOAK_SERVER_URL', 'https://auth-dev.tugraz.at/auth')
->set('KEYCLOAK_CLIENT_ID', 'auth-dev-mw-dev')
->set('KEYCLOAK_FRONTEND_CLIENT_ID', 'auth-dev-mw-frontend')
->set('rsync', $rsync_config)
->set('rsync_src', __DIR__)
->set('rsync_dest', '{{release_path}}')
->set('cachetool', '127.0.0.1:9001');
// Build task
task('build-custom', function () {
$APP_ENV = get('APP_ENV');
$vars = [
'KEYCLOAK_CLIENT_SECRET' => getenv('KEYCLOAK_CLIENT_SECRET'),
'APP_ENV' => $APP_ENV,
'APP_DEBUG' => get('APP_DEBUG'),
'APP_DEPLOYMENT_ENV' => get('APP_DEPLOYMENT_ENV'),
'KEYCLOAK_SERVER_URL' => get('KEYCLOAK_SERVER_URL'),
'KEYCLOAK_CLIENT_ID' => get('KEYCLOAK_CLIENT_ID'),
'KEYCLOAK_FRONTEND_CLIENT_ID' => get('KEYCLOAK_FRONTEND_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 \"APP_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 \"APP_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 warmup
runLocally('php bin/console cache:clear');
runLocally('php bin/console cache:warmup');
});
// 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');
......@@ -15,7 +15,11 @@ class Kernel extends BaseKernel
protected function configureContainer(ContainerConfigurator $container): void
{
$container->import('../config/{packages}/*.yaml');
// Ignore all errors in case we are not local/development. We disable some
// bundles in demo/prod which leads to unused config, which symfony fails over.
$ignoreErrors = !in_array($_ENV['APP_DEPLOYMENT_ENV'], ['local', 'development'], true);
$container->import('../config/{packages}/*.yaml', null, $ignoreErrors);
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
......
......@@ -40,6 +40,15 @@
"dbp/api-starter-bundle": {
"version": "dev-main"
},
"deployer/deployer": {
"version": "v6.8.0"
},
"deployer/phar-update": {
"version": "v2.2.0"
},
"deployer/recipes": {
"version": "6.2.2"
},
"dnoegel/php-xdg-base-dir": {
"version": "v0.1.1"
},
......@@ -169,6 +178,9 @@
"phpstan/phpstan-phpunit": {
"version": "0.12.16"
},
"pimple/pimple": {
"version": "v3.4.0"
},
"psr/cache": {
"version": "1.0.1"
},
......