-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.gitlab-ci.yml
89 lines (83 loc) · 2.81 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
variables:
ANSIBLE_PROJECT: atlas_aws_chatlas
APP: playground_app
DOCKER_IMAGE_URL: "registry.gitlab.com/atlasconsulting/devops/atlas-aws-test"
DOCKER_IMAGE_TAG: "v3.2"
DOCKER_NAME: "build-$CI_COMMIT_SHORT_SHA-$CI_JOB_ID"
RUN_CHECK_FORMAT: 0 # skip check format for now
RUN_CHECK_LINT: 0 # skip check lint for now
stages:
- check
- build
- deploy-test
- deploy-prod
check_project:
stage: check
before_script:
- docker pull $DOCKER_IMAGE_URL:$DOCKER_IMAGE_TAG
- docker run -d --rm --mount type=bind,source=$CI_PROJECT_DIR,target=/home --name=$DOCKER_NAME $DOCKER_IMAGE_URL:$DOCKER_IMAGE_TAG -c "/bin/sleep 300"
script:
# check code formatting and lint using `RUN_CHECK_*` vars as flags
- if [ $RUN_CHECK_FORMAT -ne 0 ]; then docker exec $DOCKER_NAME bash -c "cd /home && npm run check-format"; fi;
- if [ $RUN_CHECK_LINT -ne 0 ]; then docker exec $DOCKER_NAME bash -c "cd /home && npm run check-lint"; fi;
rules:
- when: always
build_package:
stage: build
before_script:
- ansible-update.sh $ANSIBLE_PROJECT
- sudo chown -R www-data:www-data $CI_PROJECT_DIR
- echo "Creating package $APP-$CI_COMMIT_SHORT_SHA"
script:
- cd /opt/ansible/$ANSIBLE_PROJECT
- |
venv/bin/ansible-playbook package-apps.yml \
-i inventory/test.hosts \
-e "target=test" \
-e "docker_image_url=$DOCKER_IMAGE_URL" \
-e "docker_image_tag=$DOCKER_IMAGE_TAG" \
-e "{\"deploy\":[\"$APP\"]}" \
-e "pack_suffix=$CI_COMMIT_SHORT_SHA" \
-e "{\"deploy_options\":{\"$APP\":{\"mount\":\"$CI_PROJECT_DIR\"}}}"
rules:
- if: $APP != null
deploy_test:
timeout: 20m
stage: deploy-test
needs: ['build_package']
before_script:
- ansible-update.sh $ANSIBLE_PROJECT
- echo "Deploying package $APP-$CI_COMMIT_SHORT_SHA in TEST"
script:
- cd /opt/ansible/$ANSIBLE_PROJECT
- |
venv/bin/ansible-playbook s3-deploy-apps.yml \
-i inventory/test.hosts \
-e "target=test" \
-e "pack_suffix=$CI_COMMIT_SHORT_SHA" \
-e "{\"deploy\": [\"$APP\"], \"archive\":\"yes\"}"
rules:
- when: manual
- if: $APP != null
# set allow_failure to `true` to avoid `blocked` pipeline status
allow_failure: true
deploy_production:
timeout: 20m
stage: deploy-prod
needs: ['build_package']
before_script:
- ansible-update.sh $ANSIBLE_PROJECT
- echo "Deploying package $APP-$CI_COMMIT_SHORT_SHA in PROD"
script:
- cd /opt/ansible/$ANSIBLE_PROJECT
- |
venv/bin/ansible-playbook s3-deploy-apps.yml \
-i inventory/production.hosts \
-e "target=production" \
-e "pack_suffix=$CI_COMMIT_SHORT_SHA" \
-e "{\"deploy\": [\"$APP\"], \"archive\":\"yes\"}"
rules:
- when: manual
- if: $APP != null
# set allow_failure to `true` to avoid `blocked` pipeline status
allow_failure: true