diff options
| -rw-r--r-- | .gitlab-ci.yml | 141 | ||||
| -rw-r--r-- | .gitlab/scripts/install_db.sh | 29 | ||||
| -rw-r--r-- | .phplint.yml | 9 | ||||
| -rw-r--r-- | composer.json | 3 | ||||
| -rw-r--r-- | composer.lock | 118 | ||||
| -rw-r--r-- | docker/release-cli/Dockerfile | 6 | ||||
| -rw-r--r-- | docker/studip/Dockerfile | 60 | ||||
| -rw-r--r-- | docker/studip/Dockerfile-Dev | 38 | ||||
| -rw-r--r-- | docker/studip/config_local.php | 47 | ||||
| -rw-r--r-- | docker/studip/docker-entrypoint.sh | 44 |
10 files changed, 493 insertions, 2 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0fd3f17..baec987 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,13 +1,154 @@ image: studip/studip:tests variables: + MYSQL_RANDOM_ROOT_PASSWORD: "true" + MYSQL_DATABASE: studip_db + MYSQL_USER: studip_user + MYSQL_PASSWORD: studip_password + MYSQL_HOST: mariadb + DEMO_DATA: "true" + MAIL_TRANSPORT: debug + # Optimize caching + FF_USE_FASTZIP: "true" + CACHE_COMPRESSION_LEVEL: "fast" # User faster docker driver DOCKER_DRIVER: overlay2 stages: + - checks + - tests - packaging - release +.scripts: + install-composer: + - make composer-dev + configure-studip: + - !reference [.scripts, install-composer] + - cp docker/studip/config_local.php config/config_local.inc.php + - cp config/config.inc.php.dist config/config.inc.php + initialize-studip-database: + - !reference [.scripts, configure-studip] + - chmod +x .gitlab/scripts/install_db.sh + - .gitlab/scripts/install_db.sh + - cli/studip migrate + remove-absolute-path-in-report: + - sed -i "s%$PWD/%%" tests/_output/report.xml + +.artifacts: + common: &common-artifacts + when: always + expire_in: 1 week + tests: &test-artifacts + <<: *common-artifacts + paths: + - tests/_output + reports: + junit: tests/_output/report.xml + +.caches: + php: &composer-cache + key: "php-$CI_COMMIT_REF_SLUG" + paths: + - composer/ + - .caches/phplint-cache + - .caches/resultCache.php + - .caches/cache/* + - .caches/resultCaches/* + js: &npm-cache + key: "js-$CI_COMMIT_REF_SLUG" + paths: + - node_modules/ + - .caches/eslint-cache + - .caches/stylelint-cache + +lint-php: + stage: checks + needs: [] + cache: *composer-cache + allow_failure: false + interruptible: true + before_script: + - !reference [.scripts, install-composer] + - mkdir -p .reports + script: + - php -d memory_limit=-1 composer/bin/phplint --xml .reports/phplint-report.xml --cache=.caches/phplint-cache + artifacts: + <<: *common-artifacts + paths: + - .reports/phplint-report.xml + reports: + junit: .reports/phplint-report.xml + +test-assets: + stage: checks + needs: [] + cache: *npm-cache + allow_failure: false + interruptible: true + before_script: + - make npm + script: + - make webpack-dev + +test-unit: + stage: tests + needs: [lint-php] + cache: + <<: *composer-cache + policy: pull + allow_failure: false + interruptible: true + before_script: + - !reference [.scripts, configure-studip] + script: + - composer/bin/codecept run unit --xml + - !reference [.scripts, remove-absolute-path-in-report] + artifacts: + <<: *test-artifacts + +test-functional: + stage: tests + needs: [lint-php] + cache: + <<: *composer-cache + policy: pull + services: + - mariadb + allow_failure: false + interruptible: true + before_script: + - !reference [.scripts, initialize-studip-database] + script: + - composer/bin/codecept run functional --xml + - !reference [.scripts, remove-absolute-path-in-report] + artifacts: + <<: *test-artifacts + +test-jsonapi: + stage: tests + needs: [lint-php] + cache: + <<: *composer-cache + policy: pull + services: + - mariadb + allow_failure: false + interruptible: true + before_script: + - !reference [.scripts, initialize-studip-database] + script: + - composer/bin/codecept run jsonapi --xml + - !reference [.scripts, remove-absolute-path-in-report] + artifacts: + <<: *test-artifacts + when: always + expire_in: 1 week + paths: + - tests/_output + reports: + junit: tests/_output/report.xml + packaging: stage: packaging cache: [] diff --git a/.gitlab/scripts/install_db.sh b/.gitlab/scripts/install_db.sh new file mode 100644 index 0000000..0f2f554 --- /dev/null +++ b/.gitlab/scripts/install_db.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +if [ $(mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "show tables;" --batch | wc -l) -eq 0 ]; then + + # Setup mysql database + echo "INSTALL DB" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip.sql + echo "INSTALL DEFAULT DATA" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_default_data.sql + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_resources_default_data.sql + + echo "INSTALL ROOTUSER" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_root_user.sql + + # Check if demodata is required + if [ ! -z $DEMO_DATA ]; then + echo "INSTALL DEMODATA" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_demo_data.sql + echo "INSTALL MVV_DEMODATA" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_mvv_demo_data.sql + echo "INSTALL RESOURCES-DEMODATA" + mysql -f -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD $MYSQL_DATABASE < ./db/studip_resources_demo_data.sql + fi + + echo "INSTALLATION FINISHED" +else + echo "Found some SQL table. Skipping installation" +fi diff --git a/.phplint.yml b/.phplint.yml new file mode 100644 index 0000000..985f01e --- /dev/null +++ b/.phplint.yml @@ -0,0 +1,9 @@ +path: ./ +jobs: 10 +cache: .caches/phplint-cache +extensions: + - php +exclude: + - composer + - public/plugins_packages + - vendor diff --git a/composer.json b/composer.json index aeaead9..0b53384 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "php-http/curl-client": "~1.7.0", "woohoolabs/yang": "2.3.2", "codeception/codeception": "~4.1.21", - "codeception/module-asserts": "^1.3" + "codeception/module-asserts": "^1.3", + "overtrue/phplint": "^3.2" }, "require": { "php": "^7.2", diff --git a/composer.lock b/composer.lock index ef1eb5a..019ebf8 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "960497e77c90d28e8581a7cd673f884d", + "content-hash": "1a043763c12cdc7fb17c8d3a75af898f", "packages": [ { "name": "algo26-matthias/idna-convert", @@ -4423,6 +4423,122 @@ "time": "2020-11-13T09:40:50+00:00" }, { + "name": "n98/junit-xml", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/cmuench/junit-xml.git", + "reference": "0017dd92ac8cb619f02e32f4cffd768cfe327c73" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cmuench/junit-xml/zipball/0017dd92ac8cb619f02e32f4cffd768cfe327c73", + "reference": "0017dd92ac8cb619f02e32f4cffd768cfe327c73", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "N98\\JUnitXml\\": "src/N98/JUnitXml" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Münch", + "email": "c.muench@netz98.de" + } + ], + "description": "JUnit XML Document generation library", + "support": { + "issues": "https://github.com/cmuench/junit-xml/issues", + "source": "https://github.com/cmuench/junit-xml/tree/1.1.0" + }, + "time": "2020-12-25T09:08:58+00:00" + }, + { + "name": "overtrue/phplint", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/overtrue/phplint.git", + "reference": "c3021ad8cebd802ad3f4924c45f508803e0b80e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/overtrue/phplint/zipball/c3021ad8cebd802ad3f4924c45f508803e0b80e5", + "reference": "c3021ad8cebd802ad3f4924c45f508803e0b80e5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "n98/junit-xml": "1.1.0", + "php": "^5.5.9 || ^7.0", + "symfony/console": "^3.2 || ^4.0 || ^5.0", + "symfony/finder": "^3.0 || ^4.0 || ^5.0", + "symfony/process": "^3.3 || ^4.0 || ^5.0", + "symfony/yaml": "^3.0 || ^4.0 || ^5.0" + }, + "require-dev": { + "brainmaestro/composer-git-hooks": "^2.7", + "friendsofphp/php-cs-fixer": "^2.16", + "jakub-onderka/php-console-highlighter": "^0.3.2 || ^0.4" + }, + "bin": [ + "bin/phplint" + ], + "type": "library", + "extra": { + "hooks": { + "pre-commit": [ + "composer fix-style" + ], + "pre-push": [ + "composer check-style" + ] + } + }, + "autoload": { + "psr-4": { + "Overtrue\\PHPLint\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "overtrue", + "email": "anzhengchao@gmail.com" + } + ], + "description": "`phplint` is a tool that can speed up linting of php files by running several lint processes at once.", + "keywords": [ + "check", + "lint", + "phplint", + "syntax" + ], + "support": { + "issues": "https://github.com/overtrue/phplint/issues", + "source": "https://github.com/overtrue/phplint/tree/3.2.0" + }, + "funding": [ + { + "url": "https://github.com/overtrue", + "type": "github" + } + ], + "time": "2022-07-12T07:37:04+00:00" + }, + { "name": "phar-io/manifest", "version": "2.0.1", "source": { diff --git a/docker/release-cli/Dockerfile b/docker/release-cli/Dockerfile new file mode 100644 index 0000000..4e41152 --- /dev/null +++ b/docker/release-cli/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine + +RUN apk --no-cache add jq bash curl grep + +ADD https://release-cli-downloads.s3.amazonaws.com/latest/release-cli-linux-amd64 /usr/bin/release-cli +RUN chmod u+x /usr/bin/release-cli
\ No newline at end of file diff --git a/docker/studip/Dockerfile b/docker/studip/Dockerfile new file mode 100644 index 0000000..de3a4b1 --- /dev/null +++ b/docker/studip/Dockerfile @@ -0,0 +1,60 @@ +# Setup php, apache and stud.ip +FROM php:7.4-apache as base + +# Install system requirements +RUN apt update && apt install -y --no-install-recommends \ + default-mysql-client \ + default-libmysqlclient-dev \ + libcurl4-openssl-dev zlib1g-dev \ + libpng-dev \ + libjpeg-dev \ + libonig-dev \ + libzip-dev \ + libicu-dev \ + vim \ + && rm -rf /var/lib/apt/lists/* + +# Install php extensions +RUN docker-php-ext-configure gd --with-jpeg +RUN docker-php-ext-install pdo gettext curl gd mbstring zip pdo pdo_mysql mysqli intl json + +FROM node:14 as nodejs + +# Install node modules +COPY . /studip +WORKDIR /studip +RUN make webpack-prod + +FROM base as build + +# Install composer +COPY --from=composer /usr/bin/composer /usr/bin/composer + +# Copy studip +COPY --from=nodejs /studip /studip + +# Execute make to install composer dependencies and build assets +WORKDIR /studip +RUN make composer + +FROM base + +# Reconfigure apache +ENV APACHE_DOCUMENT_ROOT /var/www/studip/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +COPY --from=build /studip /var/www/studip + +WORKDIR /var/www/studip + +# Add config template +COPY ./docker/studip/config_local.php ./config/config_local.inc.php + +# Add custom entrypoint +COPY ./docker/studip/docker-entrypoint.sh /usr/local/bin/ +RUN chmod u+x /usr/local/bin/docker-entrypoint.sh + +# Set start parameters +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/docker/studip/Dockerfile-Dev b/docker/studip/Dockerfile-Dev new file mode 100644 index 0000000..960bd97 --- /dev/null +++ b/docker/studip/Dockerfile-Dev @@ -0,0 +1,38 @@ +# Setup php, apache and stud.ip +FROM php:7.4-apache as base + +# Install system requirements +RUN apt update && apt install -y --no-install-recommends \ + default-mysql-client \ + default-libmysqlclient-dev \ + libcurl4-openssl-dev zlib1g-dev \ + libpng-dev \ + libjpeg-dev \ + libonig-dev \ + libzip-dev \ + libicu-dev \ + vim \ + && rm -rf /var/lib/apt/lists/* + +# Install php extensions +RUN docker-php-ext-configure gd --with-jpeg +RUN docker-php-ext-install pdo gettext curl gd mbstring zip pdo pdo_mysql mysqli intl json + + +# Reconfigure apache +ENV APACHE_DOCUMENT_ROOT /var/www/studip/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +WORKDIR /var/www/studip + +# Add config template +ADD ./docker/studip/config_local.php ./config/config_local.inc.php + +# Add custom entrypoint +COPY ./docker/studip/docker-entrypoint.sh /usr/local/bin/ +RUN chmod u+x /usr/local/bin/docker-entrypoint.sh + +# Set start parameters +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +CMD ["apache2-foreground"]
\ No newline at end of file diff --git a/docker/studip/config_local.php b/docker/studip/config_local.php new file mode 100644 index 0000000..4e77ed8 --- /dev/null +++ b/docker/studip/config_local.php @@ -0,0 +1,47 @@ +<?php +/*basic settings for Stud.IP +---------------------------------------------------------------- +you find here the basic system settings. You shouldn't have to touch much of them... +please note the CONFIG.INC.PHP for the indivual settings of your installation!*/ + +namespace Studip { + //const ENV = 'development'; + define ('ENV', getenv('ENV') ?? 'development'); +} + +namespace { + /*settings for database access + ---------------------------------------------------------------- + please fill in your database connection settings. + */ + + // default Stud.IP database (DB_Seminar) + $DB_STUDIP_HOST = getenv('MYSQL_HOST'); + $DB_STUDIP_USER = getenv('MYSQL_USER'); + $DB_STUDIP_PASSWORD = getenv('MYSQL_PASSWORD'); + $DB_STUDIP_DATABASE = getenv('MYSQL_DATABASE'); + $MAIL_TRANSPORT = getenv('MAIL_TRANSPORT'); + + /*URL + ---------------------------------------------------------------- + customize if automatic detection fails, e.g. when installation is hidden + behind a proxy + */ + //$CANONICAL_RELATIVE_PATH_STUDIP = '/'; + //$ABSOLUTE_URI_STUDIP = 'https://www.studip.de/'; + //$ASSETS_URL = 'https://www.studip.de/assets/'; + + // Set proxy url + if ($PROXY_URL = getenv('PROXY_URL')) { + $ABSOLUTE_URI_STUDIP = $PROXY_URL; + $ASSETS_URL = $PROXY_URL.'/assets/'; + unset($PROXY_URL); + } + + // Use autoproxy + if (getenv('AUTO_PROXY')) { + $ABSOLUTE_URI_STUDIP = $_SERVER['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_X_FORWARDED_HOST'].'/'; + $ASSETS_URL = $ABSOLUTE_URI_STUDIP.'/assets/'; + } + $MAIL_TRANSPORT = getenv('STUDIP_MAIL_TRANSPORT'); +}
\ No newline at end of file diff --git a/docker/studip/docker-entrypoint.sh b/docker/studip/docker-entrypoint.sh new file mode 100644 index 0000000..bafc2fe --- /dev/null +++ b/docker/studip/docker-entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e + +STUDIP='/var/www/studip' +CONFIGFILE="$STUDIP/config/config_local.inc.php" +DOCKERCONFIGFILE="/config/config_local.inc.php" +CONF="$STUDIP/config/config.inc.php" + +# Check if we have a config +if [ ! -f $CONFIGFILE ]; then + echo "Setting up new config" + cp "$DOCKERCONFIGFILE" "$CONFIGFILE" + cp "$CONF.dist" "$CONF" +fi + +# wait until MySQL is really available +maxcounter=45 + +counter=1 +while ! mysql -u $MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD -e "show databases;" > /dev/null 2>&1; do + sleep 1 + counter=`expr $counter + 1` + if [ $counter -gt $maxcounter ]; then + echo "We have been waiting for MySQL too long already; failing." >&2 + exit 1 + fi; +done + +sh $STUDIP/.gitlab/scripts/install_db.sh + +if [ ! -z $AUTO_MIGRATE ]; then + echo "Migrate Instance" + # If migrate fails start instance anyway + php "$STUDIP/cli/studip migrate" || true + echo "Migration finished" +fi + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- apache2-foreground "$@" +fi + +exec "$@" + |
