Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
akhettar committed Jul 7, 2020
1 parent befbf50 commit 72aaecb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories:
The above configuration file contains list of the Git repositories we aim to generate or update the CI pipeline for. The `url` is the only mandotory parameter. You can define as many parameters in the form of `key` and `value`.


2. Template file - see [deploy-prod.yml as example of java microservice to be deployed to AWS kube](templates/deploy-prod.yml).
2. Template file - This file contains the CI template from which instances of the CI piepline will be generated - see [Github action sample](templates/deploy-staging.yml).


Note that you can also define `templates` within the CI template - see [circleci pipeline example](templates/circleci-template.yml):
Expand Down
87 changes: 87 additions & 0 deletions templates/circleci-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{[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" ]}





0 comments on commit 72aaecb

Please sign in to comment.