mirror of
https://github.com/elyby/accounts.git
synced 2025-02-03 09:19:39 +05:30
Upgrade gitlab-ci
This commit is contained in:
parent
6c4ce8cb8d
commit
7505bc8262
187
.gitlab-ci.yml
187
.gitlab-ci.yml
@ -1,32 +1,75 @@
|
|||||||
stages:
|
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
|
||||||
- test
|
|
||||||
- build
|
|
||||||
- release
|
|
||||||
- cleanup
|
|
||||||
|
|
||||||
.defineVersion: &defineVersion |-
|
stages:
|
||||||
export VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA:0:7}}"
|
- prepare
|
||||||
.loginIntoRegistry: &loginIntoRegistry |-
|
- testing
|
||||||
docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by
|
- build
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
APP_IMAGE_NAME: "registry.ely.by/elyby/accounts"
|
APP_IMAGE_NAME: "$CI_REGISTRY_IMAGE/app"
|
||||||
WEB_IMAGE_NAME: "registry.ely.by/elyby/accounts-nginx"
|
WEB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/web"
|
||||||
DB_IMAGE_NAME: "registry.ely.by/elyby/accounts-mariadb"
|
DB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/db"
|
||||||
|
|
||||||
php-cs-fixer:
|
#######################
|
||||||
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
|
# Shared script steps #
|
||||||
stage: test
|
#######################
|
||||||
|
|
||||||
|
# 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:
|
cache:
|
||||||
key: backend-vendor
|
key: backend-deps
|
||||||
paths:
|
paths:
|
||||||
- vendor
|
- 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:
|
script:
|
||||||
- composer install
|
|
||||||
- vendor/bin/php-cs-fixer fix -v --dry-run
|
- vendor/bin/php-cs-fixer fix -v --dry-run
|
||||||
|
|
||||||
codeception:
|
Codeception:
|
||||||
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
|
stage: testing
|
||||||
|
extends:
|
||||||
|
- .vendorCache
|
||||||
services:
|
services:
|
||||||
- name: redis:4.0.10-alpine
|
- name: redis:4.0.10-alpine
|
||||||
alias: redis
|
alias: redis
|
||||||
@ -45,103 +88,67 @@ codeception:
|
|||||||
MYSQL_DATABASE: "ely_accounts_test"
|
MYSQL_DATABASE: "ely_accounts_test"
|
||||||
MYSQL_USER: "ely_accounts_tester"
|
MYSQL_USER: "ely_accounts_tester"
|
||||||
MYSQL_PASSWORD: "ely_accounts_tester_password"
|
MYSQL_PASSWORD: "ely_accounts_tester_password"
|
||||||
stage: test
|
|
||||||
cache:
|
|
||||||
key: backend-vendor
|
|
||||||
paths:
|
|
||||||
- vendor
|
|
||||||
before_script:
|
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
|
- sudo rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
||||||
script:
|
script:
|
||||||
- composer install
|
|
||||||
- php yii rbac/generate
|
- php yii rbac/generate
|
||||||
- ./docker/php/wait-for-it.sh "${DB_HOST}:3306" -s -t 0 -- "php yii migrate/up --interactive=0"
|
- ./docker/php/wait-for-it.sh "${DB_HOST}:3306" -s -t 0 -- "php yii migrate/up --interactive=0"
|
||||||
- vendor/bin/codecept run
|
- vendor/bin/codecept run
|
||||||
|
|
||||||
build:production:
|
###############
|
||||||
image: docker:18.02
|
# Build stage #
|
||||||
|
###############
|
||||||
|
|
||||||
|
Docker images:
|
||||||
stage: build
|
stage: build
|
||||||
|
image: docker:19.03.2
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
before_script:
|
before_script:
|
||||||
- *defineVersion
|
- *defineVars
|
||||||
- *loginIntoRegistry
|
- *dockerLogin
|
||||||
- sed -i -e "s/{{PLACE_VERSION_HERE}}/$VERSION/g" common/config/config.php
|
- sed -i -e "s/{{PLACE_VERSION_HERE}}/$VERSION/g" common/config/config.php
|
||||||
script:
|
script:
|
||||||
- docker pull "$APP_IMAGE_NAME:latest"
|
# Download previous images to use them as a cache
|
||||||
- docker pull "$WEB_IMAGE_NAME:latest"
|
- docker pull "$APP_LATEST_IMAGE_NAME" || true
|
||||||
- docker pull "$DB_IMAGE_NAME:latest"
|
- docker pull "$WEB_LATEST_IMAGE_NAME" || true
|
||||||
|
- docker pull "$DB_LATEST_IMAGE_NAME" || true
|
||||||
|
# Build images
|
||||||
- >
|
- >
|
||||||
docker build
|
docker build
|
||||||
--pull
|
--pull
|
||||||
--target app
|
--target app
|
||||||
--build-arg "build_env=prod"
|
--build-arg "build_env=prod"
|
||||||
--cache-from "$APP_IMAGE_NAME:latest"
|
--cache-from "$APP_LATEST_IMAGE_NAME"
|
||||||
-t "$APP_IMAGE_NAME:$CI_PIPELINE_ID" .
|
-t "$APP_VERSIONED_IMAGE_NAME"
|
||||||
|
-t "$APP_LATEST_IMAGE_NAME" .
|
||||||
- >
|
- >
|
||||||
docker build
|
docker build
|
||||||
--pull
|
--pull
|
||||||
--target web
|
--target web
|
||||||
--build-arg "build_env=prod"
|
--build-arg "build_env=prod"
|
||||||
--cache-from "$APP_IMAGE_NAME:$CI_PIPELINE_ID"
|
--cache-from "$APP_VERSIONED_IMAGE_NAME"
|
||||||
--cache-from "$WEB_IMAGE_NAME:latest"
|
--cache-from "$WEB_LATEST_IMAGE_NAME"
|
||||||
-t "$WEB_IMAGE_NAME:$CI_PIPELINE_ID" .
|
-t "$WEB_VERSIONED_IMAGE_NAME"
|
||||||
|
-t "$WEB_LATEST_IMAGE_NAME" .
|
||||||
- >
|
- >
|
||||||
docker build
|
docker build
|
||||||
--pull
|
--pull
|
||||||
--target db
|
--target db
|
||||||
--build-arg "build_env=prod"
|
--build-arg "build_env=prod"
|
||||||
--cache-from "$APP_IMAGE_NAME:$CI_PIPELINE_ID"
|
--cache-from "$APP_VERSIONED_IMAGE_NAME"
|
||||||
--cache-from "$DB_IMAGE_NAME:latest"
|
--cache-from "$WEB_VERSIONED_IMAGE_NAME"
|
||||||
-t "$DB_IMAGE_NAME:$CI_PIPELINE_ID" .
|
--cache-from "$DB_LATEST_IMAGE_NAME"
|
||||||
|
-t "$DB_VERSIONED_IMAGE_NAME"
|
||||||
|
-t "$DB_LATEST_IMAGE_NAME" .
|
||||||
|
# Push images to the registry
|
||||||
|
- docker push $APP_IMAGE_VERSIONED_NAME
|
||||||
|
- docker push $APP_IMAGE_LATEST_NAME
|
||||||
|
- docker push $WEB_IMAGE_VERSIONED_NAME
|
||||||
|
- docker push $WEB_IMAGE_LATEST_NAME
|
||||||
|
- docker push $DB_IMAGE_VERSIONED_NAME
|
||||||
|
- docker push $DB_IMAGE_LATEST_NAME
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- tags
|
- 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"
|
|
||||||
|
|
||||||
- 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:
|
|
||||||
stage: cleanup
|
|
||||||
variables:
|
|
||||||
GIT_STRATEGY: none
|
|
||||||
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
|
|
||||||
when: always
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user