Skip to content

Commit 235c7e3

Browse files
committed
infra: TODO: add a dummy deployment workflow,
1 parent 81ab51c commit 235c7e3

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

.github/workflows/build_and_deploy.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
frontend-build:
3636
uses: naxa-developers/tasking-manager/.github/workflows/frontend-build.yml@ci-gh-workflows
3737
secrets: inherit
38+
needs:
39+
- frontend-test
3840
with:
3941
node-version: 16.x
4042
context: ./frontend
@@ -54,7 +56,7 @@ jobs:
5456
with:
5557
name: ${{ needs.frontend-build.outputs.artifact-name }}
5658
path: ./build
57-
59+
#TODO: Handle Auth and upload to respective s3 bucket & do a cloudfront invalidation
5860
- name: Debug check files
5961
run: |
6062
ls -alh
@@ -98,6 +100,7 @@ jobs:
98100
- name: Create Snapshot
99101
run:
100102
echo " TODO Database backup Steps; See CircleCI"
103+
# See https://app.circleci.com/pipelines/github/hotosm/tasking-manager/11487/workflows/e98ba643-5812-4b2a-a09f-cc499285b3cc/jobs/23599
101104
#TODO: Check circleci for references
102105

103106
backend_deploy_to_vm:
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Note: variables: SSH_HOST and SSH_USER must be set for your environment.
2+
# Note: secrets: SSH_PRIVATE_KEY must be set for your environment.
3+
4+
name: Remote Deploy (Compose)
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
environment:
10+
description: "The Github environment to get variables from. Default repository vars."
11+
required: false
12+
type: string
13+
docker_compose_file:
14+
description: "Path to docker compose file to deploy."
15+
required: true
16+
type: string
17+
example_env_file_path:
18+
description: "Path to example dotenv file to substitute variables for."
19+
type: string
20+
default: .env.example
21+
env_file_path:
22+
description: "Path to write dotenv file"
23+
type: string
24+
default: .env
25+
26+
jobs:
27+
remote-deploy:
28+
runs-on: ubuntu-latest
29+
environment: ${{ inputs.environment }}
30+
31+
steps:
32+
- name: Checkout Repository
33+
uses: actions/checkout@v4
34+
35+
- name: Vars and Secrets to Env
36+
env:
37+
GIT_BRANCH: ${{ github.ref_name }}
38+
VARS_CONTEXT: ${{ toJson(vars) }}
39+
SECRETS_CONTEXT: ${{ toJson(secrets) }}
40+
run: |
41+
# Random delimeter string for security
42+
delim=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
43+
44+
# Parse JSON with multiline strings, using delimeter (Github specific)
45+
to_envs() { jq -r "to_entries[] | \"\(.key)<<$delim\n\(.value)\n$delim\n\""; }
46+
47+
# Set vars to env for next step
48+
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV
49+
echo "TAG_OVERRIDE=${TAG_OVERRIDE}" >> $GITHUB_ENV
50+
51+
# Set VARS_CONTEXT if not null
52+
if [ "${VARS_CONTEXT}" != "null" ]; then
53+
echo "${VARS_CONTEXT}" | to_envs >> $GITHUB_ENV
54+
fi
55+
56+
# Set SECRETS_CONTEXT if not null
57+
if [ "${SECRETS_CONTEXT}" != "null" ]; then
58+
echo "${SECRETS_CONTEXT}" | to_envs >> $GITHUB_ENV
59+
fi
60+
61+
- name: Create .env file
62+
env:
63+
EXAMPLE_DOTENV: ${{ inputs.example_env_file_path }}
64+
run: |
65+
echo "Checking if ${EXAMPLE_DOTENV} exists"
66+
if [ -f ${EXAMPLE_DOTENV} ]; then
67+
# Get a8m/envsubst (required for default vals syntax ${VAR:-default})
68+
echo "Downloading envsubst"
69+
curl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst
70+
if [ $? -ne 0 ]; then
71+
echo "Failed to download envsubst"
72+
exit 1
73+
fi
74+
chmod +x envsubst
75+
echo "Substituting variables from ${EXAMPLE_DOTENV} --> ${{ inputs.env_file_path }}"
76+
./envsubst < "${EXAMPLE_DOTENV}" > ${{ inputs.env_file_path }}
77+
else
78+
echo "${EXAMPLE_DOTENV} not found, creating empty ${{ inputs.env_file_path }}"
79+
touch ${{ inputs.env_file_path }}
80+
fi
81+
82+
echo "GIT_BRANCH=${GIT_BRANCH}" >> ${{ inputs.env_file_path }}
83+
echo "TAG_OVERRIDE=${TAG_OVERRIDE}" >> ${{ inputs.env_file_path }}
84+
85+
# TODO: Add step to force new deployment here: also update image_tag accordingly in terraform vars.
86+
# - uses: webfactory/[email protected]
87+
# with:
88+
# ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
89+
90+
# - name: Add host keys to known_hosts
91+
# run: |
92+
# ssh-keyscan "${{ vars.SSH_HOST }}" >> ~/.ssh/known_hosts
93+
94+
# - name: Deploy
95+
# run: |
96+
# docker compose --file ${{ inputs.docker_compose_file }} pull
97+
# docker compose --file ${{ inputs.docker_compose_file }} up \
98+
# --detach --remove-orphans --force-recreate
99+
# env:
100+
# DOCKER_HOST: "ssh://${{ vars.SSH_USER }}@${{ vars.SSH_HOST }}"

0 commit comments

Comments
 (0)