-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
185 lines (171 loc) · 6.29 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
image: golang:latest
cache:
key: golang-cache
paths:
- vendor/
before_script:
- echo deb http://deb.debian.org/debian/ stretch main > /etc/apt/sources.list
- ln -s /builds /go/src/jba.io
- cd /go/src/jba.io/go/thing
- export GOCACHE="/cache/go"
#- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
#- eval $(ssh-agent -s)
#- ssh-add <(echo "$SSH_PRIVATE_KEY")
#- mkdir -p ~/.ssh
#- '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
stages:
- install-environment
- get-deps
- build-css
- build
- test
- package
- deploy
install-go:
stage: install-environment
script:
- go version
- echo $PATH
- echo $GOPATH
- go env
- which go
get-deps:
stage: get-deps
script:
- curl -o dep -sL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
- chmod +x dep
- ./dep ensure -v
- go get -d -v
build-css:
stage: build-css
script:
- curl -sL https://deb.nodesource.com/setup_6.x | bash -
- apt-get update -y && apt-get install -y nodejs
- npm install -g bower gulp
- /bin/sh ./build_css.sh
artifacts:
expire_in: 1 day
paths:
- assets/css/thing.css
- assets/css/thing.css.map
build-my-project:
stage: build
script:
- curl -o dep -sL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
- chmod +x dep
- ./dep ensure -v
- go get -d github.com/shurcooL/vfsgen
- cd vfs/assets && go get -d && cd ../../
- cd vfs/templates && go get -d && cd ../../
- go get -d -v
- go generate ./...
- go build -o ./thing
artifacts:
expire_in: 1 day
paths:
- thing
- vfs/templates/templates_vfsdata.go
- vfs/assets/assets_vfsdata.go
test-my-project:
stage: test
coverage: '/coverage: \d+\.\d+/'
script:
- curl -o dep -sL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
- chmod +x dep
- ./dep ensure -v
- go get -d -v
- go test -v
- go test -race
- go test -cover
build-package:
stage: package
script:
- apt update && apt install -y build-essential devscripts debhelper
- cp thing gothing
- dch -M -v 1.0-$CI_COMMIT_REF_NAME-$CI_JOB_ID "New version from Git" && dch -M -r -D stretch ""
- debuild -us -uc -b
- mv ../gothing_*_amd64.deb gothing.deb
artifacts:
expire_in: 1 day
paths:
- gothing.deb
#deploy_to_repo:
# stage: deploy
# variables:
# DEPLOY_HOST: '[email protected]'
# script:
# - scp ./*.deb $DEPLOY_HOST:/home/repo/
# - ssh $DEPLOY_HOST reprepro -b www/debian/ includedeb stretch *.deb
deploy_to_prod:
stage: deploy
variables:
DEPLOY_HOST: '[email protected]'
script:
- scp gothing.deb $DEPLOY_HOST:/home/deploy/
- ssh $DEPLOY_HOST sudo dpkg -i gothing.deb
only:
- master
deploy_to_staging:
stage: deploy
variables:
DEPLOY_HOST: '[email protected]'
script:
- scp gothing.deb $DEPLOY_HOST:/home/deploy/
- ssh $DEPLOY_HOST sudo dpkg -i gothing.deb
when: manual
#deploy_staging:
# stage: deploy
# variables:
# DEPLOY_HOST: '[email protected]'
# SERVICE_MANAGER: 'systemctl --user'
# script:
# - tar -cf $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar thing assets/ templates/
# - scp $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar $DEPLOY_HOST:$CI_PROJECT_NAME.$CI_COMMIT_SHA.tar
# - ssh $DEPLOY_HOST ./helper -app thing -tar $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar -svc "golang@thing"
# ## scp to fresh folder
# #- scp -r ./ $DEPLOY_HOST:$CI_PROJECT_NAME.$CI_COMMIT_SHA
# ## Stop app, to release DB locks
# #- ssh $DEPLOY_HOST $SERVICE_MANAGER stop golang@$CI_PROJECT_NAME
# ## If $CI_PROJECT_NAME exists, and is not a symlink, fail here since the next step fails otherwise
# #- ssh $DEPLOY_HOST /bin/bash -c "'if test -d $CI_PROJECT_NAME -a ! -L $CI_PROJECT_NAME; then echo ERROR $CI_PROJECT_NAME is not a symlink && exit 1; fi'"
# ## If $CI_PROJECT_NAME.new exists, fail here since this is a sign of a failed previous deployment
# #- ssh $DEPLOY_HOST /bin/bash -c "'if test -d $CI_PROJECT_NAME.new; then echo ERROR $CI_PROJECT_NAME.new exists && exit 1; fi'"
# ## Create symlink from $CI_PROJECT_NAME.$CI_COMMIT_SHA to $CI_PROJECT_NAME.new
# #- ssh $DEPLOY_HOST ln -sv $CI_PROJECT_NAME.$CI_COMMIT_SHA $CI_PROJECT_NAME.new
# ## Move $CI_PROJECT_NAME.new into place, overwriting old symlink
# #- ssh $DEPLOY_HOST mv -T $CI_PROJECT_NAME.new $CI_PROJECT_NAME
# ## Restart app
# #- ssh $DEPLOY_HOST $SERVICE_MANAGER start golang@$CI_PROJECT_NAME
# environment:
# name: staging
# url: http://thing.rick.jba.io
# when: manual
#deploy_prod:
# stage: deploy
# variables:
# DEPLOY_HOST: '[email protected]'
# # using sudo due to no systemctl --user on CentOS 7 (https://bugs.centos.org/view.php?id=8767)
# #SERVICE_MANAGER: 'sudo systemctl'
# script:
# - tar -cf $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar thing assets/ templates/
# - scp $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar $DEPLOY_HOST:$CI_PROJECT_NAME.$CI_COMMIT_SHA.tar
# - ssh $DEPLOY_HOST ./helper -app thing -tar $CI_PROJECT_NAME.$CI_COMMIT_SHA.tar -svc "golang@thing" -sudo true
# ## scp to fresh folder
# #- scp -r ./ $DEPLOY_HOST:$CI_PROJECT_NAME.$CI_COMMIT_SHA
# ## Stop app, to release DB locks
# #- ssh $DEPLOY_HOST $SERVICE_MANAGER stop golang@$CI_PROJECT_NAME
# ## If $CI_PROJECT_NAME exists, and is not a symlink, fail here since the next step fails otherwise
# #- ssh $DEPLOY_HOST /bin/bash -c "'if test -d $CI_PROJECT_NAME -a ! -L $CI_PROJECT_NAME; then echo ERROR $CI_PROJECT_NAME is not a symlink && exit 1; fi'"
# ## If $CI_PROJECT_NAME.new exists, fail here since this is a sign of a failed previous deployment
# #- ssh $DEPLOY_HOST /bin/bash -c "'if test -d $CI_PROJECT_NAME.new; then echo ERROR $CI_PROJECT_NAME.new exists && exit 1; fi'"
# ## Create symlink from $CI_PROJECT_NAME.$CI_COMMIT_SHA to $CI_PROJECT_NAME.new
# #- ssh $DEPLOY_HOST ln -sv $CI_PROJECT_NAME.$CI_COMMIT_SHA $CI_PROJECT_NAME.new
# ## Move $CI_PROJECT_NAME.new into place, overwriting old symlink
# #- ssh $DEPLOY_HOST mv -T $CI_PROJECT_NAME.new $CI_PROJECT_NAME
# ## Restart app
# #- ssh $DEPLOY_HOST $SERVICE_MANAGER start golang@$CI_PROJECT_NAME
# environment:
# name: production
# url: https://squanch.space
# only:
# - master