Skip to content

Commit

Permalink
Added basic deployment templates
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenkp2000 committed Nov 16, 2023
1 parent 8cbf9f5 commit 2e4b143
Show file tree
Hide file tree
Showing 25 changed files with 944 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/main-ci-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI-Only Workflow

# Trigger for commit on any branch, other than the ones in the list
on:
push:
branches-ignore:
- master
- int
- develop

jobs:
### Job to Build and Publish artifacts
Build-and-Publish:
uses: ./.github/workflows/reusable-build-and-publish.yml
63 changes: 63 additions & 0 deletions .github/workflows/main-dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Dev Workflow

# Trigger for commit on develop branch
on:
push:
branches:
- develop
#workflow_dispatch:
#pull_request:
#types:
#- opened
#- reopened
#- synchronize
#branches:
#- develop

# let the run-name get picked up dynamically from most recent commit
#run-name: '[${{ github.event_name }}] event on ${{ github.ref_type }}/PR# [${{ github.ref_name }}]'

jobs:
### Job to Build and Publish artifacts
# Output
# - pipeline-artifact-name = Name of the pipeline artifact to be used in release step (e.g. codedeploy-artifact)
# - app-version = Application version to be used in release step as S3 bucket directory (e.g. 1.1.1-SNAPSHOT, 1.2.0)
# - codedeploy-artifact-version = CodeDeploy artifact version to be used in uniquely naming deployment bundle (e.g. 20230528-144100_d63fd762704ef242d9827662b872b305744f753e)
Build-and-Publish:
uses: ./.github/workflows/reusable-build-and-publish.yml



### Job to Release CodeDeploy artifact to S3 bucket
# Output
# - s3-artifact-path = s3 bucket artifact path to be used for codedeploy (e.g. 1.1.1/deployment.tar.gz)
S3-CodeDeploy-Release:
needs: Build-and-Publish
uses: ./.github/workflows/reusable-s3-codedeploy-release.yml
with:
aws-region: ${{ vars.AWS_REGION }}
pipeline-artifact-name: ${{ needs.Build-and-Publish.outputs.pipeline-artifact-name }}
s3-bucket-name: ${{ vars.RELEASE_S3_BUCKET_NAME }}
s3-bucket-dir-path: ${{ needs.Build-and-Publish.outputs.app-version }}
s3-artifact-version: ${{ needs.Build-and-Publish.outputs.codedeploy-artifact-version }}
secrets:
aws-key: ${{ secrets.AWS_KEY }}
aws-secret: ${{ secrets.AWS_SECRET }}



### Job to Deploy CodeDeploy artifact to Dev environment
Dev-Deploy:
needs: S3-CodeDeploy-Release
uses: ./.github/workflows/reusable-codedeploy-deployment.yml
with:
aws-region: ${{ vars.AWS_REGION }}
codedeploy-app-name: ${{ vars.CODEDEPLOY_APP_NAME }}
codedeploy-group-name: ${{ vars.CODEDEPLOY_DEV_GROUP_NAME }}
deployment-description: 'Deployment triggered by ${{ github.triggering_actor }} from Github repo [${{ github.repository }}], ${{ github.ref_type }} [${{ github.ref_name }}], commit sha [${{ github.sha }}]'
s3-bucket-name: ${{ vars.RELEASE_S3_BUCKET_NAME }}
s3-artifact-path: ${{ needs.S3-CodeDeploy-Release.outputs.s3-artifact-path }}
s3-artifact-type: tgz
secrets:
aws-key: ${{ secrets.AWS_KEY }}
aws-secret: ${{ secrets.AWS_SECRET }}
52 changes: 52 additions & 0 deletions .github/workflows/main-e2e-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: E2E Workflow

# Trigger for commit on int branch (i.e. integration)
on:
push:
branches:
- int

