From 5041bcb177e3ff3b0720a3f2110723235d0c1d42 Mon Sep 17 00:00:00 2001 From: Rajesh Rajendran Date: Tue, 17 May 2022 20:07:02 +0000 Subject: [PATCH] GH aciton with new format (#479) * chore(actions): update GH Actions to new deployment format Signed-off-by: rjshrjndrn * fix(actions): yaml indentation Signed-off-by: rjshrjndrn * fix(actions): image override helm doesn't support multipart yaml files. Signed-off-by: rjshrjndrn * chore(action): enable docker image cache Signed-off-by: rjshrjndrn * chore(actions): chalice deployment Signed-off-by: rjshrjndrn * chore(actions): check previous image prior deploying Because we're using an umbrella chart and not storing the image tags which is deployed from actions anywhere, a new deployment will reset all older deployed image tags. For that we've to fetch the existing image tags and feed it to the current deployment. Signed-off-by: rjshrjndrn * fix(actions): static path the build input Signed-off-by: rjshrjndrn * chore(actions): adding dev branch to chalice deployment Signed-off-by: rjshrjndrn --- .github/workflows/api.yaml | 48 +++++++++++++++++++++---- .github/workflows/workers.yaml | 64 ++++++++++++++++++++++++++-------- 2 files changed, 91 insertions(+), 21 deletions(-) diff --git a/.github/workflows/api.yaml b/.github/workflows/api.yaml index 9fe8c5611..b721f21ee 100644 --- a/.github/workflows/api.yaml +++ b/.github/workflows/api.yaml @@ -3,6 +3,7 @@ on: workflow_dispatch: push: branches: + - dev - api-v1.5.5 paths: - api/** @@ -32,6 +33,12 @@ jobs: kubeconfig: ${{ secrets.OSS_KUBECONFIG }} # Use content of kubeconfig in secret. id: setcontext + # Caching docker images + - uses: satackey/action-docker-layer-caching@v0.0.11 + # Ignore the failure of a step and avoid terminating the job. + continue-on-error: true + + - name: Building and Pusing api image id: build-image env: @@ -41,15 +48,42 @@ jobs: run: | cd api PUSH_IMAGE=1 bash build.sh + - name: Creating old image input + run: | + # + # Create yaml with existing image tags + # + kubectl get pods -n app -o jsonpath="{.items[*].spec.containers[*].image}" |\ + tr -s '[[:space:]]' '\n' | sort | uniq -c | grep '/foss/' | cut -d '/' -f3 > /tmp/image_tag.txt + + echo > /tmp/image_override.yaml + + for line in `cat /tmp/image_tag.txt`; + do + image_array=($(echo "$line" | tr ':' '\n')) + cat <> /tmp/image_override.yaml + ${image_array[0]}: + image: + tag: ${image_array[1]} + EOF + done + - name: Deploy to kubernetes run: | - cd scripts/helm/ - sed -i "s#minio_access_key.*#minio_access_key: \"${{ secrets.OSS_MINIO_ACCESS_KEY }}\" #g" vars.yaml - sed -i "s#minio_secret_key.*#minio_secret_key: \"${{ secrets.OSS_MINIO_SECRET_KEY }}\" #g" vars.yaml - sed -i "s#domain_name.*#domain_name: \"foss.openreplay.com\" #g" vars.yaml - sed -i "s#kubeconfig.*#kubeconfig_path: ${KUBECONFIG}#g" vars.yaml - sed -i "s/image_tag:.*/image_tag: \"$IMAGE_TAG\"/g" vars.yaml - bash kube-install.sh --app chalice + cd scripts/helmcharts/ + + ## Update secerts + sed -i "s/postgresqlPassword: \"changeMePassword\"/postgresqlPassword: \"${{ secrets.OSS_PG_PASSWORD }}\"/g" vars.yaml + sed -i "s/accessKey: \"changeMeMinioAccessKey\"/accessKey: \"${{ secrets.OSS_MINIO_ACCESS_KEY }}\"/g" vars.yaml + sed -i "s/secretKey: \"changeMeMinioPassword\"/secretKey: \"${{ secrets.OSS_MINIO_SECRET_KEY }}\"/g" vars.yaml + sed -i "s/jwt_secret: \"SetARandomStringHere\"/jwt_secret: \"${{ secrets.OSS_JWT_SECRET }}\"/g" vars.yaml + sed -i "s/domainName: \"\"/domainName: \"${{ secrets.OSS_DOMAIN_NAME }}\"/g" vars.yaml + + # Update changed image tag + sed -i "/chalice/{n;n;s/.*/ tag: ${IMAGE_TAG}/}" /tmp/image_override.yaml + + # Deploy command + helm upgrade --install openreplay -n app openreplay -f vars.yaml -f /tmp/image_override.yaml env: DOCKER_REPO: ${{ secrets.OSS_REGISTRY_URL }} IMAGE_TAG: ${{ github.sha }} diff --git a/.github/workflows/workers.yaml b/.github/workflows/workers.yaml index e6a91647d..5a43446af 100644 --- a/.github/workflows/workers.yaml +++ b/.github/workflows/workers.yaml @@ -33,7 +33,12 @@ jobs: kubeconfig: ${{ secrets.OSS_KUBECONFIG }} # Use content of kubeconfig in secret. id: setcontext - - name: Build, tag, and Deploy to k8s + # Caching docker images + - uses: satackey/action-docker-layer-caching@v0.0.11 + # Ignore the failure of a step and avoid terminating the job. + continue-on-error: true + + - name: Build, tag id: build-image env: DOCKER_REPO: ${{ secrets.OSS_REGISTRY_URL }} @@ -47,42 +52,73 @@ jobs: # # Getting the images to build # - + set -x { git diff --name-only HEAD HEAD~1 | grep -E "backend/cmd|backend/services" | grep -vE ^ee/ | cut -d '/' -f3 git diff --name-only HEAD HEAD~1 | grep -E "backend/pkg|backend/internal" | grep -vE ^ee/ | cut -d '/' -f3 | uniq | while read -r pkg_name ; do grep -rl "pkg/$pkg_name" backend/services backend/cmd | cut -d '/' -f3 done - } | uniq > backend/images_to_build.txt + } | uniq > /tmp/images_to_build.txt - [[ $(cat backend/images_to_build.txt) != "" ]] || (echo "Nothing to build here"; exit 0) + [[ $(cat /tmp/images_to_build.txt) != "" ]] || (echo "Nothing to build here"; exit 0) # # Pushing image to registry # cd backend - for image in $(cat images_to_build.txt); + for image in $(cat /tmp/images_to_build.txt); do echo "Bulding $image" PUSH_IMAGE=1 bash -x ./build.sh skip $image echo "::set-output name=image::$DOCKER_REPO/$image:$IMAGE_TAG" done + - name: Creating old image input + env: + IMAGE_TAG: ${{ github.sha }} + run: | + # + # Create yaml with existing image tags + # + kubectl get pods -n app -o jsonpath="{.items[*].spec.containers[*].image}" |\ + tr -s '[[:space:]]' '\n' | sort | uniq -c | grep '/foss/' | cut -d '/' -f3 > /tmp/image_tag.txt + + echo > /tmp/image_override.yaml + + for line in `cat /tmp/image_tag.txt`; + do + image_array=($(echo "$line" | tr ':' '\n')) + cat <> /tmp/image_override.yaml + ${image_array[0]}: + image: + tag: ${image_array[1]} + EOF + done + + - name: Deploying to kuberntes + env: + IMAGE_TAG: ${{ github.sha }} + run: | # # Deploying image to environment. # - cd ../scripts/helm/ - sed -i "s#minio_access_key.*#minio_access_key: \"${{ secrets.OSS_MINIO_ACCESS_KEY }}\" #g" vars.yaml - sed -i "s#minio_secret_key.*#minio_secret_key: \"${{ secrets.OSS_MINIO_SECRET_KEY }}\" #g" vars.yaml - sed -i "s#domain_name.*#domain_name: \"foss.openreplay.com\" #g" vars.yaml - sed -i "s#kubeconfig.*#kubeconfig_path: ${KUBECONFIG}#g" vars.yaml - for image in $(cat ../../backend/images_to_build.txt); + cd scripts/helmcharts/ + + ## Update secerts + sed -i "s/postgresqlPassword: \"changeMePassword\"/postgresqlPassword: \"${{ secrets.OSS_PG_PASSWORD }}\"/g" vars.yaml + sed -i "s/accessKey: \"changeMeMinioAccessKey\"/accessKey: \"${{ secrets.OSS_MINIO_ACCESS_KEY }}\"/g" vars.yaml + sed -i "s/secretKey: \"changeMeMinioPassword\"/secretKey: \"${{ secrets.OSS_MINIO_SECRET_KEY }}\"/g" vars.yaml + sed -i "s/jwt_secret: \"SetARandomStringHere\"/jwt_secret: \"${{ secrets.OSS_JWT_SECRET }}\"/g" vars.yaml + sed -i "s/domainName: \"\"/domainName: \"${{ secrets.OSS_DOMAIN_NAME }}\"/g" vars.yaml + ## Update images + for image in $(cat /tmp/images_to_build.txt); do - sed -i "s/image_tag:.*/image_tag: \"$IMAGE_TAG\"/g" vars.yaml - # Deploy command - bash kube-install.sh --app $image + sed -i "/${image}/{n;n;s/.*/ tag: ${IMAGE_TAG}/}" /tmp/image_override.yaml done + # Deploy command + helm upgrade --install openreplay -n app openreplay -f vars.yaml -f /tmp/image_override.yaml + # - name: Debug Job # if: ${{ failure() }} # uses: mxschmitt/action-tmate@v3