This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
147 lines (137 loc) · 4.56 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
image: "golang:latest"
variables:
# Tell 'docker:dind' to enable TLS (recommended)
# and generate certificates in the specified directory.
DOCKER_TLS_CERTDIR: "/certs"
stages:
- test
- build
- deploy
test-cov:
stage: test
variables:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: defaultdb
services:
- name: postgres:latest
alias: db-host
script:
- go install github.com/boumenot/gocover-cobertura@latest
- go test $(go list ./... | grep -v /vendor/) -ldflags "-X 'dev.sum7.eu/genofire/golang-lib/web/webtest.DBConnection=postgres://root:root@db-host/defaultdb?sslmode=disable'" -v -failfast -p 1 -coverprofile .testCoverage.txt -covermode count
- go tool cover -func="$CI_PROJECT_DIR/.testCoverage.txt"
- gocover-cobertura < .testCoverage.txt > coverage.xml
artifacts:
reports:
coverage_report:
coverage_format: "cobertura"
path: "coverage.xml"
paths:
- .testCoverage.txt
- coverage.xml
test-lint:
stage: test
script:
- go install github.com/client9/misspell/cmd/misspell@latest
- find . -type f -not -path "./webroot/assets" | grep -v "models/.*_testdata.*.go" | xargs misspell -error
- ./.ci/check-gofmt
- ./.ci/check-testfiles
test-docs:
stage: test
script:
- go install github.com/swaggo/swag/cmd/swag@latest
- swag init --parseDependency --parseDepth 4 --parseInternal -g web/docs.go -o web/docs
build-linux:
stage: build
except:
- tags
- master
- main
script:
# build doc
- go install github.com/swaggo/swag/cmd/swag@latest
- swag init --parseDependency --parseDepth 4 --parseInternal -g web/docs.go -o web/docs
# build app with version
- export CGO_ENABLED=0
- go install -ldflags "-X main.VERSION=$CI_COMMIT_TAG" .
- mv "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_DIR/$CI_PROJECT_NAME"
artifacts:
paths:
- config_example.toml
- "$CI_PROJECT_NAME"
build-docker-latest:
stage: build
image: docker:latest
services:
- docker:dind
only:
- master
- main
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --build-arg VERSION=$CI_COMMIT_TAG
-t $CI_REGISTRY_IMAGE:latest
.
- docker push $CI_REGISTRY_IMAGE:latest
build-docker-release:
stage: build
image: docker:latest
services:
- docker:dind
only:
- tags
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --build-arg VERSION=$CI_COMMIT_TAG
-t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
-t $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%\.[0-9]*}
-t $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%\.[0-9]*\.[0-9]*}
.
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%\.[0-9]*}
- docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%\.[0-9]*\.[0-9]*}
build-deploy_staging:
stage: deploy
only:
- master
- main
script:
# build doc
- go install github.com/swaggo/swag/cmd/swag@latest
- swag init --parseDependency --parseDepth 4 --parseInternal -g web/docs.go -o web/docs
# setup ssh for deploy
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -p $CI_DEPLOY_PORT $CI_DEPLOY_ADDR >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# build app with version + deploy
- export CGO_ENABLED=0
- go install -ldflags "-X main.VERSION=$CI_COMMIT_TAG" .
- ssh -p $CI_DEPLOY_PORT "$CI_DEPLOY_USER@$CI_DEPLOY_ADDR" sudo systemctl stop "$CI_PROJECT_NAME"
- scp -P $CI_DEPLOY_PORT "/go/bin/$CI_PROJECT_NAME" "$CI_DEPLOY_USER@$CI_DEPLOY_ADDR:~/bin/$CI_PROJECT_NAME"
- ssh -p $CI_DEPLOY_PORT "$CI_DEPLOY_USER@$CI_DEPLOY_ADDR" "sudo systemctl start $CI_PROJECT_NAME && sudo systemctl status $CI_PROJECT_NAME"
- mv "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_DIR/$CI_PROJECT_NAME"
artifacts:
paths:
- config_example.toml
- "$CI_PROJECT_NAME"
build-release:
stage: build
only:
- tags
script:
# build doc
- go install github.com/swaggo/swag/cmd/swag@latest
- swag init --parseDependency --parseDepth 4 --parseInternal -g web/docs.go -o web/docs
# build app with version
- export CGO_ENABLED=0
- go install -ldflags "-X main.VERSION=$CI_COMMIT_TAG" .
- mv "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_DIR/$CI_PROJECT_NAME"
artifacts:
paths:
- config_example.toml
- "$CI_PROJECT_NAME"
expire_in: never