jobs:
### Job to Build and Publish artifacts
# Output
# - pipeline-artifact-name = Name of the pipeline artifact to be used in release step (e.g. codedeploy-artifact)
# - app-version = Application version to be used in release step as S3 bucket directory (e.g. 1.1.1-SNAPSHOT, 1.2.0)
# - codedeploy-artifact-version = CodeDeploy artifact version to be used in uniquely naming deployment bundle (e.g. 20230528-144100_d63fd762704ef242d9827662b872b305744f753e)
Build-and-Publish:
uses: ./.github/workflows/reusable-build-and-publish.yml



### Job to Release CodeDeploy artifact to S3 bucket
# Output
# - s3-artifact-path = s3 bucket artifact path to be used for codedeploy (e.g. 1.1.1/deployment.tar.gz)
S3-CodeDeploy-Release:
needs: Build-and-Publish
uses: ./.github/workflows/reusable-s3-codedeploy-release.yml
with:
aws-region: ${{ vars.AWS_REGION }}
pipeline-artifact-name: ${{ needs.Build-and-Publish.outputs.pipeline-artifact-name }}
s3-bucket-name: ${{ vars.RELEASE_S3_BUCKET_NAME }}
s3-bucket-dir-path: ${{ needs.Build-and-Publish.outputs.app-version }}
s3-artifact-version: ${{ needs.Build-and-Publish.outputs.codedeploy-artifact-version }}
secrets:
aws-key: ${{ secrets.AWS_KEY }}
aws-secret: ${{ secrets.AWS_SECRET }}



### Job to Deploy CodeDeploy artifact to E2E environment
E2E-Deploy:
needs: S3-CodeDeploy-Release
uses: ./.github/workflows/reusable-codedeploy-deployment.yml
with:
aws-region: ${{ vars.AWS_REGION }}
codedeploy-app-name: ${{ vars.CODEDEPLOY_APP_NAME }}
codedeploy-group-name: ${{ vars.CODEDEPLOY_E2E_GROUP_NAME }}
deployment-description: 'Deployment triggered by ${{ github.triggering_actor }} from Github repo [${{ github.repository }}], ${{ github.ref_type }} [${{ github.ref_name }}], commit sha [${{ github.sha }}]'
s3-bucket-name: ${{ vars.RELEASE_S3_BUCKET_NAME }}
s3-artifact-path: ${{ needs.S3-CodeDeploy-Release.outputs.s3-artifact-path }}
s3-artifact-type: tgz
secrets:
aws-key: ${{ secrets.AWS_KEY }}
aws-secret: ${{ secrets.AWS_SECRET }}
53 changes: 53 additions & 0 deletions .github/workflows/main-prd-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Prod Workflow

# Trigger for push of a tag Naksha_*
on:
push:
tags:
- Naksha_*

jobs:
### Job to Build and Publish artifacts
# Output
# - pipeline-artifact-name = Name of the pipeline artifact to be used in release step (e.g. codedeploy-artifact)
# - app-version = Application version to be used in release step as S3 bucket directory (e.g. 1.1.1-SNAPSHOT, 1.2.0)
# - codedeploy-artifact-version = CodeDeploy artifact version to be used in uniquely naming deployment bundle (e.g. 20230528-144100_d63fd762704ef242d9827662b872b305744f753e)
Build-and-Publish:
uses: ./.github/workflows/reusable-build-and-publish.yml



### Job to Release CodeDeploy artifact to S3 bucket
# Output
# - s3-artifact-path = s3 bucket artifact path to be used for codedeploy (e.g. 1.1.1/deployment.tar.gz)
S3-CodeDeploy-Release:
needs: Build-and-Publish
uses: ./.github/workflows/reusable-s3-codedeploy-release.yml
with:
aws-region: ${{ vars.AWS_REGION }}
pipeline-artifact-name: ${{ needs.Build-and-Publish.outputs.pipeline-artifact-name }}
s3-bucket-name: ${{ vars.RELEASE_S3_BUCKET_NAME }}
s3-bucket-dir-path: ${{ needs.Build-and-Publish.outputs.app-version }}
s3-artifact-version: ${{ needs.Build-and-Publish.outputs.codedeploy-artifact-version }}
secrets:
aws-key: ${{ secrets.AWS_KEY }}
aws-secret: ${{ secrets.AWS_SECRET }}



