Skip to content

Commit ad0bf89

Browse files
author
dmitriy
committed
improved environment
1 parent 3ce2838 commit ad0bf89

32 files changed

+6406
-1686
lines changed

.env.dev

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
###> docker-compose configuration ###
2+
COMPOSE_PROJECT_NAME=environment3
3+
###< docker-compose configuration ###
4+
15
APP_NAME=Laravel
26
APP_ENV=dev
37
APP_KEY=base64:KgeWah2LwOk5HLjCYuIZjaQQwX59ASqUjCKZMD6H4Ew=

.env.prod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
###> docker-compose configuration ###
2+
COMPOSE_PROJECT_NAME=environment3
3+
###< docker-compose configuration ###
4+
15
APP_NAME=Laravel
26
APP_ENV=prod
37
APP_KEY=

.env.staging

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
###> docker-compose configuration ###
2+
COMPOSE_PROJECT_NAME=environment3
3+
###< docker-compose configuration ###
4+
5+
APP_NAME=Laravel
6+
APP_ENV=staging
7+
APP_KEY=
8+
APP_DEBUG=false
9+
APP_URL=http://localhost
10+
11+
LOG_CHANNEL=stack
12+
13+
DB_CONNECTION=mysql
14+
DB_HOST=mysql
15+
DB_PORT=3306
16+
DB_DATABASE=laravel
17+
DB_USERNAME=root
18+
DB_PASSWORD=secret
19+
20+
BROADCAST_DRIVER=log
21+
CACHE_DRIVER=file
22+
QUEUE_CONNECTION=sync
23+
SESSION_DRIVER=file
24+
SESSION_LIFETIME=120
25+
26+
REDIS_HOST=127.0.0.1
27+
REDIS_PASSWORD=null
28+
REDIS_PORT=6379
29+
30+
MAIL_DRIVER=smtp
31+
MAIL_HOST=smtp.mailtrap.io
32+
MAIL_PORT=2525
33+
MAIL_USERNAME=null
34+
MAIL_PASSWORD=null
35+
MAIL_ENCRYPTION=null
36+
MAIL_FROM_ADDRESS=null
37+
MAIL_FROM_NAME="${APP_NAME}"
38+
39+
AWS_ACCESS_KEY_ID=
40+
AWS_SECRET_ACCESS_KEY=
41+
AWS_DEFAULT_REGION=us-east-1
42+
AWS_BUCKET=
43+
44+
PUSHER_APP_ID=
45+
PUSHER_APP_KEY=
46+
PUSHER_APP_SECRET=
47+
PUSHER_APP_CLUSTER=mt1
48+
49+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
50+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
###> docker-compose configuration ###
2+
COMPOSE_PROJECT_NAME=environment3
3+
###< docker-compose configuration ###
4+
15
APP_NAME=Laravel
26
APP_ENV=test
37
APP_KEY=base64:KgeWah2LwOk5HLjCYuIZjaQQwX59ASqUjCKZMD6H4Ew=

.env.test-ci

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# by default test environment using .env.test. So all tests will use the same database. If you need to separate it, just use make env-test-ci command and then run migrations and seed.
2+
###> docker-compose configuration ###
3+
COMPOSE_PROJECT_NAME=environment3
4+
###< docker-compose configuration ###
5+
26
APP_NAME=Laravel
37
APP_ENV=test
48
APP_KEY=base64:KgeWah2LwOk5HLjCYuIZjaQQwX59ASqUjCKZMD6H4Ew=

.github/workflows/ci.yml

Lines changed: 1 addition & 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

.gitlab-ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
- make build-test
27+
- make start-test
28+
- docker ps -a
29+
- make wait-for-db
30+
- make drop-migrate
31+
- make seed
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+
- make build-staging
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+
- /^release.*$/
57+
58+
push_prod_images:
59+
stage: deploy
60+
script:
61+
- make build-prod
62+
# TODO: set necessary image name in docker-compose-prod.yml according to your registry and edit lines bellow
63+
#- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
64+
#- docker-compose -f docker-compose-prod.yml push
65+
only:
66+
- master
67+
- /^release.*$/

Dockerfile

Lines changed: 2 additions & 1 deletion
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

Makefile

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
dir=${CURDIR}
2-
project=-p laravel
3-
service=laravel:latest
2+
3+
ifndef APP_ENV
4+
include .env
5+
endif
6+
7+
project=-p ${COMPOSE_PROJECT_NAME}
8+
service=${COMPOSE_PROJECT_NAME}:latest
49
interactive:=$(shell [ -t 0 ] && echo 1)
510
ifneq ($(interactive),1)
611
optionT=-T
712
endif
13+
ifeq ($(GITLAB_CI),1)
14+
# Determine additional params for phpunit in order to generate coverage badge on GitLabCI side
15+
phpunitOptions=--coverage-text --colors=never
16+
endif
17+
18+
build:
19+
@docker-compose -f docker-compose.yml build
20+
21+
build-test:
22+
@docker-compose -f docker-compose-test-ci.yml build
23+
24+
build-staging:
25+
@docker-compose -f docker-compose-staging.yml build
26+
27+
build-prod:
28+
@docker-compose -f docker-compose-prod.yml build
829

