Skip to content

Update All User Environments #8

Update All User Environments

Update All User Environments #8

name: "Update All User Environments"
on:
schedule:
- cron: '0 6 * * 0'
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-all-demo-environments:
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.set_branches.outputs.branches }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get all branches and loop through them
id: set_branches
run: |
git fetch --all
branches_to_update="["
for branch in $(git branch -r | grep -v '\->' | grep 'demoenv'); do
branch=${branch#origin/}
echo "Branch $branch is a demo environment"
branches_to_update="$branches_to_update\"$branch\","
done
branches_to_update="${branches_to_update%,}]" # Remove trailing comma and close the array
echo "BRANCHES=$branches_to_update" >> $GITHUB_OUTPUT
update-all-demo-environments:
needs: get-all-demo-environments
runs-on: ubuntu-latest
env:
BRANCHES: ${{ needs.get-all-demo-environments.outputs.branches }}
strategy:
fail-fast: false
matrix:
branch: ${{ fromJson(needs.get-all-demo-environments.outputs.branches) }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup branch environment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Updating branch ${{ matrix.branch }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git fetch
git checkout ${{ matrix.branch }}
git merge origin/main --no-edit
- name: Get Namespace
id: get-namespace
run: |
NAMESPACE="${{ matrix.branch }}"
NAMESPACE=${NAMESPACE#demoenv-}
echo "DEMO_NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
- 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: Get LD Env Vars for Demo Environment
id: create_ld_project
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/create_ld_project.py
- name: Create .env file
run: |
touch ./.env.production
echo NEXT_PUBLIC_LD_CLIENT_KEY=${{ env.LD_CLIENT_KEY }} >> ./.env.production
echo LD_SDK_KEY=${{ env.LD_SDK_KEY }} >> ./.env.production
echo DB_URL=${{ secrets.DB_URL }} >> ./.env.production
echo LD_API_KEY=${{ secrets.LD_API_KEY }} >> ./.env.production
echo DESTINATIONENV=${{ env.DEMO_NAMESPACE }} >> ./.env.production
echo PROJECT_KEY=${{ env.DEMO_NAMESPACE }}-ld-demo >> ./.env.production
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ld-core-demo
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
- name: Update K8s Deploy File
run: python ./.github/workflows/update_k8s_deploy_file.py
env:
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
URL: ${{ env.DEMO_NAMESPACE }}.launchdarklydemos.com
IMAGE: ${{ steps.login-ecr.outputs.registry }}/ld-core-demo:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
- name: Check Namespace in Kubernetes
uses: kodermax/kubectl-aws-eks@master
with:
args: get namespace ${{ env.DEMO_NAMESPACE }} &>/dev/null && echo "namespace_exists=true" >> $GITHUB_ENV || echo "namespace_exists=false" >> $GITHUB_ENV
- name: Create Namespace In Kubernetes
if: env.namespace_exists == 'false'
uses: kodermax/kubectl-aws-eks@master
with:
args: create namespace ${{ env.DEMO_NAMESPACE }}
- name: Applying deploy file to Kubernetes
uses: kodermax/kubectl-aws-eks@master
with:
args: apply -f ./.github/workflows/deploy_files/deploy.yaml -n ${{ env.DEMO_NAMESPACE }}
- name: Delete the deploy file
run: rm -rf ./.github/workflows/deploy_files
- name: Remove .env file
run: rm ./.env.production