forked from Alarm-Integration/sms-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
76 lines (68 loc) · 2.05 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
image: docker:19.03.12
stages:
- test
- build
- package
- deploy
variables:
CONTAINER_NAME: $SERVICE_NAME
IMAGE_NAME: $SERVICE_NAME
test:
image: golang:1.16
stage: test
script:
- go test $(go list ./... | grep -v /vendor/) -v -coverprofile=testCoverage.txt
- go tool cover -func=testCoverage.txt
artifacts:
paths:
- testCoverage.txt
build-go-application:
image: golang:1.16
stage: build
script:
- go mod download
- go mod verify
- go build -o main
artifacts:
paths:
- main
cache:
key: ${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}
policy: push
paths:
- main
package-docker-image:
stage: package
cache:
key: ${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}
policy: pull
paths:
- main
script:
- docker login -u $DOCKER_HUB_ID -p $DOCKER_HUB_PASSWORD
- docker build -t $DOCKER_HUB_ID/$IMAGE_NAME .
- docker push $DOCKER_HUB_ID/$IMAGE_NAME
g238_deploy:
stage: deploy
tags:
- g238
script:
- docker pull $DOCKER_HUB_ID/$IMAGE_NAME
- docker stop $CONTAINER_NAME || true
- docker run --rm -d -p $SMS_SERVICE_PORT:$SMS_SERVICE_PORT -e SMS_SERVICE_PORT=$SMS_SERVICE_PORT -e SERVICE_NAME=$SERVICE_NAME -e CONFIG_SERVER=$CONFIG_SERVER -e HOST_IP=$HOST_238_IP --name $CONTAINER_NAME $DOCKER_HUB_ID/$IMAGE_NAME
g239_deploy:
stage: deploy
tags:
- g239
script:
- docker pull $DOCKER_HUB_ID/$IMAGE_NAME
- docker stop $CONTAINER_NAME || true
- docker run --rm -d -p $SMS_SERVICE_PORT:$SMS_SERVICE_PORT -e SMS_SERVICE_PORT=$SMS_SERVICE_PORT -e SERVICE_NAME=$SERVICE_NAME -e CONFIG_SERVER=$CONFIG_SERVER -e HOST_IP=$HOST_239_IP --name $CONTAINER_NAME $DOCKER_HUB_ID/$IMAGE_NAME
g240_deploy:
stage: deploy
tags:
- g240
script:
- docker pull $DOCKER_HUB_ID/$IMAGE_NAME
- docker stop $CONTAINER_NAME || true
- docker run --rm -d -p $SMS_SERVICE_PORT:$SMS_SERVICE_PORT -e SMS_SERVICE_PORT=$SMS_SERVICE_PORT -e SERVICE_NAME=$SERVICE_NAME -e CONFIG_SERVER=$CONFIG_SERVER -e HOST_IP=$HOST_240_IP --name $CONTAINER_NAME $DOCKER_HUB_ID/$IMAGE_NAME