forked from Sunbird-Obsrv/obsrv-api-service
-
Notifications
You must be signed in to change notification settings - Fork 9
147 lines (136 loc) · 5.23 KB
/
build_and_deploy.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Build and Deploy
run-name: Workflow run for ${{ github.ref }}
on:
push:
tags:
- "*"
workflow_dispatch:
inputs:
aws-deploy:
type: boolean
required: true
default: false
jobs:
verify-tags:
runs-on: ubuntu-latest
outputs:
ALLOWED_TAG: ${{ steps.tag-checker.outputs.TRIGGER_ALLOWED }}
steps:
- name: Check if tag is one in list of current releases
id: tag-checker
run: |
(echo -n TRIGGER_ALLOWED= && echo 'print("${{ github.ref_name }}".split("_")[0] not in "${{ vars.CURRENT_RELEASE }}")' | python3) >> "$GITHUB_OUTPUT"
api-service:
needs: verify-tags
if: needs.verify-tags.outputs.ALLOWED_TAG == 'True'
runs-on: ubuntu-latest
steps:
- name: Login to docker hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker image and push
uses: docker/build-push-action@v4
with:
file: ./api-service/Dockerfile
push: true
tags: ${{ vars.DOCKERHUB_USERNAME }}/obsrv-api-service:${{ github.ref_name }}
command-service:
needs: verify-tags
if: needs.verify-tags.outputs.ALLOWED_TAG == 'True'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Change directory to command-service
run: cd command-service
working-directory: ${{ github.workspace }}/command-service
- name: Login to docker hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# username: sanketikahub
# password: mxP17gAtFOOn
- name: Build docker image and push
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
push: true
tags: ${{ vars.DOCKERHUB_USERNAME }}/obsrv-command-service:${{ github.ref_name }}
# tags: sanketikahub/obsrv-command-service:1.0
aws-deploy:
needs: [ verify-tags,api-service, command-service]
if: needs.verify-tags.outputs.ALLOWED_TAG == 'True'
runs-on: ubuntu-latest
environment: aws-dev
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terragrunt
uses: autero1/[email protected]
with:
terragrunt_version: v0.45.8
- name: Terragrunt installation
run: terragrunt --version
- name: Clone the terraform deployment repo
uses: actions/checkout@v3
with:
repository: ${{ vars.DEPLOY_REPO }}
path: deploy
ref: ${{ vars.DEPLOY_REPO_REF }}
# ref: action-deploy
- name: Fetch and update kubeconfig file
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_REGION }}
run: |
aws eks --region us-east-2 update-kubeconfig --name obsrv-ga-dev-dev-eks
- name: Run terraform init and apply
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_REGION }}
# AWS_TERRAFORM_BACKEND_BUCKET_NAME: ${{ vars.AWS_TERRAFORM_BACKEND_BUCKET_NAME }}
# AWS_TERRAFORM_BACKEND_BUCKET_REGION: ${{ vars.AWS_TERRAFORM_BACKEND_BUCKET_REGION }}
AWS_TERRAFORM_BACKEND_BUCKET_NAME: obsrv-ga-dev-tfstate
AWS_TERRAFORM_BACKEND_BUCKET_REGION: us-east-2
KUBE_CONFIG_PATH: ~/.kube/config
run: |
cd deploy/terraform/aws
terragrunt init
terragrunt apply --target=module.dataset_api \
-var dataset_api_container_registry=${{ vars.DOCKERHUB_USERNAME }} \
-var dataset_api_image_tag=develop-241-4
# -var env=dev \
# -var building_block=obsrv-ga-dev \
# -var region=us-east-2 \
# -var availability_zone=["us-east-2a","us-east-2b","us-east-2c"] \
# -var timezone=UTC \
# -var create_vpc=true -var create_velero_user=true -var create_kong_ingress=true \
# -var cluster_logs_enabled=true
azure-deploy:
# needs: [verify-tags, api-service, command-service]
if: needs.verify-tags.outputs.ALLOWED_TAG == 'True' && vars.CLOUD_PROVIDER == 'azure'
runs-on: ubuntu-latest
steps:
- name: Clone the terraform deployment repo
uses: actions/checkout@v3
with:
repository: ${{ vars.DEPLOY_REPO }}
path: deploy
ref: ${{ vars.DEPLOY_REPO_REF }}
- name: Run terraform init and apply
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
run: |
cd deploy/terraform/azure
terragrunt init
terragrunt apply -auto-approve --target=module.dataset_api \
-var dataset_api_container_registry=${{ secrets.DOCKERHUB_USERNAME }} \
-var dataset_api_image_tag=${{ github.ref_name }}