Skip to content

Commit 87e0539

Browse files
author
dmitriy
committed
Added ElasticSearch + Kibana, improved environment
1 parent 7ab56d4 commit 87e0539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4359
-1593
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ jobs:
1515
make start-test
1616
1717
- run:
18-
name: Wait for DB container is running and initialize DB & messenger component
18+
name: Wait for DB container is running and initialize DB & messenger component / cron / elastic
1919
command: |
2020
make wait-for-db
2121
make drop-migrate
2222
make generate-jwt-keys
2323
make create-roles-groups
24+
make migrate-cron-jobs
2425
make messenger-setup-transports
26+
make wait-for-elastic
27+
make elastic-create-or-update-template
2528
2629
- run:
2730
name: Run unit/functional tests

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/public/bundles/
1010
/var/mysql-data
1111
/var/rabbitmq
12+
/var/elasticsearch-data
1213
/vendor/
1314
/tools/*/vendor/
1415

.env

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
1414
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
1515

16+
###> docker-compose configuration ###
17+
COMPOSE_PROJECT_NAME=backend
18+
###< docker-compose configuration ###
19+
1620
###> symfony/framework-bundle ###
1721
APP_ENV=dev
1822
APP_DEBUG=1
@@ -30,13 +34,25 @@ DATABASE_URL=mysql://root:secret@mysql:3306/symfony
3034
###< doctrine/doctrine-bundle ###
3135

3236
###> symfony/mailer ###
33-
# MAILER_DSN=smtp://localhost
37+
MAILER_DSN=smtp://user:pass@smtp.example.com
38+
APP_SENDER_EMAIL=admin@localhost
39+
APP_EMAIL_NOTIFICATION_ABOUT_ERROR=1
40+
APP_ERROR_RECEIVER_EMAIL=admin@localhost
3441
###< symfony/mailer ###
3542

3643
###> symfony/messenger ###
3744
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages
3845
###< symfony/messenger ###
3946

47+
###> Elasticsearch configuration ###
48+
ELK_VERSION=7.8.0
49+
ELASTICSEARCH_HOST=http://elasticsearch:9200
50+
ELASTICSEARCH_NUMBER_OF_SHARDS=1
51+
ELASTICSEARCH_NUMBER_OF_REPLICAS=0
52+
ELASTICSEARCH_USERNAME=elastic
53+
ELASTICSEARCH_PASSWORD=changeme
54+
###< Elasticsearch configuration ###
55+
4056
###> lexik/jwt-authentication-bundle ###
4157
JWT_SECRET_KEY=config/jwt/private.pem
4258
JWT_PUBLIC_KEY=config/jwt/public.pem
@@ -48,6 +64,9 @@ JWT_TOKEN_TTL=3600
4864
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
4965
###< nelmio/cors-bundle ###
5066

67+
# how many failure attempts for lock account, 0 - off
68+
LOCK_USER_ON_LOGIN_FAILURE_ATTEMPTS=0
69+
5170
# how many days health history will be stored in the db
5271
DATABASE_HEALTH_HISTORY_DAYS=7
5372

.env.prod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ APP_DEBUG=0
77
DATABASE_URL=mysql://root:secret@mysql:3306/symfony
88
###< doctrine/doctrine-bundle ###
99

10+
###> symfony/mailer ###
11+
MAILER_DSN=smtp://user:pass@smtp.example.com?encryption=tls
12+
APP_SENDER_EMAIL=admin@localhost
13+
APP_EMAIL_NOTIFICATION_ABOUT_ERROR=1
14+
APP_ERROR_RECEIVER_EMAIL=admin@localhost
15+
###< symfony/mailer ###
16+
1017
###> symfony/messenger ###
1118
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages
1219
###< symfony/messenger ###
20+
21+
###> Elasticsearch configuration ###
22+
ELASTICSEARCH_HOST=http://elasticsearch:9200
23+
ELASTICSEARCH_NUMBER_OF_SHARDS=1
24+
ELASTICSEARCH_NUMBER_OF_REPLICAS=0
25+
ELASTICSEARCH_USERNAME=elastic
26+
ELASTICSEARCH_PASSWORD=changeme
27+
###< Elasticsearch configuration ###

.env.staging

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,24 @@
22
APP_ENV=staging
33
APP_SECRET=42f011ec3a7bde0bec87364b1d967194
44
APP_DEBUG=0
5+
6+
###> doctrine/doctrine-bundle ###
7+
DATABASE_URL=mysql://root:secret@mysql:3306/symfony
8+
###< doctrine/doctrine-bundle ###
9+
10+
###> symfony/mailer ###
11+
MAILER_DSN=smtp://user:pass@smtp.example.com?encryption=tls
12+
APP_SENDER_EMAIL=admin@localhost
13+
APP_EMAIL_NOTIFICATION_ABOUT_ERROR=1
14+
APP_ERROR_RECEIVER_EMAIL=admin@localhost
15+
###< symfony/mailer ###
16+
17+
###> symfony/messenger ###
18+
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f/messages
19+
###< symfony/messenger ###
20+
21+
###> Elasticsearch configuration ###
22+
ELASTICSEARCH_HOST=http://elasticsearch:9200
23+
ELASTICSEARCH_USERNAME=elastic
24+
ELASTICSEARCH_PASSWORD=changeme
25+
###< Elasticsearch configuration ###

.env.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ KERNEL_CLASS='App\Kernel'
44
APP_SECRET='$ecretf0rt3st'
55
APP_DEBUG=0
66
SYMFONY_DEPRECATIONS_HELPER=999999
7+
8+
###> doctrine/doctrine-bundle ###
79
DATABASE_URL=mysql://root:secret@mysql:3306/symfony_testing
10+
###< doctrine/doctrine-bundle ###

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v1
2323
- name: Build the docker images
24-
run: docker-compose -f docker-compose-test-ci.yml build
24+
run: make build-test
2525
- name: Start the docker images
2626
run: make start-test
2727
- name: Check running containers
@@ -34,8 +34,14 @@ jobs:
3434
run: make generate-jwt-keys
3535
- name: Create roles and groups
3636
run: make create-roles-groups
37+
- name: Create cron jobs
38+
run: make migrate-cron-jobs
3739
- name: Setup transports for Messenger component
3840
run: make messenger-setup-transports
41+
- name: Wait for Elastic connection
42+
run: make wait-for-elastic
43+
- name: Create or update Elastic index template
44+
run: make elastic-create-or-update-template
3945
- name: Run test suite
4046
run: make phpunit
4147
- name: Run coding standard

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ reports/*
88
/.env.*.local
99
/config/secrets/prod/prod.decrypt.private.php
1010
/public/bundles/
11-
/var/
11+
/var/*
12+
!/var/elasticsearch-data/nodes/0/.gitkeep
1213
/vendor/
1314
/tools/**/vendor
1415
###< symfony/framework-bundle ###

