-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
169 lines (153 loc) · 4.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
stages:
- build-container
- test
- deploy
variables:
GIT_SUBMODULE_STRATEGY: none
SSH_PRIVATE_KEY: $LIBWEBRUNNER_PRIVATE_KEY
SSH_USER: $SSH_DEPLOY_USER
SSH_SERVER: $SSH_DEPLOY_SERVER
# Include before_script to download utilities repo & run scripts
include: 'https://content.library.unt.edu/www/utilities/raw/master/scripts/gitlab-ci/.before-script-utils-repo.yml'
########################
# Build container stage
########################
.build-container:
stage: build-container
tags:
- dind
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $FULL_IMAGE_NAME || true
- docker build --cache-from $FULL_IMAGE_NAME -f Dockerfile -t $FULL_IMAGE_NAME .
- docker push $FULL_IMAGE_NAME
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- if: '$CI_PIPELINE_SOURCE == "trigger"'
when: never
- changes:
- Dockerfile*
- .gitlab-ci.yml
- Gemfile*
- package*.json
- yarn.lock
when: always
- when: manual
allow_failure: true
build-container:alpha:
extends: .build-container
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/alpha:latest
RAILS_PORT: 3000
RAILS_ENV: development
RAILS_SERVE_STATIC_FILES: "false"
build-container:beta:
extends: .build-container
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/beta:latest
RAILS_PORT: 3100
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: "true"
build-container:production:
extends: .build-container
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/production:latest
RAILS_PORT: 3200
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: "true"
#############
# Test stage
#############
test:
tags:
- dind
stage: test
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
ADD_PACKAGES: py-pip python-dev libffi-dev openssl-dev gcc libc-dev make docker-compose-plugin
RAILS_PORT: 3300
RAILS_ENV: test
RAILS_SERVE_STATIC_FILES: "true"
script:
- "docker info"
- "echo \"$RAILS_MASTER_KEY\" >> .env"
- "docker compose build"
- "docker compose run --rm web rake db:create"
- "docker compose run --rm web rake db:migrate"
- "docker compose run --rm web rails assets:precompile"
- "docker compose run --rm web bundle exec rspec --format documentation"
- "docker compose down"
when: manual
###############
# Deploy stage
###############
.deploy:
stage: deploy
image: $CI_REGISTRY/www/utilities/deploy:latest
variables:
GIT_SUBMODULE_STRATEGY: none
GIT_BRANCH: master
SITE_DEST_DIR: /var/www/html/$CI_ENVIRONMENT_URL
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
before_script:
- source /app/prepare_ssh.sh
script:
- ssh $SSH_USER@$SSH_SERVER "
cd $SITE_DEST_DIR &&
git fetch --all &&
git checkout -f $CI_COMMIT_SHA &&
rm -f .env &&
echo APP_IMAGE_NAME=$FULL_IMAGE_NAME >> .env &&
echo RAILS_PORT=$RAILS_PORT >> .env &&
echo RAILS_ENV=$RAILS_ENV >> .env &&
echo NODE_ENV=$RAILS_ENV >> .env &&
echo RAILS_SERVE_STATIC_FILES=$RAILS_SERVE_STATIC_FILES >> .env &&
echo POSTGRES_PASSWORD=$POSTGRES_PASSWORD >> .env &&
echo RAILS_MASTER_KEY=$RAILS_MASTER_KEY >> .env &&
echo WEB_CONCURRENCY=$WEB_CONCURRENCY >> .env &&
docker compose pull &&
docker compose up -d &&
docker compose exec -T web rails assets:precompile &&
docker compose restart
"
when: manual
deploy:alpha:
extends: .deploy
environment:
name: alpha
url: alpha.discover.library.unt.edu
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/alpha:latest
RAILS_PORT: 3000
RAILS_ENV: development
RAILS_SERVE_STATIC_FILES: "false"
WEB_CONCURRENCY: 1
deploy:beta:
extends: .deploy
environment:
name: beta
url: beta.discover.library.unt.edu
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/beta:latest
RAILS_PORT: 3100
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: "true"
WEB_CONCURRENCY: 1
deploy:production:
extends: .deploy
environment:
name: production
url: discover.library.unt.edu
variables:
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE/production:latest
RAILS_PORT: 3200
RAILS_ENV: production
RAILS_SERVE_STATIC_FILES: "true"
WEB_CONCURRENCY: 8