Skip to content

Commit

Permalink
Changes for Production Deployment Pipeline (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
dauntlessnomad authored Apr 26, 2022
1 parent 717ea34 commit f6545bf
Showing 1 changed file with 104 additions and 2 deletions.
106 changes: 104 additions & 2 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
pull_request:
branches:
- master
- production
push:
branches:
- master
- production
env:
IMAGE_NAME: care
AWS_DEFAULT_REGION: ap-south-1
Expand Down Expand Up @@ -98,9 +100,77 @@ jobs:
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID --all-tags
build-dockerhub-production:
needs: test
name: Build & Push to Dockerhub Production
if: github.ref == 'refs/heads/production'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set current date as ENV variable
run: echo "NOW=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: Github Short SHA
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Push image
run: |
IMAGE_ID=${{ secrets.DOCKER_HUB_USERNAME }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "production" ] && VERSION=production-latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
docker tag $IMAGE_NAME $IMAGE_ID:production-latest
docker push $IMAGE_ID --all-tags
build-github-production:
needs: test
if: github.ref == 'refs/heads/production'
name: Build and push to GitHub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set current date as ENV variable
run: echo "NOW=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: Github Short SHA
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "production" ] && VERSION=production-latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION-$GITHUB_RUN_NUMBER-$NOW-$SHORT_SHA
docker tag $IMAGE_NAME $IMAGE_ID:production-latest
docker push $IMAGE_ID --all-tags
deploy-staging-egov:
needs: build-github-staging
name: Deploy to EKS
name: Deploy to EKS Egov
runs-on: ubuntu-latest
environment:
name: Staging-egov
Expand Down Expand Up @@ -133,7 +203,7 @@ jobs:
deploy-staging-gdc:
needs: build-github-staging
name: Deploy to EKS
name: Deploy to EKS GDC
runs-on: ubuntu-latest
environment:
name: Staging-gdc
Expand Down Expand Up @@ -163,3 +233,35 @@ jobs:
kubectl apply -f care-backend.yaml
kubectl apply -f care-celery-beat.yaml
kubectl apply -f care-celery-worker.yaml
deploy-production-futureace:
needs: build-github-production
name: Deploy to EKS Futureace
runs-on: ubuntu-latest
environment:
name: Production-futureace
url: https://careapi.plexusindia.in
steps:
- name: Checkout Kube Config
uses: actions/checkout@v2
with:
repository: coronasafe/future-hospitals-infra
token: ${{ secrets.GIT_ACCESS_TOKEN }}
path: kube
ref: main
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-south-1
- name: Deploy Care Production Futureace
run: |
mkdir -p $HOME/.kube/
aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region ap-south-1
cd kube/deployments/
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-backend.yaml
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-beat.yaml
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-worker.yaml
kubectl apply -f care-backend.yaml
kubectl apply -f care-celery-beat.yaml
kubectl apply -f care-celery-worker.yaml

0 comments on commit f6545bf

Please sign in to comment.