.gitlab-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ stages:
2323
build:
2424
stage: build
2525
script:
26-
- docker-compose -f docker-compose-test-ci.yml build
26+
- make build-test
2727
- make start-test
2828
- docker ps -a
2929
- make wait-for-db
3030
- make drop-migrate
3131
- make generate-jwt-keys
3232
- make create-roles-groups
33+
- make migrate-cron-jobs
3334
- make messenger-setup-transports
35+
- make wait-for-elastic
36+
- make elastic-create-or-update-template
3437
- *general_scripts
3538
- make phpunit
3639
- make ecs
@@ -48,18 +51,19 @@ build:
4851
push_staging_images:
4952
stage: deploy
5053
script:
51-
- docker-compose -f docker-compose-staging.yml build
54+
- make build-staging
5255
# TODO: set necessary image name in docker-compose-staging.yml according to your registry and edit lines bellow
5356
#- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
5457
#- docker-compose -f docker-compose-staging.yml push
5558
only:
5659
- master
5760
- develop
61+
- /^release.*$/
5862

5963
push_prod_images:
6064
stage: deploy
6165
script:
62-
- docker-compose -f docker-compose-prod.yml build
66+
- make build-prod
6367
# TODO: set necessary image name in docker-compose-prod.yml according to your registry and edit lines bellow
6468
#- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
6569
#- docker-compose -f docker-compose-prod.yml push

