-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
108 lines (98 loc) · 3.19 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
image: golang:1.10
variables:
REPO_NAME: github.com/uninett/goidc-proxy
before_script:
- export OUR_VERSION=${CI_BUILD_TAG:-$CI_BUILD_REF_NAME}
- echo "Setting version to $OUR_VERSION"
- export DEPLOY_DIR="/opt/goidc-proxy-deploys/$OUR_VERSION/"
- echo "Setting deploy dir to $DEPLOY_DIR"
stages:
- test
- build
- deploy
- docker-latest
- docker-stable
test-project:
stage: test
script:
- go version
- echo $CI_PROJECT_DIR
- curl https://glide.sh/get | sh
- mkdir -p $GOPATH/src/$REPO_NAME
- mv $CI_PROJECT_DIR/* $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- cp goidc_test.json goidc.json
- glide install
- go get -v github.com/go-playground/overalls
- overalls -project=$REPO_NAME -covermode=atomic -ignore=.git,.glide,vendor -debug -- -race -v
- go tool cover -func=overalls.coverprofile
build-project:
stage: build
script:
- go version
- echo $CI_PROJECT_DIR
- curl https://glide.sh/get | sh
- mkdir -p $GOPATH/src/$REPO_NAME
- mv $CI_PROJECT_DIR/* $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- glide install
- CGO_ENABLED=0 go build -o $CI_PROJECT_DIR/goidc-proxy
artifacts:
paths:
- goidc-proxy
deploy-testing:
stage: deploy
variables:
DEPLOY_HOST: "goidc-deploy@$TESTING_HOST"
SSH_OPTIONS: "-o GlobalKnownHostsFile=ssh-known-hosts -i ssh-private-key"
script:
- echo "$DEPLOY_KEY" > ssh-private-key
- chmod 0600 ssh-private-key
- echo "$TESTING_HOSTKEY" > ssh-known-hosts
- ssh $SSH_OPTIONS $DEPLOY_HOST /bin/mkdir -p $DEPLOY_DIR
- scp $SSH_OPTIONS goidc-proxy $DEPLOY_HOST:$DEPLOY_DIR
- rm ssh-private-key ssh-known-hosts
environment:
name: testing
only:
- master
deploy-prod:
stage: deploy
variables:
SSH_OPTIONS: "-o GlobalKnownHostsFile=ssh-known-hosts -i ssh-private-key"
script:
- echo "$DEPLOY_KEY" > ssh-private-key
- chmod 0600 ssh-private-key
- echo "$PROD_HOST_A_HOSTKEY" > ssh-known-hosts
- ssh $SSH_OPTIONS goidc-deploy@$PROD_HOST_A /bin/mkdir -p $DEPLOY_DIR
- scp $SSH_OPTIONS goidc-proxy goidc-deploy@$PROD_HOST_A:$DEPLOY_DIR
- echo "$PROD_HOST_B_HOSTKEY" > ssh-known-hosts
- ssh $SSH_OPTIONS goidc-deploy@$PROD_HOST_B /bin/mkdir -p $DEPLOY_DIR
- scp $SSH_OPTIONS goidc-proxy goidc-deploy@$PROD_HOST_B:$DEPLOY_DIR
- rm ssh-private-key ssh-known-hosts
environment:
name: production
only:
- tags
docker-latest:
stage: deploy
image: registry.uninett.no/system/docker-builder:1.13.1-uninett7
script:
- docker build -t "registry.uninett.no/public/goidc-proxy:latest" -t "quay.io/uninett/goidc-proxy:latest" .
- docker push "quay.io/uninett/goidc-proxy:latest"
- docker push "registry.uninett.no/public/goidc-proxy:latest"
only:
- master
when:
manual
docker-stable:
stage: deploy
image: registry.uninett.no/system/docker-builder:1.13.1-uninett7
script:
- docker build -t "registry.uninett.no/public/goidc-proxy:$CI_BUILD_REF_NAME" -t "quay.io/uninett/goidc-proxy:$CI_BUILD_REF_NAME" .
- docker push "quay.io/uninett/goidc-proxy:$CI_BUILD_REF_NAME"
- docker push "registry.uninett.no/public/goidc-proxy:$CI_BUILD_REF_NAME"
only:
- tags
when:
manual