930
start:
1031
@docker-compose -f docker-compose.yml $(project) up -d
1132

1233
start-test:
1334
@docker-compose -f docker-compose-test-ci.yml $(project) up -d
1435

36+
start-staging:
37+
@docker-compose -f docker-compose-staging.yml $(project) up -d
38+
1539
start-prod:
1640
@docker-compose -f docker-compose-prod.yml $(project) up -d
1741

@@ -21,11 +45,15 @@ stop:
2145
stop-test:
2246
@docker-compose -f docker-compose-test-ci.yml $(project) down
2347

48+
stop-staging:
49+
@docker-compose -f docker-compose-staging.yml $(project) down
50+
2451
stop-prod:
2552
@docker-compose -f docker-compose-prod.yml $(project) down
2653

2754
restart: stop start
2855
restart-test: stop-test start-test
56+
restart-staging: stop-staging start-staging
2957
restart-prod: stop-prod start-prod
3058

3159
env-dev:
@@ -61,7 +89,7 @@ report-clean:
6189
wait-for-db:
6290
@make exec cmd="php artisan db:wait"
6391

64-
composer-install-prod:
92+
composer-install-no-dev:
6593
@make exec-bash cmd="COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader --no-dev"
6694

6795
composer-install:
@@ -70,27 +98,31 @@ composer-install:
7098
composer-update:
7199
@make exec-bash cmd="COMPOSER_MEMORY_LIMIT=-1 composer update"
72100

101+
key-generate:
102+
@make exec cmd="php artisan key:generate"
103+
73104
info:
74105
@make exec cmd="php artisan --version"
106+
@make exec cmd="php artisan env"
75107
@make exec cmd="php --version"
76108

77109
logs:
78-
@docker logs -f laravel
110+
@docker logs -f ${COMPOSE_PROJECT_NAME}_laravel
79111

80112
logs-nginx:
81-
@docker logs -f nginx
113+
@docker logs -f ${COMPOSE_PROJECT_NAME}_nginx
82114

83115
logs-supervisord:
84-
@docker logs -f supervisord
116+
@docker logs -f ${COMPOSE_PROJECT_NAME}_supervisord
85117

86118
logs-mysql:
87-
@docker logs -f mysql
119+
@docker logs -f ${COMPOSE_PROJECT_NAME}_mysql
88120

89121
drop-migrate:
90122
@make exec cmd="php artisan migrate:fresh"
91123
@make exec cmd="php artisan migrate:fresh --env=test"
92124

93-
migrate-prod:
125+
migrate-no-test:
94126
@make exec cmd="php artisan migrate --force"
95127

96128
migrate:
@@ -101,7 +133,7 @@ seed:
101133
@make exec cmd="php artisan db:seed --force"
102134

103135
phpunit:
104-
@make exec cmd="./vendor/bin/phpunit -c phpunit.xml --coverage-html reports/coverage --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
136+
@make exec cmd="./vendor/bin/phpunit -c phpunit.xml --coverage-html reports/coverage $(phpunitOptions) --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
105137

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

bitbucket-pipelines.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ pipelines:
99
script:
1010
- chmod +x .bitbucket/dependencies.sh
1111
- .bitbucket/dependencies.sh
12-
- docker-compose -f docker-compose-test-ci.yml build
12+
- make build-test
1313
- make start-test
1414
- docker ps -a
1515
- make wait-for-db
1616
- make drop-migrate
1717
- make seed
18+
- make info
1819
- make phpunit
1920
- make ecs
2021
- make phpcs

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"authors": [
1717
{
1818
"name": "Dmitriy Kravtsov",
19-
"email": "[email protected]",
19+
"email": "[email protected]",
2020
"homepage": "https://github.com/dimadeush",
2121
"role": "Developer"
2222
}
@@ -35,9 +35,9 @@
3535
"laravel/tinker": "^2.0"
3636
},
3737
"require-dev": {
38-
"bamarni/composer-bin-plugin": "^1.3",
39-
"barryvdh/laravel-ide-helper": "^2.6",
40-
"ergebnis/composer-normalize": "^2.3",
38+
"bamarni/composer-bin-plugin": "^1.4",
39+
"barryvdh/laravel-ide-helper": "^2.8",
40+
"ergebnis/composer-normalize": "^2.7",
4141
"facade/ignition": "^1.4",
4242
"fzaninotto/faker": "^1.9",
4343
"mockery/mockery": "^1.0",

0 commit comments

Comments
 (0)