~hokiegeek/biologist-web

ref: 3.0.2 biologist-web/.gitlab-ci.yml -rw-r--r-- 4.0 KiB View raw
8c657b44HokieGeek Pushing this to both Hub and GCR, for the time being 9 months ago
                                                                                
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
170
171
172
173
174
175
image: node:10-alpine

stages:
    - build
    - test
    - release
    - deploy

variables:
    PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"
    CHROME_BIN: "/usr/bin/chromium-browser"

cache:
  paths:
    - node_modules/
    - dist/

.build-template: &build-template
  stage: build
  before_script:
    - npm install
  script:
    - npm run ng -- build
  after_script:
    - version=$(awk 'BEGIN { FS=":"; RS="," } $1 ~ /"version"/ { gsub(/( |")/, "", $0); print $2 }' package.json)
    - sed -i '/^<head>$/ a\    <meta name="application-name" content="hokiegeek.net_life" data-version="'${version}${version_suffix:+":${version_suffix}"}'" />' dist/index.html
    - head dist/index.html

.build-snapshot:
  <<: *build-template
  variables:
    version_suffix: "SNAPSHOT"
  only:
    - master
  except:
    - tags

build-branch:
  <<: *build-template
  variables:
    version_suffix: $CI_COMMIT_REF_NAME
  only:
    - branches
  except:
    - master

build-release:
  <<: *build-template
  script:
    - npm run build # Run optimized build
  only:
    - tags

## Linting
.lint-template: &lint-template
  stage: build
  script:
    - npm install
    - npm run lint
  retry: 1

lint:
  <<: *lint-template
  only:
    - tags

lint-warn:
  <<: *lint-template
  except:
    - master
    - tags
  allow_failure: true

## Unit testing
.node-unit-test: &node-unit-test
  stage: test
  before_script:
    - apk update && apk upgrade
    - echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
    - echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories
    - apk add --no-cache chromium@edge nss@edge
  script:
    - npm run test
  only:
    - branches
    - tags
  except:
    - master
  retry: 2
  allow_failure: true
      # coverage: /TODO/

unit-node:10:
  <<: *node-unit-test
  allow_failure: false

unit-node:latest:
  <<: *node-unit-test
  image: node:alpine

## Create container
.build-docker-image: &build-docker-image
  stage: release
  image: docker:git
  services:
    - docker:dind
  before_script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  script:
    - head dist/index.html
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
  retry: 1

create-container-dev:
  <<: *build-docker-image
  variables:
    IMAGE_TAG: $CI_REGISTRY_IMAGE:SNAPSHOT
  except:
    - tags
    - master

create-container:
  <<: *build-docker-image
  variables:
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
    IMAGE_LATEST_TAG: $CI_REGISTRY_IMAGE:latest
  after_script:
    - docker tag $IMAGE_TAG $IMAGE_LATEST_TAG
    - docker push $IMAGE_LATEST_TAG
  only:
    - tags
  except:
    - branches

.server-connector-template: &server-connector-template
  image: alpine:latest
  before_script:
    - apk add --update --no-cache openssh
    - echo $HOST_SSH_KEY | base64 -d > /tmp/sshkey
    - chmod 0600 /tmp/sshkey

add-proxy-server:
  <<: *server-connector-template
  stage: deploy
  script:
    - scp -i /tmp/sshkey -o StrictHostKeyChecking=no ./prod-conf/proxy-life.conf $ADMIN_USER@${DEPLOY_HOST}:/tmp
    - ssh -i /tmp/sshkey -o StrictHostKeyChecking=no $ADMIN_USER@${DEPLOY_HOST} "sudo mv /tmp/proxy-life.conf /etc/nginx/conf.d"
    - ssh -i /tmp/sshkey -o StrictHostKeyChecking=no $ADMIN_USER@${DEPLOY_HOST} "sudo systemctl restart hgproxy.service"
  only:
    - tags
  except:
    - branches

## Service restarter
.service-restarter: &service-restarter
  <<: *server-connector-template
  stage: deploy
  script:
    - scp -i /tmp/sshkey -o StrictHostKeyChecking=no ./prod-conf/${SERVICE} $ADMIN_USER@${DEPLOY_HOST}:/tmp
    - ssh -i /tmp/sshkey -o StrictHostKeyChecking=no $ADMIN_USER@${DEPLOY_HOST} "sudo mv /tmp/${SERVICE} /etc/systemd/system/ && sudo systemctl daemon-reload"
    - ssh -i /tmp/sshkey -o StrictHostKeyChecking=no $ADMIN_USER@${DEPLOY_HOST} "sudo systemctl enable ${SERVICE}; sudo systemctl restart ${SERVICE}"
  retry: 1

restart-service:
  <<: *service-restarter
  variables:
    SERVICE: hglife.service
  environment:
    name: production
    url: http://life.hokiegeek.net
  only:
    - tags
  except:
    - branches