accounts/.gitlab-ci.yml

176 lines
4.5 KiB
YAML
Raw Normal View History

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
- build
2019-11-05 17:57:07 +05:30
- cleanup
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:
cache:
2019-11-05 17:40:37 +05:30
key: backend-deps
paths:
- vendor
2019-11-05 17:40:37 +05:30
policy: pull
#################
# Prepare stage #
#################
Precache dependencies:
stage: prepare
extends:
- .vendorCache
cache:
policy: pull-push
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
script:
- vendor/bin/php-cs-fixer fix -v --dry-run
2019-11-05 17:40:37 +05:30
Codeception:
stage: testing
extends:
- .vendorCache
services:
- name: redis:4.0.10-alpine
alias: redis
- name: bitnami/mariadb:10.3.20-debian-9-r4
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"
MARIADB_DATABASE: "ely_accounts_test"
MARIADB_USER: "ely_accounts_tester"
MARIADB_PASSWORD: "ely_accounts_tester_password"
before_script:
2019-11-05 17:40:37 +05:30
# 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:
- 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 #
###############
Docker images:
stage: build
2019-11-05 17:40:37 +05:30
image: docker:19.03.2
before_script:
2019-11-05 17:40:37 +05:30
- *defineVars
- *dockerLogin
- 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
- >
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" .
- >
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" .
- >
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
#################
# Cleanup stage #
#################
2019-11-05 17:58:18 +05:30
Remove Docker images:
2019-11-05 17:57:07 +05:30
stage: cleanup
image: docker:19.03.2
variables:
GIT_STRATEGY: none
2019-11-05 18:01:23 +05:30
before_script:
- *defineVars
2019-11-05 17:57:07 +05:30
script:
- 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