-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircleci-template.yml
87 lines (73 loc) · 3.55 KB
/
circleci-template.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
{[define "DEPLOYMENT"]}
- name: Fetch kubeconfig
run: |-
eval "$( aws sts assume-role --role-arn arn:aws:iam::{[.AWSAccountNumber]}:role/rolen-name-{[.Env]} --role-session session | jq -r '.Credentials | keys[] as $k | "\($k) \(.[$k])"' | awk '{ gsub(/[A-Z]/,"_&",$1); print "export","AWS"toupper($1)"="$2}' )"
aws eks update-kubeconfig --name wave-eks-main-{[.Env]} --kubeconfig ./kubeconfig --region=eu-west-2 --role-arn arn:aws:iam::{[.AWSAccountNumber]}:role/role-name-{[.Env]}
- name: Deploy to {[.Env]}
run: |
CHART_VERSION=$(cat CHART-VERSION)
helm init --client-only
helm repo add test $HELM_REPO_URL --username $ARTIFACTORY_USERNAME --password $ARTIFACTORY_PASSWORD && helm repo update
echo "Running helm upgrade --install {[.Env]}-{[.Name]} --timeout 300 --version $CHART_VERSION --wait --set environment={[.Env]} --namespace={[.Env]} test/{[.Name]} --debug"
if ! helm upgrade --install {[.Env]}-{[.Name]} --timeout 300 --version $CHART_VERSION --wait --set environment={[.Env]} --namespace={[.Env]} test/{[.Name]} --debug; then
echo "Detected that the upgrade failed, attempting rollback."
helm rollback {[.Env]}-{[.Name]} 0
curl -X POST \
https://hooks.slack.com/services/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 \
-H 'Content-Type: application/json' \
-d '{"channel": "#{[.Env]}-alerts","attachments": [ {"title": "Deployment failed to {[.Env]}","text": "{[.Name]} ('"$VERSION"') has NOT been deployed to {[.Env]}. Helm rolled back deployment.","color": "danger"} ] }'
exit 1
fi
- name: Tag HEAD with {[.Env]}
run: |-
echo "Tagging HEAD with {[.Env]}"
if ! git tag -d {[.Env]} ; then
echo "No tag to remove from git"
fi
git tag {[.Env]}
git push --force origin refs/tags/{[.Env]}:refs/tags/{[.Env]}
echo "Tagging complete"
- name: publish to API Gateway {[.Env]}
run: |-
SERVICE_NAME={[.Name]} \
ASSUME_ROLE=arn:aws:iam::{[.AWSAccountNumber]}:role/githubaction-swagger-publisher-role-{[.Env]} \
ENVIRONMENT={[.Env]} \
CONNECTION_TYPE=VPC \
VPC_ID=${[.Env]}_VPC_ID \
API_GATEWAY_ID=${[.Env]}_API_GATEWAY_ID \
/bin/swagger-publisher;
{[end]}
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Build with Maven
run: mvn -B package --file pom.xml -DskipTests -s .github/settings.xml
- name: Run tests
run: mvn -B package --file pom.xml
- name: {[.service_name]}
- name: Build
run: |-
docker build \
--tag "docker.pkg.github.com/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
# Push the Docker image to Github registry
- name: Publish
run: |-
docker push "docker.pkg.github.com/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
{[template "DEPLOYMENT" map "Env" "dev" "Name" .service_name "AWSAccountNumber" "326458601802" "key1" "value1" ]}
{[template "DEPLOYMENT" map "Env" "staging" "Name" .service_name "AWSAccountNumber" "125695174157" "key1" "value1" ]}
{[template "DEPLOYMENT" map "Env" "prod" "Name" .service_name "AWSAccountNumber" "430419974501" "key1" "value1" ]}