-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
76 lines (71 loc) · 2.74 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
stages:
- build
- test
- deploy
build-for-tests:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo $CI_REGISTRY_IMAGE
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:tests
tags:
- general
build-for-production:
stage: build
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: on_success
- if: $CI_COMMIT_BRANCH != "master"
when: manual
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
tags:
- general
postman_tests:
stage: test
image: docker:latest
needs: ["build-for-tests"]
when: on_success
script:
- docker --version
- docker login -u "$CSC_USER" -p "$CSC_KEY" gitlab.labranet.jamk.fi:4567
- docker pull gitlab.labranet.jamk.fi:4567/aa9358/service-oriented-applications:latest
- if [ "$(docker ps -a | grep 'restapi-container')" ]; then docker stop restapi-container; docker rm restapi-container; else echo no previous container; fi;
- docker run -d --name restapi-container -p 8000:8000 $CI_REGISTRY_IMAGE:tests
- newman --version
- curl http://0.0.0.0:8000/ping
- newman run https://www.getpostman.com/collections/5aa7ec40d5dad92bc8fc\?apikey\=PMAK-60925f46c52981004dc94241-754f82db650e0501dd777b46702c46c498
- docker stop /restapi-container
- docker rm /restapi-container
tags:
- test_runner
deploy:
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: on_success
- if: $CI_COMMIT_BRANCH != "master"
when: manual
image: docker:latest
before_script:
- sudo apt-get update
- sudo apt-get install -y openssh-client
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- eval $(ssh-agent -s)
- ssh-add - <<< "${SSH_PRIVATE_KEY}"
script:
- ssh -o StrictHostKeyChecking=no $SERVER_LOGIN " cd infra/; docker login -u '$CSC_USER' -p '$CSC_KEY' gitlab.labranet.jamk.fi:4567 "
- ssh -o StrictHostKeyChecking=no $SERVER_LOGIN " cd infra/; docker pull gitlab.labranet.jamk.fi:4567/aa9358/service-oriented-applications:latest "
- ssh -o StrictHostKeyChecking=no $SERVER_LOGIN " cd infra/; docker-compose up -d imager-api "
tags:
- test_runner