Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto deploy when images are published #226

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy

on:
workflow_run:
workflows: [Docker build and publish]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: "Configure"
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{vars.AWS_REGION}}
aws-access-key-id: ${{ secrets.DEPLOY_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_ACCESS_KEY }}

- name: install oathtool
run: sudo apt-get install -y oathtool jq

- id: auth
name: Authenticate to STS
run: |
mfa_serial="arn:aws:iam::${{vars.AWS_ACCOUNT_NUMBER}}:mfa/gh-action"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gh-action should be an environment variable.

I see mfa/gh-action is tied to your AWS username. From our Slack conversation, we need another GH Ticket to track creating an AWS user that is isolated for this GH Action CI pipeline, and that would have its own mfa/, which would be great if its editable as an env var.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

mfa_code=$(oathtool -b --totp ${{secrets.MFA_KEY}})
STS=$(aws sts get-session-token --region "${{vars.AWS_REGION}}" --serial-number "$mfa_serial" --token-code "$mfa_code")

aws_access_key_id=$(echo "$STS" | jq -r '.Credentials.AccessKeyId')
echo "::add-mask::$aws_access_key_id"
aws_secret_access_key=$(echo "$STS" | jq -r '.Credentials.SecretAccessKey')
echo "::add-mask::$aws_secret_access_key"
aws_session_token=$(echo "$STS" | jq -r '.Credentials.SessionToken')
echo "::add-mask::$aws_session_token"

echo "AWS_ACCESS_KEY_ID=$aws_access_key_id" >> "$GITHUB_OUTPUT"
echo "AWS_SECRET_ACCESS_KEY=$aws_secret_access_key" >> "$GITHUB_OUTPUT"
echo "AWS_SESSION_TOKEN=$aws_session_token" >> "$GITHUB_OUTPUT"

- name: Assume role
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{vars.AWS_REGION}}
aws-access-key-id: ${{ steps.auth.outputs.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ steps.auth.outputs.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ steps.auth.outputs.AWS_SESSION_TOKEN }}
role-skip-session-tagging: true
role-to-assume: "arn:aws:iam::${{vars.AWS_ACCOUNT_NUMBER}}:role/eks-${{vars.AWS_USER}}"

- uses: actions/checkout@v2

- name: Update kubeconfig
run: |
aws eks update-kubeconfig --name ${{vars.CLUSTER}} --region ${{vars.AWS_REGION}}
helm repo add medic https://docs.communityhealthtoolkit.org/helm-charts

- name: Upgrade users-chis-civ
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-civ.yaml users-chis-civ medic/cht-user-management

- name: Upgrade users-chis-tg
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-tg.yaml users-chis-tg medic/cht-user-management

- name: Upgrade users-chis-ke
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-ke.yaml users-chis-ke medic/cht-user-management
Loading