-
Notifications
You must be signed in to change notification settings - Fork 1
/
.travis.yml
85 lines (78 loc) · 3.55 KB
/
.travis.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
language: node_js
node_js: "13"
# install: skip
env:
- IMAGE_NAME=shaungc/slack-middleware-service
jobs:
include:
- stage: test
# only build if it's master branch
if: branch = release
name: Test the code
install:
# add redis port-forwarding
- ls -la
- . ./get-k8-toolkit.sh
- KUBECONFIG=kubeconfig.yaml ./kubectl -n redis-cluster port-forward deploy/redis-cluster-deployment 6379:6379 &
- export REDIS_PORT_FORWARD_PID=$!
- echo "Port fowarding process is $REDIS_PORT_FORWARD_PID"
# install project dependencies
- cd ./src
- npm i
script:
# will continue using the previous working directory `./src`
- npm test
- kill $REDIS_PORT_FORWARD_PID
- |
SLACK_MESSAGE="*Slack Middleware Service* - test success."
if [ "a$SLACK_TOKEN_INCOMING_URL" != "a" ]; then
curl -X POST --data-urlencode "payload={ \"text\": \"(TRAVIS) ${SLACK_MESSAGE}\", \"channel\": \"#build\"}" ${SLACK_TOKEN_INCOMING_URL}
fi
- stage: build_push
# only deploy if it's master branch
if: branch = master
name: Build and push docker image
install: skip
script:
- pwd
- ls
- docker build -f ./prod.Dockerfile -t $IMAGE_NAME:latest . || exit 1
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
- export SHORT_TRAVIS_COMMIT=$(git rev-parse --short ${TRAVIS_COMMIT})
- docker tag $IMAGE_NAME:latest $IMAGE_NAME:$SHORT_TRAVIS_COMMIT
- docker push $IMAGE_NAME:latest
- docker push $IMAGE_NAME:$SHORT_TRAVIS_COMMIT
- |
SLACK_MESSAGE="*Slack Middleware Service* - docker built and pushed successfully."
if [ "a$SLACK_TOKEN_INCOMING_URL" != "a" ]; then
curl -X POST --data-urlencode "payload={ \"text\": \"(TRAVIS) ${SLACK_MESSAGE}\", \"channel\": \"#build\"}" ${SLACK_TOKEN_INCOMING_URL}
fi
- stage: deploy
# TODO: consider only deploy if it's release branch
# To allow multiple branches, you can use `branch = master OR branch = release`
if: |
branch = release
name: Run terraform and deploy
install: skip
script:
- export SHORT_TRAVIS_COMMIT=$(git rev-parse --short ${TRAVIS_COMMIT})
- cd ./cicd && . ./production.run-terraform.sh
- |
SLACK_MESSAGE="*Slack Middleware Service* - deployed successfully."
if [ "a$SLACK_TOKEN_INCOMING_URL" != "a" ]; then
curl -X POST --data-urlencode "payload={ \"text\": \"(TRAVIS) ${SLACK_MESSAGE}\", \"channel\": \"#build\"}" ${SLACK_TOKEN_INCOMING_URL}
fi
notifications:
slack:
rooms:
secure: t2q9RU1UzJKcszkMYKqunEuofekThh6sBn4BnNws+ZPJ8X3fTDk9HfQ8xI1cVRIOxH4vsAuC7nCzSM5twl7ZjQ/n6tljKHnRfK0McQPniiTmcQ1qSNnKv4ytKTwQEgzqwgJIXm7lhoLsC4agBBkt9e8hl8iML95HBUtekW33MkpTvWEL4OYumKCVX8ph5VE0/asfjUIsBwMD4IDrD+WJRoTZizbhUBzUzxZCkgBEPBkvOm0+gNJr+hh1LTHu3heMAUBwbjyfz/Dfpw5EsOeo+E+vjZ8nU+25qFJ30iFQs+ChJepfb+kU9uRKFJzLlCxB4r6BWKVgUTSRN8V0btF2nC7UkSb3OSHo9Mqi31aNdQ3/Jx9dfaYzwNnjZy+QtgEsjLiV63OAkD3RwezMwjjtAdA566B/nKsHZPXzmexmiELxbOwBqDZxCLemSdi/cARu3zojT/pK9yG1nsuuIv3/KGHh24qiP8p6p390/LhvYQnrzZwFdJFv7vLxraRwHhhYFbUXW0lGjWMYlg+DxDaSA4guSikk0R5fWONYOjSkW0pWksezwA7Hu1f9/w19vdh4u6Gj4FD0GDNCachyq/SW1WmcuTfGHUvwM+Z+fH1gkINPG1LvhEtTg9dWYFHMmy+AyqiOVUbqCITm7zTzIzOUNoG/WQ3VfJIhgi3x2iOaaoI=
on_start: always
on_success: always
on_failure: always
template:
- "*%{repository_slug}: %{message}*"
- "Published successfully: https://slack.api.shaungc.com"
- "*Git commit:* %{commit_message}"
- 'Commit hash: `%{commit}`'
- 'Result: %{result} in %{duration}'
- 'Build details: <%{build_url}|Link>'