Skip to content

Commit

Permalink
add terragrunt deployment support & hcl checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-naxa committed Nov 15, 2024
1 parent b0f5115 commit 3702521
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ jobs:
env_file_path: tasking-manager.env
secrets: inherit

backup-database:
runs-on: ubuntu-latest
needs:
- backend-test
name: Backup Database before deployment
steps:
- name: Create Snapshot
run:
echo " TODO Database backup Steps; See CircleCI"
# See https://app.circleci.com/pipelines/github/hotosm/tasking-manager/11487/workflows/e98ba643-5812-4b2a-a09f-cc499285b3cc/jobs/23599
#TODO: Check circleci for references
# backup-database:
# runs-on: ubuntu-latest
# needs:
# - backend-test
# name: Backup Database before deployment
# steps:
# - name: Create Snapshot
# run:
# echo " TODO Database backup Steps; See CircleCI"
# # See https://app.circleci.com/pipelines/github/hotosm/tasking-manager/11487/workflows/e98ba643-5812-4b2a-a09f-cc499285b3cc/jobs/23599
# #TODO: Check circleci for references

backend_deploy_to_vm:
name: Deploy Backend to VM
needs:
- backup-database
- backend-test
uses: naxa-developers/tasking-manager/.github/workflows/remote_deploy_compose.yml@ci-gh-workflows
with:
docker_compose_file: docker-compose.yml
Expand Down
63 changes: 49 additions & 14 deletions .github/workflows/remote_deploy_compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@ on:
description: "The Github environment to get variables from. Default repository vars."
required: false
type: string
terragrunt_deployment:
description: "If the service to be deployed on using Terraform"
required: false
default: false
type: boolean
tofu_version:
description: "OpenToFu version for deployment"
type: string
default: '1.8.1'
tg_version:
description: "Terragrunt version for deployment"
type: string
default: '0.67.0'
tg_working_dir:
description: "Directory where terragrunt command is applied"
type: string
docker_depoyment:
description: "If the service is to be deployed with docker"
type: boolean
default: true
required: false
docker_compose_file:
description: "Path to docker compose file to deploy."
required: true
required: false
type: string
example_env_file_path:
description: "Path to example dotenv file to substitute variables for."
Expand All @@ -33,6 +54,7 @@ jobs:
uses: actions/checkout@v4

- name: Vars and Secrets to Env
if: ${{ inputs.docker_depoyment }}
env:
GIT_BRANCH: ${{ github.ref_name }}
VARS_CONTEXT: ${{ toJson(vars) }}
Expand All @@ -59,6 +81,7 @@ jobs:
fi
- name: Create .env file
if: ${{ inputs.docker_depoyment }}
env:
EXAMPLE_DOTENV: ${{ inputs.example_env_file_path }}
run: |
Expand All @@ -83,18 +106,30 @@ jobs:
echo "TAG_OVERRIDE=${TAG_OVERRIDE}" >> ${{ inputs.env_file_path }}
# TODO: Add step to force new deployment here: also update image_tag accordingly in terraform vars.
# - uses: webfactory/[email protected]
# with:
# ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
- uses: webfactory/[email protected]
if: ${{ inputs.docker_depoyment }}
with:
ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"

- name: Add host keys to known_hosts
if: ${{ inputs.docker_depoyment }}
run: |
ssh-keyscan "${{ vars.SSH_HOST }}" >> ~/.ssh/known_hosts
# - name: Add host keys to known_hosts
# run: |
# ssh-keyscan "${{ vars.SSH_HOST }}" >> ~/.ssh/known_hosts
- name: Deploy with Docker
if: ${{ inputs.docker_depoyment }}
run: |
docker compose --file ${{ inputs.docker_compose_file }} pull
docker compose --file ${{ inputs.docker_compose_file }} up \
--detach --remove-orphans --force-recreate
env:
DOCKER_HOST: "ssh://${{ vars.SSH_USER }}@${{ vars.SSH_HOST }}"

# - name: Deploy
# run: |
# docker compose --file ${{ inputs.docker_compose_file }} pull
# docker compose --file ${{ inputs.docker_compose_file }} up \
# --detach --remove-orphans --force-recreate
# env:
# DOCKER_HOST: "ssh://${{ vars.SSH_USER }}@${{ vars.SSH_HOST }}"
- name: Check terragrunt HCL
if: ${{ inputs.terragrunt_deployment }}
uses: gruntwork-io/terragrunt-action@v2
with:
tofu_version: ${{ inputs.tofu_version }}
tg_version: ${{ inputs.tg_version }}
tg_dir: ${{ inputs.working_dir }}
tg_command: 'hclfmt --terragrunt-check --terragrunt-diff'

0 comments on commit 3702521

Please sign in to comment.