### Job to Deploy CodeDeploy artifact to Production environment
Prd-Deploy:
needs: S3-CodeDeploy-Release
uses: ./.github/workflows/reusable-codedeploy-deployment.yml
with:
aws-region: ${{ vars.PRD_AWS_REGION }}
codedeploy-app-name: ${{ vars.CODEDEPLOY_APP_NAME }}
codedeploy-group-name: ${{ vars.CODEDEPLOY_PRD_GROUP_NAME }}
deployment-description: 'Deployment triggered by ${{ github.triggering_actor }} from Github repo [${{ github.repository }}], ${{ github.ref_type }} [${{ github.ref_name }}], commit sha [${{ github.sha }}]'
# we use Prod access point (eu-west-1) to fetch deployment artifacts from E2E S3 bucket (us-east-1)
s3-bucket-name: ${{ vars.PRD_RELEASE_S3_BUCKET_NAME }}
s3-artifact-path: ${{ needs.S3-CodeDeploy-Release.outputs.s3-artifact-path }}
s3-artifact-type: tgz
secrets:
aws-key: ${{ secrets.PRD_AWS_KEY }}
aws-secret: ${{ secrets.PRD_AWS_SECRET }}
75 changes: 75 additions & 0 deletions .github/workflows/reusable-build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
on:
workflow_call:
outputs:
pipeline-artifact-name:
description: 'Name of the uploaded artifact which can be downloaded using actions/download-artifact within the same pipeline (e.g. codedeploy-artifact)'
value: ${{ jobs.main.outputs.pipeline-artifact-name }}
app-version:
description: 'Application version identified using maven (e.g. 1.1.1-SNAPSHOT, 1.2.0)'
value: ${{ jobs.main.outputs.app-version }}
codedeploy-artifact-version:
description: 'Unique version which should be used in next step(s) for CodeDeploy artifact (e.g. 20230528-144100_d63fd762704ef242d9827662b872b305744f753e)'
value: ${{ jobs.main.outputs.codedeploy-artifact-version }}

env:
SERVICE_JAR_DIR: ${{ github.workspace }}/build/libs
CODEDEPLOY_DIR: ${{ github.workspace }}/deployment/codedeploy
GITHUB_CODEDEPLOY_ARTIFACT_NAME: codedeploy-artifact

