-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
107 lines (92 loc) · 3.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
image: fhyx/golang:edge
stages:
- lint
- test
- deploy
services:
- name: redis:5-alpine
alias: redis
- name: fhyx/postgresql:15e
alias: auroradb
variables:
DEVELOP_HOST: moon
DEPLOY_HOST: earth
DEPLOY_USER: sa
DEPLOY_ROOT: /opt/morrigan
CGO_ENABLED: '0'
GO111MODULE: 'on'
GOPATH: /cache/go
GOPRIVATE: daxv.cn,hyyl.xyz
GOPROXY: https://goproxy.io,direct
NAME: morrigan
ROOF: github/liut/morrigan
DB_NAME: morrigantest
DB_USER: morrigan
DB_PASS: develop
PG_EXTENSIONS: 'btree_gin btree_gist pg_trgm'
MORRIGAN_PG_STORE_DSN: postgres://morrigan:develop@morrigandb:5432/morrigantest?sslmode=disable
MORRIGAN_REDIS_URI: 'redis://redis:6379/0'
before_script:
# SSH
- mkdir -p ~/.ssh
- test -f /secret/sa_id_ecdsa && cp /secret/sa_id_ecdsa ~/.ssh/id_ecdsa || (echo "$SSH_PRIVATE_KEY") > ~/.ssh/id_ecdsa
- chmod 0600 ~/.ssh/id_ecdsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# - ls -al ~/.ssh/
- eval $(ssh-agent -s)
# Go Environments
- go env
- export DATE=$(date '+%Y%m%d')
- export TAG="${DATE}-${CI_COMMIT_SHORT_SHA}-${CI_JOB_ID}"
- echo "${TAG}"
- echo -e "Host ${DEVELOP_HOST:-moon}\n\tPort ${DEVELOP_PORT:-22}\n\tUser ${DEVELOP_USER:-sa}\n\n" >> ~/.ssh/config
- echo -e "Host ${DEPLOY_HOST:-earth}\n\tPort ${DEPLOY_PORT:-22}\n\tUser ${DEPLOY_USER:-sa}\n\n" >> ~/.ssh/config
test-lint:
stage: lint
services: []
script:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- go vet ./... && ${GOPATH}/bin/golangci-lint --disable structcheck run ./...
test-stores:
stage: test
script:
- go test -v -cover ./pkg/services/stores
test-initdb:
stage: test
script:
- go run . initdb
only:
changes:
- data/schemas/*.sql
deploy-to-testing:
stage: deploy
services: []
script:
- export LDFLAGS="-X ${ROOF}/pkg/settings.name=${NAME} -X ${ROOF}/pkg/settings.version=${TAG}"
- mkdir -p dist/linux_amd64
- GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS} -s -w" -o dist/linux_amd64/${NAME} ${CI_PROJECT_DIR}
- ssh ${DEVELOP_USER:-sa}@${DEVELOP_HOST:-moon} "test -d dist || mkdir dist"
- scp dist/linux_amd64/${NAME} ${DEVELOP_USER:-sa}@${DEVELOP_HOST:-moon}:dist/
# - ssh ${DEVELOP_USER:-sa}@${DEVELOP_HOST:-moon} "test -d ${DEPLOY_ROOT}/bin && sudo install dist/${NAME} ${DEPLOY_ROOT}/bin/ && sudo systemctl restart '${NAME}*'"
only:
- main
when: on_success
deploy-to-staging:
stage: deploy
services: []
script:
- export LDFLAGS="-X ${ROOF}/pkg/settings.name=${NAME} -X ${ROOF}/pkg/settings.version=${TAG}"
- mkdir -p dist/linux_amd64
- GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS} -s -w" -o dist/linux_amd64/${NAME} ${CI_PROJECT_DIR}
- ls dist/linux_amd64 | xargs tar -cvJf ${NAME}-linux-amd64-${TAG}.tar.xz -C dist/linux_amd64
- scp *-linux-amd64-*.tar.?z "${DEPLOY_HOST:-earth}:gopkg/cupola/"
- ssh ${DEPLOY_USER:-sa}@${DEPLOY_HOST:-earth} "test -d dist && tar -xvJf gopkg/cupola/${NAME}-linux-amd64-${TAG}.tar.xz -C dist"
# - ssh ${DEPLOY_USER:-sa}@${DEPLOY_HOST:-earth} "test -d ${DEPLOY_ROOT}/bin && sudo install dist/${NAME} ${DEPLOY_ROOT}/bin/ && sudo systemctl restart '${NAME}*'"
artifacts:
name: "${CI_PROJECT_PATH_SLUG}_${CI_JOB_ID}"
paths:
- dist/
only:
- main
- /^release-.+$/
when: manual