Skip to content

Remove Demo Environment From K8s and LD #251

Remove Demo Environment From K8s and LD

Remove Demo Environment From K8s and LD #251

name: "Remove Demo Environment From K8s and LD"
on:
delete:
branches:
- '*demoenv*'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
ECR_REPOSITORY: ld-core-demo
KUBECTL_VERSION: "v1.23.0"
LD_API_KEY: ${{ secrets.LD_API_KEY }}
jobs:
get-branch-name:
runs-on: ubuntu-latest
outputs:
branch_name: ${{ steps.set_branch_name.outputs.branch_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get deleted branch name
id: set_branch_name
run: |
echo "DELETED_BRANCH_NAME=${{ github.event.ref }}"
echo "BRANCH_NAME=${{ github.event.ref }}" >> $GITHUB_ENV
echo "::set-output name=branch_name::${{ github.event.ref }}"
remove-demoenv:
needs: get-branch-name
if: contains(needs.get-branch-name.outputs.branch_name, 'demoenv')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set namespace for deployment
id: set_namespace
run: |
BRANCH_REF=${{ github.event.ref }}
NAMESPACE=${BRANCH_REF#demoenv-}
echo "DEMO_NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
echo "::set-output name=namespace::$NAMESPACE"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./.github/workflows/requirements.txt
- name: Delete LD Project for User
id: delete_ld_project
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Deleting LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/delete_ld_project.py
- name: Delete Kubernetes Namespace
uses: kodermax/kubectl-aws-eks@master
with:
args: delete namespace ${{ env.DEMO_NAMESPACE }}