Skip to content

Commit 6c440c4

Browse files
author
dmitriy
committed
added staging environment, gitlab ci integration, refactoring
1 parent 83151de commit 6c440c4

31 files changed

+3222
-692
lines changed

.env.staging

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the staging env here
2+
APP_ENV=staging
3+
APP_SECRET=42f011ec3a7bde0bec87364b1d967194
4+
APP_DEBUG=0

.gitlab-ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
image: docker:latest
2+
3+
variables:
4+
DOCKER_DRIVER: overlay2
5+
DOCKER_TLS_CERTDIR: ""
6+
GITLAB_CI: 1
7+
8+
services:
9+
- docker:dind
10+
11+
before_script:
12+
- apk update
13+
- apk upgrade
14+
- apk add --no-cache make bash docker-compose && rm -rf /var/cache/apk/*
15+
16+
stages:
17+
- build
18+
- deploy
19+
20+
.general_scripts: &general_scripts
21+
- make info
22+
23+
build:
24+
stage: build
25+
script:
26+
- docker-compose -f docker-compose-test-ci.yml build
27+
- make start-test
28+
- docker ps -a
29+
- make wait-for-db
30+
- make drop-migrate
31+
- make messenger-setup-transports
32+
- *general_scripts
33+
- make phpunit
34+
- make ecs
35+
- make phpcs
36+
- make stop-test
37+
artifacts:
38+
paths:
39+
- reports/
40+
only:
41+
- merge_requests
42+
- tags
43+
- master
44+
- develop
45+
46+
push_staging_images:
47+
stage: deploy
48+
script:
49+
- docker-compose -f docker-compose-staging.yml build
50+
# TODO: set necessary image name in docker-compose-staging.yml according to your registry and edit lines bellow
51+
#- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
52+
#- docker-compose -f docker-compose-staging.yml push
53+
only:
54+
- master
55+
- develop
56+
57+
push_prod_images:
58+
stage: deploy
59+
script:
60+
- docker-compose -f docker-compose-prod.yml build
61+
# TODO: set necessary image name in docker-compose-prod.yml according to your registry and edit lines bellow
62+
#- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
63+
#- docker-compose -f docker-compose-prod.yml push
64+
only:
65+
- master
66+
- /^release.*$/

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ ENV APP_HOME /var/www/html
1111
RUN if [ "$BUILD_ARGUMENT_ENV" = "default" ]; then echo "Set BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev" && exit 2; \
1212
elif [ "$BUILD_ARGUMENT_ENV" = "dev" ]; then echo "Building development environment."; \
1313
elif [ "$BUILD_ARGUMENT_ENV" = "test" ]; then echo "Building test environment."; \
14+
elif [ "$BUILD_ARGUMENT_ENV" = "staging" ]; then echo "Building staging environment."; \
1415
elif [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then echo "Building production environment."; \
15-
else echo "Set correct BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev. Available choices are dev,test,prod." && exit 2; \
16+
else echo "Set correct BUILD_ARGUMENT_ENV in docker build-args like --build-arg BUILD_ARGUMENT_ENV=dev. Available choices are dev,test,staging,prod." && exit 2; \
1617
fi
1718

1819
# install all the dependencies and enable PHP modules
@@ -87,8 +88,8 @@ RUN if [ "$BUILD_ARGUMENT_ENV" = "dev" ] || [ "$BUILD_ARGUMENT_ENV" = "test" ];
8788
else export APP_ENV=$BUILD_ARGUMENT_ENV && COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader --no-interaction --no-progress --no-dev; \
8889
fi
8990

90-
# create cached config file .env.local.php in case prod environment
91-
RUN if [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then composer dump-env $BUILD_ARGUMENT_ENV; \
91+
# create cached config file .env.local.php in case staging/prod environment
92+
RUN if [ "$BUILD_ARGUMENT_ENV" = "staging" ] || [ "$BUILD_ARGUMENT_ENV" = "prod" ]; then composer dump-env $BUILD_ARGUMENT_ENV; \
9293
fi
9394

9495
USER root

Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ interactive:=$(shell [ -t 0 ] && echo 1)
66
ifneq ($(interactive),1)
77
optionT=-T
88
endif
9+
ifeq ($(GITLAB_CI),1)
10+
# Determine additional params for phpunit in order to generate coverage badge on GitLabCI side
11+
phpunitOptions=--coverage-text --colors=never
12+
endif
913

1014
ifndef APP_ENV
11-
# Determine which .env file to use
15+
include .env
16+
# Determine if .env.local file exist
1217
ifneq ("$(wildcard .env.local)","")
1318
include .env.local
14-
else
15-
include .env
1619
endif
1720
endif
1821

@@ -22,6 +25,9 @@ start:
2225
start-test:
2326
@docker-compose -f docker-compose-test-ci.yml $(project) up -d
2427

28+
start-staging:
29+
@docker-compose -f docker-compose-staging.yml $(project) up -d
30+
2531
start-prod:
2632
@docker-compose -f docker-compose-prod.yml $(project) up -d
2733

@@ -31,16 +37,23 @@ stop:
3137
stop-test:
3238
@docker-compose -f docker-compose-test-ci.yml $(project) down
3339

40+
stop-staging:
41+
@docker-compose -f docker-compose-staging.yml $(project) down
42+
3443
stop-prod:
3544
@docker-compose -f docker-compose-prod.yml $(project) down
3645

3746
restart: stop start
3847
restart-test: stop-test start-test
48+
restart-staging: stop-staging start-staging
3949
restart-prod: stop-prod start-prod
4050

4151
env-prod:
4252
@make exec cmd="composer dump-env prod"
4353

54+
env-staging:
55+
@make exec cmd="composer dump-env staging"
56+
4457
###> lexik/jwt-authentication-bundle ###
4558
generate-jwt-keys:
4659
@make exec cmd="make generate-jwt-keys-process"
@@ -90,7 +103,7 @@ report-clean:
90103
wait-for-db:
91104
@make exec cmd="php bin/console db:wait"
92105

93-
composer-install-prod:
106+
composer-install-no-dev:
94107
@make exec-bash cmd="COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader --no-dev"
95108

96109
composer-install:
@@ -123,7 +136,7 @@ drop-migrate:
123136
@make exec cmd="php bin/console doctrine:schema:drop --full-database --force --env=test"
124137
@make migrate
125138

126-
migrate-prod:
139+
migrate-no-test:
127140
@make exec cmd="php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing"
128141

129142
migrate:
@@ -143,7 +156,7 @@ messenger-setup-transports:
143156
@make exec cmd="php bin/console messenger:setup-transports"
144157

145158
phpunit:
146-
@make exec-bash cmd="rm -rf ./var/cache/test* && bin/console cache:warmup --env=test && ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/coverage --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
159+
@make exec-bash cmd="rm -rf ./var/cache/test* && bin/console cache:warmup --env=test && ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/coverage $(phpunitOptions) --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
147160

148161
###> php-coveralls ###
149162
report-code-coverage: ## update code coverage on coveralls.io. Note: COVERALLS_REPO_TOKEN should be set on CI side.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"easycorp/easy-log-handler": "1.0.*",
3939
"jmose/command-scheduler-bundle": "^2.2",
4040
"lexik/jwt-authentication-bundle": "^2.6",
41-
"mark-gerarts/automapper-plus-bundle": "^1.2",
41+
"mark-gerarts/automapper-plus-bundle": "^1.3",
4242
"matthiasnoback/symfony-console-form": "^3.6",
4343
"nelmio/api-doc-bundle": "^3.6",
4444
"nelmio/cors-bundle": "^2.0",
@@ -88,7 +88,7 @@
8888
"ergebnis/composer-normalize": "^2.3",
8989
"roave/security-advisories": "dev-master",
9090
"symfony/debug-pack": "*",
91-
"symfony/maker-bundle": "^1.15",
91+
"symfony/maker-bundle": "^1.17",
9292
"symfony/requirements-checker": "^1.1"
9393
},
9494
"config": {

0 commit comments

Comments
 (0)