2019-12-29 20:53:20 +05:30
|
|
|
image: edbizarro/gitlab-ci-pipeline-php:7.4-alpine
|
2019-11-05 17:40:37 +05:30
|
|
|
|
2016-08-09 12:23:05 +05:30
|
|
|
stages:
|
2019-11-05 17:40:37 +05:30
|
|
|
- prepare
|
|
|
|
- testing
|
2019-08-03 18:46:08 +05:30
|
|
|
- build
|
2019-08-04 00:20:34 +05:30
|
|
|
|
2016-08-09 12:23:05 +05:30
|
|
|
variables:
|
2019-11-05 17:40:37 +05:30
|
|
|
APP_IMAGE_NAME: "$CI_REGISTRY_IMAGE/app"
|
|
|
|
WEB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/web"
|
|
|
|
DB_IMAGE_NAME: "$CI_REGISTRY_IMAGE/db"
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# 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"
|
2016-08-09 12:23:05 +05:30
|
|
|
|
2019-11-05 17:40:37 +05:30
|
|
|
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:
|
2019-08-03 18:46:08 +05:30
|
|
|
cache:
|
2019-11-05 17:40:37 +05:30
|
|
|
key: backend-deps
|
2019-08-03 18:46:08 +05:30
|
|
|
paths:
|
|
|
|
- vendor
|
2019-11-05 17:40:37 +05:30
|
|
|
policy: pull
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Prepare stage #
|
|
|
|
#################
|
|
|
|
|
2020-05-21 18:49:28 +05:30
|
|
|
Composer:
|
2019-11-05 17:40:37 +05:30
|
|
|
stage: prepare
|
|
|
|
extends:
|
|
|
|
- .vendorCache
|
|
|
|
cache:
|
|
|
|
policy: pull-push
|
2019-12-15 07:56:45 +05:30
|
|
|
before_script:
|
|
|
|
- sudo apk add --update --no-cache patch
|
2019-11-05 17:40:37 +05:30
|
|
|
script:
|
|
|
|
- composer install --ignore-platform-reqs
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Testing stage #
|
|
|
|
#################
|
|
|
|
|
|
|
|
PHP-CS-Fixer:
|
|
|
|
stage: testing
|
|
|
|
extends:
|
|
|
|
- .vendorCache
|
2019-08-03 18:46:08 +05:30
|
|
|
script:
|
|
|
|
- vendor/bin/php-cs-fixer fix -v --dry-run
|
2018-07-10 22:32:19 +05:30
|
|
|
|
2019-11-05 17:40:37 +05:30
|
|
|
Codeception:
|
|
|
|
stage: testing
|
|
|
|
extends:
|
|
|
|
- .vendorCache
|
2019-08-03 18:46:08 +05:30
|
|
|
services:
|
|
|
|
- name: redis:4.0.10-alpine
|
|
|
|
alias: redis
|
2019-11-15 22:33:52 +05:30
|
|
|
- name: bitnami/mariadb:10.3.20-debian-9-r4
|
2019-08-03 18:46:08 +05:30
|
|
|
alias: db
|
|
|
|
variables:
|
|
|
|
# App config
|
|
|
|
DB_HOST: "db"
|
|
|
|
DB_DATABASE: "ely_accounts_test"
|
|
|
|
DB_USER: "ely_accounts_tester"
|
|
|
|
DB_PASSWORD: "ely_accounts_tester_password"
|
|
|
|
REDIS_HOST: "redis"
|
|
|
|
REDIS_PORT: "6379"
|
|
|
|
# MariaDB config
|
2019-11-15 22:39:19 +05:30
|
|
|
ALLOW_EMPTY_PASSWORD: "yes"
|
2019-11-15 22:33:52 +05:30
|
|
|
MARIADB_DATABASE: "ely_accounts_test"
|
|
|
|
MARIADB_USER: "ely_accounts_tester"
|
|
|
|
MARIADB_PASSWORD: "ely_accounts_tester_password"
|
2019-08-03 18:46:08 +05:30
|
|
|
before_script:
|
2019-11-05 17:40:37 +05:30
|
|
|
# We don't count code coverage yet, so xdebug can be removed
|
2019-08-03 18:46:08 +05:30
|
|
|
- sudo rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
|
|
|
script:
|
|
|
|
- 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
|
2016-08-09 12:23:05 +05:30
|
|
|
|
2019-11-05 17:40:37 +05:30
|
|
|
###############
|
|
|
|
# Build stage #
|
|
|
|
###############
|
|
|
|
|
2020-05-21 18:49:28 +05:30
|
|
|
Docker:
|
2019-08-03 18:46:08 +05:30
|
|
|
stage: build
|
2020-05-21 18:49:28 +05:30
|
|
|
image: docker:19.03.9-dind
|
2019-08-03 18:46:08 +05:30
|
|
|
before_script:
|
2019-11-05 17:40:37 +05:30
|
|
|
- *defineVars
|
|
|
|
- *dockerLogin
|
2019-08-03 18:46:08 +05:30
|
|
|
- sed -i -e "s/{{PLACE_VERSION_HERE}}/$VERSION/g" common/config/config.php
|
|
|
|
script:
|
2019-11-05 17:40:37 +05:30
|
|
|
# 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
|
2019-08-03 18:46:08 +05:30
|
|
|
- >
|
|
|
|
docker build
|
|
|
|
--pull
|
|
|
|
--target app
|
|
|
|
--build-arg "build_env=prod"
|
2019-11-05 17:40:37 +05:30
|
|
|
--cache-from "$APP_LATEST_IMAGE_NAME"
|
|
|
|
-t "$APP_VERSIONED_IMAGE_NAME"
|
|
|
|
-t "$APP_LATEST_IMAGE_NAME" .
|
2019-08-03 18:46:08 +05:30
|
|
|
- >
|
|
|
|
docker build
|
|
|
|
--pull
|
|
|
|
--target web
|
|
|
|
--build-arg "build_env=prod"
|
2019-11-05 17:40:37 +05:30
|
|
|
--cache-from "$APP_VERSIONED_IMAGE_NAME"
|
|
|
|
--cache-from "$WEB_LATEST_IMAGE_NAME"
|
|
|
|
-t "$WEB_VERSIONED_IMAGE_NAME"
|
|
|
|
-t "$WEB_LATEST_IMAGE_NAME" .
|
2019-08-03 18:46:08 +05:30
|
|
|
- >
|
|
|
|
docker build
|
|
|
|
--pull
|
|
|
|
--target db
|
|
|
|
--build-arg "build_env=prod"
|
2019-11-05 17:40:37 +05:30
|
|
|
--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
|
2019-11-05 17:57:07 +05:30
|
|
|
- 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
|