-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
executable file
·72 lines (66 loc) · 2.48 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
before_script:
- echo "[$CI_JOB_NAME] Job for $CI_PROJECT_NAME started by $GITLAB_USER_NAME"
.setup-project: &setup-project
before_script:
- mkdir -p /docker-data/$CI_PROJECT_NAME
- cp -n -R src/storage /docker-data/$CI_PROJECT_NAME/
# - chown -R 1000:1000 /docker-data/$CI_PROJECT_NAME
- >
[[ ! -f "/docker-data/$CI_PROJECT_NAME/.env" ]] && echo APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) > /docker-data/$CI_PROJECT_NAME/.env && echo "laravel app key set";
stages:
- build
- test
- deploy
build-project:
<<: *setup-project
tags:
- shell-runner
stage: build
script:
- cp .env.staging .env #docker staging settings
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker-compose -f docker-compose.yml -f docker-compose.staging.yml build --pull
- docker-compose -f docker-compose.yml -f docker-compose.staging.yml push
only:
- staging
build-prod-project:
<<: *setup-project
tags:
- shell-runner
stage: build
script:
- cp .env.staging .env #docker staging settings
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker-compose -f docker-compose.yml -f docker-compose.production.yml build --pull
- docker-compose -f docker-compose.yml -f docker-compose.production.yml push
only:
- master
run-tests:
tags:
- shell-runner
stage: test
script:
- echo "tests"
only:
- master
deploy-staging:
stage: deploy
tags:
- shell-runner
environment:
name: review/$CI_COMMIT_REF_NAME
script:
- cp -u -p .env.staging .env #THIS IS FOR DOCKER!! -u update if newer, -p preserver permissions, -n do not copy if exists
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker-compose -f docker-compose.yml -f docker-compose.staging.yml pull
- docker-compose -f docker-compose.yml -f docker-compose.staging.yml down
- docker-compose -f docker-compose.yml -f docker-compose.staging.yml up -d
- docker exec ${CI_PROJECT_NAME}-php chown -R www-data:www-data {/app/storage,/app/public}
- docker exec ${CI_PROJECT_NAME}-php find /app -type f -exec chmod 644 {} \;
- docker exec ${CI_PROJECT_NAME}-php find /app -type d -exec chmod 755 {} \;
- docker exec ${CI_PROJECT_NAME}-php php artisan migrate:fresh --seed --force
- docker exec ${CI_PROJECT_NAME}-php php artisan view:clear
- docker exec ${CI_PROJECT_NAME}-php php artisan cache:clear
only:
- staging
when: on_success