Skip to content

Commit f6545bf

Browse files
Changes for Production Deployment Pipeline (#728)
1 parent 717ea34 commit f6545bf

1 file changed

Lines changed: 104 additions & 2 deletions

File tree

.github/workflows/deployment.yaml

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
pull_request:
55
branches:
66
- master
7+
- production
78
push:
89
branches:
910
- master
11+
- production
1012
env:
1113
IMAGE_NAME: care
1214
AWS_DEFAULT_REGION: ap-south-1
@@ -98,9 +100,77 @@ jobs:
98100
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
99101
docker tag $IMAGE_NAME $IMAGE_ID:latest
100102
docker push $IMAGE_ID --all-tags
103+
build-dockerhub-production:
104+
needs: test
105+
name: Build & Push to Dockerhub Production
106+
if: github.ref == 'refs/heads/production'
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Checkout
110+
uses: actions/checkout@v2
111+
112+
- name: Set current date as ENV variable
113+
run: echo "NOW=$(date +'%Y%m%d')" >> $GITHUB_ENV
114+
115+
- name: Github Short SHA
116+
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
117+
- name: Login to Docker Hub
118+
uses: docker/login-action@v1
119+
with:
120+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
121+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
122+
123+
- name: Build image
124+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
125+
126+
- name: Push image
127+
run: |
128+
IMAGE_ID=${{ secrets.DOCKER_HUB_USERNAME }}/$IMAGE_NAME
129+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
130+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
131+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
132+
[ "$VERSION" == "production" ] && VERSION=production-latest
133+
echo IMAGE_ID=$IMAGE_ID
134+
echo VERSION=$VERSION
135+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
136+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
137+
docker tag $IMAGE_NAME $IMAGE_ID:production-latest
138+
docker push $IMAGE_ID --all-tags
139+
build-github-production:
140+
needs: test
141+
if: github.ref == 'refs/heads/production'
142+
name: Build and push to GitHub
143+
runs-on: ubuntu-latest
144+
steps:
145+
- uses: actions/checkout@v2
146+
- name: Set current date as ENV variable
147+
run: echo "NOW=$(date +'%Y%m%d')" >> $GITHUB_ENV
148+
149+
- name: Github Short SHA
150+
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
151+
152+
- name: Build image
153+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
154+
155+
- name: Log into registry
156+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
157+
158+
- name: Push image
159+
run: |
160+
IMAGE_ID=ghcr.io/${{ github.repository }}
161+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
162+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
163+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
164+
[ "$VERSION" == "production" ] && VERSION=production-latest
165+
echo IMAGE_ID=$IMAGE_ID
166+
echo VERSION=$VERSION
167+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
168+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
169+
docker tag $IMAGE_NAME $IMAGE_ID:production-latest
170+
docker push $IMAGE_ID --all-tags
101171
deploy-staging-egov:
102172
needs: build-github-staging
103-
name: Deploy to EKS
173+
name: Deploy to EKS Egov
104174
runs-on: ubuntu-latest
105175
environment:
106176
name: Staging-egov
@@ -133,7 +203,7 @@ jobs:
133203
134204
deploy-staging-gdc:
135205
needs: build-github-staging
136-
name: Deploy to EKS
206+
name: Deploy to EKS GDC
137207
runs-on: ubuntu-latest
138208
environment:
139209
name: Staging-gdc
@@ -163,3 +233,35 @@ jobs:
163233
kubectl apply -f care-backend.yaml
164234
kubectl apply -f care-celery-beat.yaml
165235
kubectl apply -f care-celery-worker.yaml
236+
deploy-production-futureace:
237+
needs: build-github-production
238+
name: Deploy to EKS Futureace
239+
runs-on: ubuntu-latest
240+
environment:
241+
name: Production-futureace
242+
url: https://careapi.plexusindia.in
243+
steps:
244+
- name: Checkout Kube Config
245+
uses: actions/checkout@v2
246+
with:
247+
repository: coronasafe/future-hospitals-infra
248+
token: ${{ secrets.GIT_ACCESS_TOKEN }}
249+
path: kube
250+
ref: main
251+
- name: Configure AWS credentials
252+
uses: aws-actions/configure-aws-credentials@v1
253+
with:
254+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}}
255+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
256+
aws-region: ap-south-1
257+
- name: Deploy Care Production Futureace
258+
run: |
259+
mkdir -p $HOME/.kube/
260+
aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region ap-south-1
261+
cd kube/deployments/
262+
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-backend.yaml
263+
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-beat.yaml
264+
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-worker.yaml
265+
kubectl apply -f care-backend.yaml
266+
kubectl apply -f care-celery-beat.yaml
267+
kubectl apply -f care-celery-worker.yaml

0 commit comments

Comments
 (0)