jobs:
main:
runs-on: ubuntu-latest
outputs:
pipeline-artifact-name: ${{ steps.save-artifact-name.outputs.name }}
app-version: ${{ steps.save-app-version.outputs.version }}
codedeploy-artifact-version: ${{ steps.save-artifact-version.outputs.version }}
steps:
- run: echo "[${{ github.triggering_actor }}] triggered [${{ github.event_name }}] event on ${{ github.ref_type }}/PR# [${{ github.ref_name }}]"
- run: echo "🎉 This job is running on a ${{ runner.os }} server hosted by GitHub!"
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 17
java-package: jdk
cache: gradle
### TODO : Include JUnit tests & verify code coverage
- name: Build package, execute tests & verify overall coverage
uses: gradle/gradle-build-action@v2
with:
arguments: shadowJar -x test
gradle-version: 8.2
- name: List generated artifacts
run: |
ls -l $SERVICE_JAR_DIR
### TODO : Publish to central repository
- name: Prepare CodeDeploy artifact content
run: |
cp -p $SERVICE_JAR_DIR/naksha-*-all.jar $CODEDEPLOY_DIR/contents/naksha-hub/
- name: List CodeDeploy artifact content
run: |
ls -lR $CODEDEPLOY_DIR
- name: Save pipeline artifact name
id: save-artifact-name
run: echo "name=${{ env.GITHUB_CODEDEPLOY_ARTIFACT_NAME }}" >> "$GITHUB_OUTPUT"
- name: Save CodeDeploy artifact content
uses: actions/upload-artifact@v3
with:
name: ${{ env.GITHUB_CODEDEPLOY_ARTIFACT_NAME }}
path: ${{ env.CODEDEPLOY_DIR }}
if-no-files-found: error
- name: Identify and save Application version
id: save-app-version
run: |
APP_VERSION=`gradle -q printAppVersion`
echo $APP_VERSION
echo "version=$APP_VERSION" >> "$GITHUB_OUTPUT"
- name: Identify and save CodeDeploy artifact version
id: save-artifact-version
run: |
ARTIFACT_VERSION=`date +"%Y%m%d-%H%M%S"`_${{ github.sha }}
echo $ARTIFACT_VERSION
echo "version=$ARTIFACT_VERSION" >> "$GITHUB_OUTPUT"
- run: echo "🍏 This job's status is ${{ job.status }}."
86 changes: 86 additions & 0 deletions .github/workflows/reusable-codedeploy-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
on:
workflow_call:
inputs:
aws-region:
type: string
description: 'AWS region the S3 bucket is associated with'
required: true
codedeploy-app-name:
type: string
description: 'CodeDeploy Application name, to be used for deployment'
required: true
codedeploy-group-name:
type: string
description: 'CodeDeploy DeploymentGroup name, to be used for deployment'
required: true
deployment-description:
type: string
description: 'CodeDeploy deployment description'
required: true
s3-bucket-name:
type: string
description: 'AWS S3 bucket name, which contains the artifact bundle to be deployed'
required: true
s3-artifact-path:
type: string
description: 'AWS S3 artifact path, which is to be used for deployment (e.g. 1.1.1/deployment.tar.gz)'
required: true
s3-artifact-type:
type: string
description: 'Type of the artifact to be deployed (e.g. tar, zip, tgz)'
required: true
secrets:
aws-key:
description: 'AWS Access key of a user, who is allowed to upload artifact to S3 bucket'
required: true
aws-secret:
description: 'AWS Access secret of a user, who is allowed to upload artifact to S3 bucket'
required: true

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Print deployment parameters
run: |
echo "aws-region = ${{ inputs.aws-region }}"
echo "codedeploy-app-name = ${{ inputs.codedeploy-app-name }}"
echo "codedeploy-group-name = ${{ inputs.codedeploy-group-name }}"
echo "deployment-description = ${{ inputs.deployment-description }}"
echo "s3-bucket-name = ${{ inputs.s3-bucket-name }}"
echo "s3-artifact-path = ${{ inputs.s3-artifact-path }}"
echo "s3-artifact-type = ${{ inputs.s3-artifact-type }}"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.aws-key }}
aws-secret-access-key: ${{ secrets.aws-secret }}
aws-region: ${{ inputs.aws-region }}
- name: Submit AWS-CodeDeploy Deployment
id: create-deployment
run: |
aws deploy create-deployment \
--application-name ${{ inputs.codedeploy-app-name }} \
--deployment-group-name ${{ inputs.codedeploy-group-name }} \
--s3-location bucket=${{ inputs.s3-bucket-name }},key=${{ inputs.s3-artifact-path }},bundleType=${{ inputs.s3-artifact-type }} \
--description "${{ inputs.deployment-description }}" \
> deployment_command.log
cat deployment_command.log
DEPLOYMENT_ID=`cat deployment_command.log | jq -r '.deploymentId'`
echo "id=$DEPLOYMENT_ID" >> "$GITHUB_OUTPUT"
- name: Print Deployment status link
run: |
echo "Deployment status link : https://$AWS_REGION.console.aws.amazon.com/codesuite/codedeploy/deployments/$DEPLOYMENT_ID?region=$AWS_REGION"
env:
DEPLOYMENT_ID: ${{ steps.create-deployment.outputs.id }}
AWS_REGION: ${{ inputs.aws-region }}
- name: Monitor Deployment status
run: |
echo "Deployment Id = $DEPLOYMENT_ID, Timeout seconds = $TIMEOUT_SEC"
bash ./.github/workflows/supporting-scripts/MonitorDeploymentStatus.sh $DEPLOYMENT_ID $TIMEOUT_SEC
env:
DEPLOYMENT_ID: ${{ steps.create-deployment.outputs.id }}
TIMEOUT_SEC: 600
- run: echo "🍏 This job's status is ${{ job.status }}."
Loading

0 comments on commit 2e4b143

Please sign in to comment.