Skip to content
Snippets Groups Projects
Unverified Commit 5be98ab5 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Initial commit

parent 25a95b85
Branches
No related tags found
No related merge requests found
Pipeline #85441 failed
Showing with 13807 additions and 0 deletions
.env 0 → 100644
# In all environments, the following files are loaded if they exist,
# the later 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.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=
###< symfony/framework-bundle ###
###> dbp/relay-core-bundle ###
CORE_API_BUILDINFO=unknown
CORE_API_BUILDINFO_URL=#
###< dbp/relay-core-bundle ###
###> dbp/relay-auth-bundle ###
AUTH_SERVER_URL=https://auth-dev.tugraz.at/auth/realms/tugraz-vpu
AUTH_APIDOCS_KEYCLOAK_SERVER=https://auth-dev.tugraz.at/auth
AUTH_APIDOCS_KEYCLOAK_REALM=tugraz-vpu
AUTH_APIDOCS_KEYCLOAK_CLIENT_ID=auth-dev-mw-frontend-local
###< dbp/relay-auth-bundle ###
###> dbp/relay-base-person-connector-ldap-bundle ###
LDAP_PERSON_PROVIDER_LDAP_HOST=directory.tugraz.at
LDAP_PERSON_PROVIDER_LDAP_USERNAME=cn=ldap_middleware,o=tug
LDAP_PERSON_PROVIDER_LDAP_BASE_DN=o=tug
LDAP_PERSON_PROVIDER_LDAP_PASSWORD=
LDAP_PERSON_PROVIDER_LDAP_ATTRIBUTE_IDENTIFIER=cn
LDAP_PERSON_PROVIDER_LDAP_ATTRIBUTE_GIVEN_NAME=givenName
LDAP_PERSON_PROVIDER_LDAP_ATTRIBUTE_FAMILY_NAME=sn
LDAP_PERSON_PROVIDER_LDAP_ATTRIBUTE_EMAIL=mail
LDAP_PERSON_PROVIDER_LDAP_ATTRIBUTE_BIRTHDAY=DateOfBirth
###< dbp/relay-base-person-connector-ldap-bundle ###
/_coverage
/*.cache
cghooks.lock
.idea
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
image: registry.gitlab.tugraz.at/dbp/relay/dbp-relay-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:"'
- 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "https://gitlab.tugraz.at/"'
variables:
COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/_composer_cache"
cache:
key: ${CI_PROJECT_PATH}
paths:
- _composer_cache
stages:
- test
- deploy
- e2e
.test_defaults: &test_defaults
script:
- sudo update-alternatives --set php "/usr/bin/${PHP}"
- composer install
- composer test
test-php7.3:
stage: test
variables:
PHP: "php7.3"
<<: *test_defaults
test-php7.4:
stage: test
variables:
PHP: "php7.4"
<<: *test_defaults
test-php8.0:
stage: test
variables:
PHP: "php8.0"
<<: *test_defaults
linting:
stage: test
allow_failure: true
script:
- sudo update-alternatives --set php /usr/bin/php7.4
- composer install
- result=0
- composer run cs || result=1
- composer run phpstan || result=1
- composer run psalm || result=1
- exit $result
.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 --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:
refs:
- main
variables:
E2E_PROJECT: rest
stage: e2e
trigger:
project: dbp/e2e-tests
strategy: depend
/vendor
\ No newline at end of file
FROM debian:bullseye
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# Basics
RUN apt-get update && apt-get install -y \
composer \
php-zip \
rsync \
sudo \
wget \
curl \
lsb-release \
&& rm -rf /var/lib/apt/lists/*
# PHP Repo
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
# PHP 7.3
RUN apt-get update && apt-get install -y \
php7.3 \
php7.3-curl \
php7.3-soap \
php7.3-xml \
php7.3-ldap \
php7.3-zip \
php7.3-gmp \
php7.3-xdebug \
php7.3-gd \
php7.3-mysql \
php7.3-mbstring \
&& rm -rf /var/lib/apt/lists/*
COPY ./php-ini-overrides.ini /etc/php/7.3/cli/conf.d/
# PHP 7.4
RUN apt-get update && apt-get install -y \
php7.4 \
php7.4-curl \
php7.4-soap \
php7.4-xml \
php7.4-ldap \
php7.4-zip \
php7.4-gmp \
php7.4-xdebug \
php7.4-gd \
php7.4-mysql \
php7.4-mbstring \
&& rm -rf /var/lib/apt/lists/*
COPY ./php-ini-overrides.ini /etc/php/7.4/cli/conf.d/
# PHP 8.0
RUN apt-get update && apt-get install -y \
php8.0 \
php8.0-curl \
php8.0-soap \
php8.0-xml \
php8.0-ldap \
php8.0-zip \
php8.0-gmp \
php8.0-xdebug \
php8.0-gd \
php8.0-mysql \
php8.0-mbstring \
&& rm -rf /var/lib/apt/lists/*
COPY ./php-ini-overrides.ini /etc/php/8.0/cli/conf.d/
# Default to PHP 7.3
RUN sudo update-alternatives --set php /usr/bin/php7.3
RUN sudo update-alternatives --set phar /usr/bin/phar7.3
RUN sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.3
# Add a normal user and enable sudo
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
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/bfd95e2a4383ee9cf7c058c2df29d7acb5f86d77/web/installer -O - -q | php --
RUN mv composer.phar composer
ENV PATH "/home/user/.local/bin:$PATH"
WORKDIR /home/user
\ No newline at end of file
* 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/dbp-relay-server-template/main:v2
\ No newline at end of file
#!/bin/bash
set -e
TAG="registry.gitlab.tugraz.at/dbp/relay/dbp-relay-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" \
--tty --interactive "${TAG}" bash
echo "Now run: sudo docker push '$TAG'"
{
"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');
zend.assertions = 1
date.timezone = "Europe/Vienna"
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
->notPath('config/bundles.php')
;
$config = new PhpCsFixer\Config();
$config->setRules([
'@Symfony' => true,
'@PHP70Migration' => true,
'@PHP71Migration' => true,
'@PHP73Migration' => true,
'@DoctrineAnnotation' => true,
'doctrine_annotation_array_assignment' => ['operator' => '='],
'yoda_style' => false,
'strict_comparison' => true,
'strict_param' => true,
'declare_strict_types' => true,
'method_argument_space' => ['on_multiline' => 'ignore'],
])
->setRiskyAllowed(true)
->setFinder($finder);
return $config;
\ No newline at end of file
{
"extends": [
"config:base",
"group:allNonMajor",
"schedule:weekends",
":automergePatch"
],
"ignorePresets": [":prHourlyLimit2"],
"rangeStrategy": "update-lockfile",
"lockFileMaintenance": {
"enabled": true
},
"packageRules": [
{
"matchPackagePrefixes": [
"symfony/"
],
"allowedVersions": "<6"
}
],
"docker": {
"enabled": false
}
}
# DBP API Server Template
[GitLab](https://gitlab.tugraz.at/dbp/relay/dbp-relay-server-template)
This repository can be used as a template/starting point for your own API instance.
It consists of a minimally configures Symfony application and development environment
and includes/integrates:
* The [dbp/api-core-bundle](https://gitlab.tugraz.at/dbp/dbp-api/api-core-bundle): Which provides authentication, some same base end points and entities and configuration for [api-platform](https://api-platform.com/)
* A docker-compose based development environment
* Linter/Unittest integration
## Documentation
The documentation is work in progress and currently exists in another repository which can be viewed here:
[Relay API Gateway](https://dbp-demo.tugraz.at/dev-guide/relay/)
It will be moved into this repository in the near future.
## Creating your own API instance and creating your own Bundle
* Fork this repository
* Run the docker-compose based development environment and test it
* Copy the "api-starter-bundle" repo and rename everything
* Add the new bundle to your API fork
## Installation
```bash
# install relay-server-template to path "relay-api" (you need php and composer for this)
composer create-project dbp/relay-server-template relay-api "dev-main"
cd relay-api
# install dependencies
composer install
```
## Development
```bash
# clone git repository
git clone https://gitlab.tugraz.at/dbp/relay/dbp-relay-server-template.git relay-api
cd relay-api
# install dependencies (you need php and composer for this)
# you can also do this in the dev docker container (see below docker-dev link)
composer install
```
Please open [docker-dev/README.md](./docker-dev/README.md) for more information.
#!/usr/bin/env php
<?php
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}
set_time_limit(0);
require dirname(__DIR__).'/vendor/autoload.php';
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}
if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
#!/usr/bin/env php
<?php
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
{
"type": "project",
"license": "proprietary",
"require": {
"php": ">=7.3",
"dbp/relay-auth-bundle": "^0.1.4",
"dbp/relay-base-person-bundle": "^0.1.5",
"dbp/relay-base-person-connector-ldap-bundle": "^0.2.0",
"dbp/relay-core-bundle": "^0.1.22",
"dbp/relay-esign-bundle": "^0.2.1",
"dbp/relay-frontend-bundle": "^0.1.0",
"symfony/apache-pack": "^1.0",
"symfony/console": "^5.4",
"symfony/dotenv": "^5.4",
"symfony/flex": "^1.11",
"symfony/framework-bundle": "^5.4",
"symfony/monolog-bundle": "^3.5",
"symfony/yaml": "^5.4"
},
"config": {
"preferred-install": {
"dbp/*": "source",
"*": "dist"
},
"sort-packages": true,
"platform": {
"php": "7.3"
}
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd",
"vendor/dbp/relay-core-bundle/bin/move-core-bundle.php": "php-script",
"vendor/dbp/relay-core-bundle/bin/disable-database-url.php": "php-script"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
"test": [
"@php vendor/bin/phpunit"
],
"coverage": [
"@php vendor/bin/phpunit --coverage-html _coverage"
],
"phpstan": [
"@php vendor/bin/phpstan analyze --ansi"
],
"psalm": [
"@php vendor/bin/psalm"
],
"lint": [
"@composer run cs",
"@composer run phpstan",
"@composer run psalm"
],
"cs-fix": [
"@php vendor/bin/php-cs-fixer --ansi fix"
],
"cs": [
"@php vendor/bin/php-cs-fixer --ansi fix --dry-run --diff"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "^5.4",
"endpoint": [
"flex://defaults",
"https://api.github.com/repos/digital-blueprint/symfony-recipes/contents/index.json?ref=flex/main"
]
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.0.2",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9",
"symfony/browser-kit": "^5.4",
"symfony/debug-bundle": "^5.4",
"symfony/http-client": "^5.4",
"symfony/phpunit-bridge": "^5.4",
"symfony/stopwatch": "^5.4",
"symfony/var-dumper": "^5.4",
"symfony/web-profiler-bundle": "^5.4",
"vimeo/psalm": "^4.2.1"
}
}
This diff is collapsed.
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => false],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Dbp\Relay\AuthBundle\DbpRelayAuthBundle::class => ['all' => true],
Dbp\Relay\BasePersonBundle\DbpRelayBasePersonBundle::class => ['all' => true],
Dbp\Relay\BasePersonConnectorLdapBundle\DbpRelayBasePersonConnectorLdapBundle::class => ['all' => true],
Dbp\Relay\FrontendBundle\DbpRelayFrontendBundle::class => ['all' => true],
Dbp\Relay\EsignBundle\DbpRelayEsignBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle::class => ['all' => true],
];
dbp_relay_auth:
server_url: '%env(AUTH_SERVER_URL)%'
# (optional) This allows you to log into the auto generated OpenAPI documentation page
# which you can see when visiting the server with a browser. Remove to disable.
frontend_keycloak_server: '%env(AUTH_APIDOCS_KEYCLOAK_SERVER)%'
frontend_keycloak_realm: '%env(AUTH_APIDOCS_KEYCLOAK_REALM)%'
frontend_keycloak_client_id: '%env(AUTH_APIDOCS_KEYCLOAK_CLIENT_ID)%'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment