.gitlab-ci.yml 3.16 KB
Newer Older
1
image: gitlab.cs.wallawalla.edu:5050/elock/doorcode:latest
2
3

services:
4
  - postgres:13-alpine
Jacob Priddy's avatar
Jacob Priddy committed
5

6
variables:
7
8
9
  POSTGRES_USER: web
  POSTGRES_PASSWORD: secret
  POSTGRES_DB: doorcode
Jacob Priddy's avatar
Jacob Priddy committed
10
11
  DOORCODE_IMAGE_NAME: doorcode/app:$CI_PIPELINE_ID
  NGINX_IMAGE_NAME: doorcode/web:$CI_PIPELINE_ID
12
13

stages:
Jacob Priddy's avatar
Jacob Priddy committed
14
  - build
15
  - test
16
  - coverage
17
  - deploy
18

Jacob Priddy's avatar
Jacob Priddy committed
19
20
21
22
23
24
25
26
27
28
29
build_web_backend:
  stage: build
  script:
    - src/backend/install-dev.sh
  artifacts:
    paths:
      - src/backend/vendor
      - src/backend/.env
      - src/backend/composer.lock
    # Currently set to build timeout
    expire_in: 1 day
Jacob Priddy's avatar
Jacob Priddy committed
30

Jacob Priddy's avatar
Jacob Priddy committed
31
32
33
34
35
36
37
38
39
40
#build_web_frontend:
#  stage: build
#  script:
#    - cd src/frontend
#    - npm install
#    - npm run build --mode=production --dest=dist
#  artifacts:
#    paths:
#      - src/frontend/dist
#    expire_in: 1 day
Jacob Priddy's avatar
Jacob Priddy committed
41

42
43
44
45
46
test_php_styles:
  stage: test
  script:
    - cd src/backend
    - vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --stop-on-violation --using-cache=no
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
test_web_backend_unit:
  stage: test
  script:
    - cd src/backend
    - vendor/bin/phpunit --testsuite Unit

test_web_backend_feature:
  stage: test
  script:
    - cd src/backend
    - vendor/bin/phpunit --testsuite Feature

test_web_backend_database:
  stage: test
  script:
    - cd src/backend
    - vendor/bin/phpunit --testsuite Database

generate_api_docs:
  stage: coverage
  script:
    - cd src/backend
    - sed -i 's/\(^APP_ENV=\).*/\1memory/' .env
Jacob Priddy's avatar
Jacob Priddy committed
71
72
    - sed -i "s/\(^APP_URL=\).*/\1https:\/\/${DEPLOY_ADDRESS}/" .env
    - "if (php artisan scribe:generate | grep \"Exception\") then echo \"Failed to generate API docs.\" && false; else true; fi"
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  artifacts:
    paths:
      - src/backend/public/docs
    expire_in: 1 day

generate_code_coverage:
  stage: coverage
  script:
    - cd src/backend
    - phpdbg -qrr -d memory_limit=256M vendor/bin/phpunit --coverage-html cov
  artifacts:
    paths:
      - src/backend/cov
    expire_in: 30 days
87

Jacob Priddy's avatar
Jacob Priddy committed
88
89
90
91
deploy application:
  image: tiangolo/docker-with-compose
  tags:
    - elock
92
93
  stage: deploy
  script:
Jacob Priddy's avatar
Jacob Priddy committed
94
95
96
97
98
99
100
101
    # Delete previous unneeded artifacts
    - >
      rm -rf src/backend/cov
      src/backend/vendor
      src/backend/tests
      src/frontend
      src/install-dev.sh
      src/backend/node_modules
102
      src/backend/.env
Jacob Priddy's avatar
Jacob Priddy committed
103
104
    - docker-compose -f docker-compose.prod.yml build
    - sed -i "s/\(^DB_PASSWORD=\).*/\1$(cat $POSTGRES_PASSWORD)/" $PROJ_DIR/.env
105
    - cp $PROJ_DIR/.env src/backend/.env
106
107
    - docker build -t $DOORCODE_IMAGE_NAME -f prod.Dockerfile .
    - docker build --build-arg APP_IMAGE=$DOORCODE_IMAGE_NAME -t $NGINX_IMAGE_NAME -f nginx.Dockerfile .
Jacob Priddy's avatar
Jacob Priddy committed
108
    - docker stack deploy -c docker-compose.prod.yml doorcode --prune
Jacob Priddy's avatar
Jacob Priddy committed
109
    # Give it some time to spin up...
Jacob Priddy's avatar
Jacob Priddy committed
110
    - sleep 120
Jacob Priddy's avatar
Jacob Priddy committed
111
    # Make sure app is running
112
113
    - "curl --fail --insecure --silent --location https://${DEPLOY_ADDRESS}/api > /dev/null"
    - "curl --fail --insecure --silent --location https://${DEPLOY_ADDRESS}/api/docs > /dev/null"
114
  environment:
Jacob Priddy's avatar
Jacob Priddy committed
115
    name: production
Jacob Priddy's avatar
Jacob Priddy committed
116
    url: https://elock.cs.wallawalla.edu/api
Jacob Priddy's avatar
Jacob Priddy committed
117
    on_stop: stop-prod
118
  when: manual
Jacob Priddy's avatar
Jacob Priddy committed
119
  only:
120
    - master
Jacob Priddy's avatar
Jacob Priddy committed
121

Jacob Priddy's avatar
Jacob Priddy committed
122
stop-prod:
123
124
  stage: deploy
  script:
Jacob Priddy's avatar
Jacob Priddy committed
125
    - docker stack rm doorcode
126
127
  only:
    - master
Jacob Priddy's avatar
Jacob Priddy committed
128
129
130
131
  when: manual
  environment:
    name: production
    action: stop