Skip to content

Commit 9432784

Browse files
mimartin12Eeebrupixman20
authored
BRE-292: Add workflow for ephemeral environment management (#357)
* BRE-292: Add Ephemeral Environment PR manager * Switch check-run to local path * Update .github/workflows/_ephemeral_environment_manager.yml Co-authored-by: Opeyemi <[email protected]> * Update .github/workflows/_ephemeral_environment_manager.yml Co-authored-by: Andy Pixley <[email protected]> --------- Co-authored-by: Opeyemi <[email protected]> Co-authored-by: Andy Pixley <[email protected]>
1 parent ced3228 commit 9432784

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Ephemeral Environment Manager
2+
run-name: Ephemeral Environment - ${{ inputs.ephemeral_env_branch }}
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
ephemeral_env_branch:
8+
required: true
9+
type: string
10+
project:
11+
type: string
12+
default: server
13+
cleanup_config:
14+
type: boolean
15+
sync_environment:
16+
type: boolean
17+
pull_request_number:
18+
type: number
19+
workflow_dispatch:
20+
inputs:
21+
ephemeral_env_branch:
22+
type: string
23+
required: true
24+
project:
25+
type: string
26+
default: server
27+
cleanup_config:
28+
type: boolean
29+
sync_environment:
30+
type: boolean
31+
pull_request_number:
32+
type: number
33+
34+
env:
35+
_KEY_VAULT: bitwarden-ci
36+
_BOT_NAME: bitwarden-devops-bot
37+
38+
jobs:
39+
check-run:
40+
name: Check PR run
41+
uses: ./.github/workflows/check-run.yml
42+
43+
cleanup:
44+
name: Cleanup config
45+
if: ${{ inputs.cleanup_config }}
46+
runs-on: ubuntu-24.04
47+
needs: check-run
48+
steps:
49+
- name: Login to Azure - Prod Subscription
50+
uses: Azure/login@a65d910e8af852a8061c627c456678983e180302 # v2.2.0
51+
with:
52+
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
53+
54+
- name: Retrieve secrets
55+
id: retrieve-secrets
56+
uses: bitwarden/gh-actions/get-keyvault-secrets@main
57+
with:
58+
keyvault: ${{ env._KEY_VAULT }}
59+
secrets: "github-pat-bitwarden-devops-bot-repo-scope,github-bitwarden-devops-bot-email"
60+
61+
- name: Checkout ${{ inputs.project }}
62+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
63+
with:
64+
repository: bitwarden/${{ inputs.project }}
65+
ref: ${{ inputs.ephemeral_env_branch }}
66+
token: '${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}'
67+
68+
- name: Remove config
69+
working-directory: ephemeral-environments
70+
run: rm -f ${{ inputs.ephemeral_env_branch }}.yaml
71+
72+
- name: Commit changes to ${{ inputs.ephemeral_env_branch }}
73+
working-directory: ephemeral-environments
74+
run: |
75+
git config --local user.email "${{ steps.retrieve-secrets.outputs.github-bitwarden-devops-bot-email }}"
76+
git config --local user.name "${{ env._BOT_NAME }}"
77+
78+
git add ${{ inputs.ephemeral_env_branch }}.yaml
79+
git commit -m "Removed ${{ inputs.ephemeral_env_branch }}.yaml config."
80+
git push
81+
82+
sync-env:
83+
name: Sync Ephemeral Environment
84+
if: ${{ inputs.sync_environment }}
85+
runs-on: ubuntu-24.04
86+
needs: check-run
87+
steps:
88+
- name: Login to Azure - Prod Subscription
89+
uses: Azure/login@a65d910e8af852a8061c627c456678983e180302 # v2.2.0
90+
with:
91+
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
92+
93+
- name: Retrieve secrets
94+
id: retrieve-secrets
95+
uses: bitwarden/gh-actions/get-keyvault-secrets@main
96+
with:
97+
keyvault: ${{ env._KEY_VAULT }}
98+
secrets: |
99+
ephemeral-environment-argocd-cluster-url,
100+
ephemeral-environment-argocd-cluster-api-secret,
101+
ephemeral-environment-argocd-cluster-api-user
102+
103+
- name: Install ArgoCD CLI
104+
run: |
105+
curl -sSL -o argocd-linux-amd64 \
106+
"https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64"
107+
108+
install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
109+
argocd version --client
110+
rm argocd-linux-amd64
111+
112+
- name: Log into Argo CD cluster
113+
run: |
114+
argocd login ${{ steps.retrieve-secrets.outputs.ephemeral-environment-argocd-cluster-url }} \
115+
--username ${{ steps.retrieve-secrets.outputs.ephemeral-environment-argocd-cluster-api-user }} \
116+
--password ${{ steps.retrieve-secrets.outputs.ephemeral-environment-argocd-cluster-api-secret }}
117+
118+
- name: Sync ${{ inputs.ephemeral_env_branch }} application
119+
run: |
120+
APP_NAME=$(argocd app list -o name | grep ${{ inputs.pull_request_number }})
121+
argocd app sync "$APP_NAME"

0 commit comments

Comments
 (0)