Makefile

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
dir=${CURDIR}
2-
project=-p symfony
3-
service=symfony:latest
2+
3+
ifndef APP_ENV
4+
include .env
5+
# Determine if .env.local file exist
6+
ifneq ("$(wildcard .env.local)","")
7+
include .env.local
8+
endif
9+
endif
10+
11+
project=-p ${COMPOSE_PROJECT_NAME}
12+
service=${COMPOSE_PROJECT_NAME}:latest
413
openssl_bin:=$(shell which openssl)
514
interactive:=$(shell [ -t 0 ] && echo 1)
615
ifneq ($(interactive),1)
@@ -11,13 +20,17 @@ ifeq ($(GITLAB_CI),1)
1120
phpunitOptions=--coverage-text --colors=never
1221
endif
1322

14-
ifndef APP_ENV
15-
include .env
16-
# Determine if .env.local file exist
17-
ifneq ("$(wildcard .env.local)","")
18-
include .env.local
19-
endif
20-
endif
23+
build:
24+
@docker-compose -f docker-compose.yml build
25+
26+
build-test:
27+
@docker-compose -f docker-compose-test-ci.yml build
28+
29+
build-staging:
30+
@docker-compose -f docker-compose-staging.yml build
31+
32+
build-prod:
33+
@docker-compose -f docker-compose-prod.yml build
2134

2235
start:
2336
@docker-compose -f docker-compose.yml $(project) up -d
@@ -88,6 +101,12 @@ ssh-mysql:
88101
ssh-rabbitmq:
89102
@docker-compose $(project) exec rabbitmq /bin/sh
90103

104+
ssh-elasticsearch:
105+
@docker-compose $(project) exec elasticsearch bash
106+
107+
ssh-kibana:
108+
@docker-compose $(project) exec kibana bash
109+
91110
exec:
92111
@docker-compose $(project) exec $(optionT) symfony $$cmd
93112

@@ -103,6 +122,9 @@ report-clean:
103122
wait-for-db:
104123
@make exec cmd="php bin/console db:wait"
105124

125+
wait-for-elastic:
126+
@make exec cmd="php bin/console elastic:wait"
127+
106128
composer-install-no-dev:
107129
@make exec-bash cmd="COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader --no-dev"
108130

@@ -117,19 +139,25 @@ info:
117139
@make exec cmd="php --version"
118140

119141
logs:
120-
@docker logs -f symfony
142+
@docker logs -f ${COMPOSE_PROJECT_NAME}_symfony
121143

122144
logs-nginx:
123-
@docker logs -f nginx
145+
@docker logs -f ${COMPOSE_PROJECT_NAME}_nginx
124146

125147
logs-supervisord:
126-
@docker logs -f supervisord
148+
@docker logs -f ${COMPOSE_PROJECT_NAME}_supervisord
127149

128150
logs-mysql:
129-
@docker logs -f mysql
151+
@docker logs -f ${COMPOSE_PROJECT_NAME}_mysql
130152

131153
logs-rabbitmq:
132-
@docker logs -f rabbitmq
154+
@docker logs -f ${COMPOSE_PROJECT_NAME}_rabbitmq
155+
156+
logs-elasticsearch:
157+
@docker logs -f ${COMPOSE_PROJECT_NAME}_elasticsearch
158+
159+
logs-kibana:
160+
@docker logs -f ${COMPOSE_PROJECT_NAME}_kibana
133161

134162
drop-migrate:
135163
@make exec cmd="php bin/console doctrine:schema:drop --full-database --force"
@@ -155,6 +183,9 @@ create-roles-groups:
155183
messenger-setup-transports:
156184
@make exec cmd="php bin/console messenger:setup-transports"
157185

186+
elastic-create-or-update-template:
187+
@make exec cmd="php bin/console elastic:create-or-update-template"
188+
158189
phpunit:
159190
@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"
160191

0 commit comments

Comments
 (0)