Merge branch 'master' into oauth_jwt_tokens

This commit is contained in:
ErickSkrauch 2019-11-07 00:00:26 +03:00
commit da318ef2ed
4 changed files with 110 additions and 84 deletions

View File

@ -1,32 +1,76 @@
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
stages:
- test
- prepare
- testing
- build
- release
- cleanup
.defineVersion: &defineVersion |-
export VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:7}}"
.loginIntoRegistry: &loginIntoRegistry |-
docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by
variables:
APP_IMAGE_NAME: "registry.ely.by/elyby/accounts"
WEB_IMAGE_NAME: "registry.ely.by/elyby/accounts-nginx"
DB_IMAGE_NAME: "registry.ely.by/elyby/accounts-mariadb"
APP_IMAGE_NAME: "$CI_REGISTRY_IMAGE/app"
WEB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/web"
DB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/db"
php-cs-fixer:
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
stage: test
#######################
# Shared script steps #
#######################
# GitLab do not supports bash syntax in the "variables" definitions,
# so we use custom step to define all necessary environment variables
.defineVars: &defineVars |-
export VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}}"
export APP_VERSIONED_IMAGE_NAME="$APP_IMAGE_NAME:$VERSION"
export APP_LATEST_IMAGE_NAME="$APP_IMAGE_NAME:latest"
export WEB_VERSIONED_IMAGE_NAME="$WEB_IMAGE_NAME:$VERSION"
export WEB_LATEST_IMAGE_NAME="$WEB_IMAGE_NAME:latest"
export DB_VERSIONED_IMAGE_NAME="$DB_IMAGE_NAME:$VERSION"
export DB_LATEST_IMAGE_NAME="$DB_IMAGE_NAME:latest"
.dockerLogin: &dockerLogin |-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
###################
# Steps to extend #
###################
.vendorCache:
cache:
key: backend-vendor
key: backend-deps
paths:
- vendor
policy: pull
#################
# Prepare stage #
#################
Precache dependencies:
stage: prepare
extends:
- .vendorCache
cache:
policy: pull-push
script:
- composer install --ignore-platform-reqs
#################
# Testing stage #
#################
PHP-CS-Fixer:
stage: testing
extends:
- .vendorCache
script:
- composer install
- vendor/bin/php-cs-fixer fix -v --dry-run
codeception:
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
Codeception:
stage: testing
extends:
- .vendorCache
services:
- name: redis:4.0.10-alpine
alias: redis
@ -45,103 +89,85 @@ codeception:
MYSQL_DATABASE: "ely_accounts_test"
MYSQL_USER: "ely_accounts_tester"
MYSQL_PASSWORD: "ely_accounts_tester_password"
stage: test
cache:
key: backend-vendor
paths:
- vendor
before_script:
# While we not counting coverage, xdebug only slow down tests
# We don't count code coverage yet, so xdebug can be removed
- sudo rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
script:
- composer install
- php yii rbac/generate
- ./docker/php/wait-for-it.sh "${DB_HOST}:3306" -s -t 0 -- "php yii migrate/up --interactive=0"
- vendor/bin/codecept run
build:production:
image: docker:18.02
###############
# Build stage #
###############
Docker images:
stage: build
image: docker:19.03.2
before_script:
- *defineVersion
- *loginIntoRegistry
- *defineVars
- *dockerLogin
- sed -i -e "s/{{PLACE_VERSION_HERE}}/$VERSION/g" common/config/config.php
script:
- docker pull "$APP_IMAGE_NAME:latest"
- docker pull "$WEB_IMAGE_NAME:latest"
- docker pull "$DB_IMAGE_NAME:latest"
# Download previous images to use them as a cache
- docker pull "$APP_LATEST_IMAGE_NAME" || true
- docker pull "$WEB_LATEST_IMAGE_NAME" || true
- docker pull "$DB_LATEST_IMAGE_NAME" || true
# Build images
- >
docker build
--pull
--target app
--build-arg "build_env=prod"
--cache-from "$APP_IMAGE_NAME:latest"
-t "$APP_IMAGE_NAME:$CI_PIPELINE_ID" .
--cache-from "$APP_LATEST_IMAGE_NAME"
-t "$APP_VERSIONED_IMAGE_NAME"
-t "$APP_LATEST_IMAGE_NAME" .
- >
docker build
--pull
--target web
--build-arg "build_env=prod"
--cache-from "$APP_IMAGE_NAME:$CI_PIPELINE_ID"
--cache-from "$WEB_IMAGE_NAME:latest"
-t "$WEB_IMAGE_NAME:$CI_PIPELINE_ID" .
--cache-from "$APP_VERSIONED_IMAGE_NAME"
--cache-from "$WEB_LATEST_IMAGE_NAME"
-t "$WEB_VERSIONED_IMAGE_NAME"
-t "$WEB_LATEST_IMAGE_NAME" .
- >
docker build
--pull
--target db
--build-arg "build_env=prod"
--cache-from "$APP_IMAGE_NAME:$CI_PIPELINE_ID"
--cache-from "$DB_IMAGE_NAME:latest"
-t "$DB_IMAGE_NAME:$CI_PIPELINE_ID" .
--cache-from "$APP_VERSIONED_IMAGE_NAME"
--cache-from "$WEB_VERSIONED_IMAGE_NAME"
--cache-from "$DB_LATEST_IMAGE_NAME"
-t "$DB_VERSIONED_IMAGE_NAME"
-t "$DB_LATEST_IMAGE_NAME" .
# Push images to the registry
- docker push $APP_VERSIONED_IMAGE_NAME
- docker push $APP_LATEST_IMAGE_NAME
- docker push $WEB_VERSIONED_IMAGE_NAME
- docker push $WEB_LATEST_IMAGE_NAME
- docker push $DB_VERSIONED_IMAGE_NAME
- docker push $DB_LATEST_IMAGE_NAME
only:
- master
- tags
release:latest:
image: docker:18.02
stage: release
variables:
GIT_STRATEGY: none
before_script:
- *loginIntoRegistry
script:
- docker tag "$APP_IMAGE_NAME:$CI_PIPELINE_ID" "$APP_IMAGE_NAME:latest"
- docker push "$APP_IMAGE_NAME:latest"
#################
# Cleanup stage #
#################
- docker tag "$WEB_IMAGE_NAME:$CI_PIPELINE_ID" "$WEB_IMAGE_NAME:latest"
- docker push "$WEB_IMAGE_NAME:latest"
- docker tag "$DB_IMAGE_NAME:$CI_PIPELINE_ID" "$DB_IMAGE_NAME:latest"
- docker push "$DB_IMAGE_NAME:latest"
only:
- master
- tags
release:tag:
image: docker:18.02
stage: release
variables:
GIT_STRATEGY: none
before_script:
- *loginIntoRegistry
script:
- docker tag "$APP_IMAGE_NAME:$CI_PIPELINE_ID" "$APP_IMAGE_NAME:$VERSION"
- docker push "$APP_IMAGE_NAME:$VERSION"
- docker tag "$WEB_IMAGE_NAME:$CI_PIPELINE_ID" "$WEB_IMAGE_NAME:$VERSION"
- docker push "$WEB_IMAGE_NAME:$VERSION"
- docker tag "$DB_IMAGE_NAME:$CI_PIPELINE_ID" "$DB_IMAGE_NAME:$VERSION"
- docker push "$DB_IMAGE_NAME:$VERSION"
only:
- tags
cleanup:
Remove Docker images:
stage: cleanup
image: docker:19.03.2
variables:
GIT_STRATEGY: none
before_script:
- *defineVars
script:
- docker rmi "$APP_IMAGE_NAME:$CI_PIPELINE_ID" "$APP_IMAGE_NAME:$VERSION" "$APP_IMAGE_NAME:latest" || true
- docker rmi "$WEB_IMAGE_NAME:$CI_PIPELINE_ID" "$WEB_IMAGE_NAME:$VERSION" "$WEB_IMAGE_NAME:latest" || true
- docker rmi "$DB_IMAGE_NAME:$CI_PIPELINE_ID" "$DB_IMAGE_NAME:$VERSION" "$DB_IMAGE_NAME:latest" || true
- docker rmi "$APP_LATEST_IMAGE_NAME" "$APP_VERSIONED_IMAGE_NAME" || true
- docker rmi "$WEB_LATEST_IMAGE_NAME" "$WEB_VERSIONED_IMAGE_NAME" || true
- docker rmi "$DB_LATEST_IMAGE_NAME" "$DB_VERSIONED_IMAGE_NAME" || true
when: always
only:
- master
- tags

View File

@ -1,4 +1,4 @@
FROM php:7.3.3-fpm-alpine3.9 AS app
FROM php:7.3.11-fpm-alpine3.10 AS app
# ENV variables for composer
ENV COMPOSER_NO_INTERACTION 1

View File

@ -26,7 +26,6 @@ class ValidateForm extends ApiForm {
}
if ($result->isExpired()) {
$result->delete();
throw new ForbiddenOperationException('Token expired.');
}

View File

@ -1,6 +1,7 @@
<?php
namespace console\controllers;
use Carbon\Carbon;
use common\models\AccountSession;
use common\models\EmailActivation;
use common\models\MinecraftAccessKey;
@ -32,7 +33,7 @@ class CleanupController extends Controller {
public function actionMinecraftSessions(): int {
$expiredMinecraftSessionsQuery = MinecraftAccessKey::find()
->andWhere(['<', 'updated_at', time() - 1209600]); // 2 weeks
->andWhere(['<', 'updated_at', Carbon::now()->subMonths(3)->getTimestamp()]);
foreach ($expiredMinecraftSessionsQuery->each(100, Yii::$app->unbufferedDb) as $minecraftSession) {
/** @var MinecraftAccessKey $minecraftSession */