-
Notifications
You must be signed in to change notification settings - Fork 3
/
.travis.yml
85 lines (75 loc) · 2.99 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
dist: xenial
services:
- docker
env:
global:
- LOCAL_BIN=${HOME}/.local/bin # For downloaded tools like terraform and awscli
# Retrieve commit tag values for each micro-service folder to be used in tagging and deploying docker images.
# Dependency folders are included as well and must be maintained
- GOLANG_TAG=$(git log --pretty=format:rc-%h -n 1 -- golang-app)
- PYTHON_TAG=$(git log --pretty=format:rc-%h -n 1 -- python-app)
- TESTBOX_TAG=$(git log --pretty=format:rc-%h -n 1 -- testbox)
before_install:
- mkdir -p ${LOCAL_BIN}
- export PATH=${PATH}:${LOCAL_BIN} # Put aws in the path
- make common-deps # install dependencies from Makefile in the root
script:
- set -e # Stop script immediately on error
- cd $SERVICE_DIR
- export AWS_PROFILE=${TARGET_AWS_PROFILE}
- make check-image-exists && travis_terminate 0 || echo "Image doesn't exist, continue with build process";
- make publish # Publish will do the build
# This governs the order of stage-execution
stages:
- name: build
- name: deployment
jobs:
include:
- stage: build
name: "✍️ Golang App Build: Build, test and publish the image"
env:
- SERVICE_DIR=golang-app
- TARGET_AWS_PROFILE=AWS_STEVE
- COMMIT_HASH=${GOLANG_TAG}
if: (branch = tag AND tag =~ /v\d+.\d+(.\d+)?/) OR (branch != tag)
- stage: build
name: "✍️ Python App Build: Build, test and publish the image"
env:
- SERVICE_DIR=python-app
- TARGET_AWS_PROFILE=AWS_STEVE
- COMMIT_HASH=${PYTHON_TAG}
if: (branch = tag AND tag =~ /v\d+.\d+(.\d+)?/) OR (branch != tag)
- stage: build
name: "✍️ TESTBOX: Build, test and publish the image"
env:
- SERVICE_DIR=testbox
- TARGET_AWS_PROFILE=AWS_STEVE
- COMMIT_HASH=${TESTBOX_TAG}
if: (branch = tag AND tag =~ /v\d+.\d+(.\d+)?/) OR (branch != tag)
# Deploy the infrastructure, use for main
- stage: terraform deployment
name: "🏖️ Main deploy to AWS: Apply changes to kubernetes infrastructure and update container images"
env:
- SERVICE_DIR=infra
- REGION=ap-southeast-2
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
script:
- set -e # Stop script immediately on error
- cd $SERVICE_DIR
- make depend
- make deploy
if: branch = main AND type != pull_request AND commit_message ="aws" AND commit_message !="destroy"
- stage: terraform deployment
name: "♨️ Branch manual destroy AWS: Destroy changes in aws"
env:
- SERVICE_DIR=infra
- REGION=ap-southeast-2
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
script:
- set -e # Stop script immediately on error
- cd $SERVICE_DIR
- make depend
- make destroy
if: commit_message ="destroy" AND type != pull_request