update google cloud auth action #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Preview Deployment Callable Workflow | ||
description: This will create a preview environment | ||
on: | ||
workflow_call: [ ] | ||
inputs: | ||
image_tag: | ||
description: 'Tag to set on the docker image' | ||
required: true | ||
github_token: | ||
description: 'GitHub token' | ||
required: true | ||
preview_branch_name: | ||
description: 'Short name for the branch for preview environment' | ||
required: true | ||
image_name: | ||
description: 'Name of the image' | ||
required: true | ||
development_gke_wip: | ||
description: 'Name of the development GKE WIP' | ||
required: true | ||
development_gke_service_account: | ||
description: 'Name of the development GKE WIP' | ||
required: true | ||
jobs: | ||
preview_deploy: | ||
runs-on: frontend-runners | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
steps: | ||
- id: "auth" | ||
name: "Authenticate to Google Cloud" | ||
uses: "google-github-actions/auth@v1" | ||
with: | ||
token_format: "access_token" | ||
workload_identity_provider: "${{ inputs.development_gke_wip }}" | ||
service_account: ${{ inputs.development_gke_service_account }} | ||
- name: 'Set up cloud sdk' | ||
uses: 'google-github-actions/setup-gcloud@v1' | ||
- name: "Get current configmap for dashboard-frontend" | ||
id: "get_configmap" | ||
run: |- | ||
[ -d ~/.kube ] ||mkdir -p ~/.kube | ||
gcloud container clusters get-credentials ultimateai-development-main-1 --region europe-west1 --project development-main-wtf1 | ||
configmap_name=$(kubectl get configmaps -n frontend | grep dashboard-frontend-dev-conf | awk '{print $1}') | ||
echo "::set-output name=configmap_name::$configmap_name" | ||
shell: bash | ||
- name: Update the apps in deployment file and service file with branch names | ||
run: |- | ||
sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/deployment.yaml" | ||
sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/service.yaml" | ||
env: | ||
preview_branch_name: ${{ inputs.preview_branch_name }} | ||
shell: bash | ||
- name: Update the current configmap in deployment file | ||
run: |- | ||
sed -i "s/configmap-name/$current_configmap_name/g" "preview_deploy/deployment.yaml" | ||
env: | ||
current_configmap_name: ${{ steps.get_configmap.outputs.configmap_name }} | ||
shell: bash | ||
- name: Update the image tag in deploymet file | ||
run: |- | ||
sed -i "s/tag-name/$image_tag/g" "preview_deploy/deployment.yaml" | ||
env: | ||
image_tag: ${{ inputs.image_tag }} | ||
shell: bash | ||
- name: Read deployment file | ||
id: deployment_file | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: preview_deploy/deployment.yaml | ||
- name: Echo deployment file | ||
run: echo "${{ steps.deployment_file.outputs.content }}" | ||
shell: bash | ||
- name: Read service file | ||
id: service_file | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: preview_deploy/service.yaml | ||
- name: Echo service file | ||
run: echo "${{ steps.service_file.outputs.content }}" | ||
shell: bash | ||
- name: "Checkout dashboard-frontend k8s manifests" | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ultimateai/k8s-manifests | ||
token: ${{ inputs.github_token }} | ||
- name: Add the Preview files deployment files | ||
run: |- | ||
cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} | ||
touch $preview_branch_name-deployment.yaml | ||
touch $preview_branch_name-service.yaml | ||
cat /dev/null > $preview_branch_name-deployment.yaml | ||
cat /dev/null > $preview_branch_name-service.yaml | ||
echo -e "$deployment_file" >> $preview_branch_name-deployment.yaml | ||
echo -e "$service_file" >> $preview_branch_name-service.yaml | ||
env: | ||
service_file: ${{ steps.service_file.outputs.content }} | ||
deployment_file: ${{ steps.deployment_file.outputs.content }} | ||
preview_branch_name: ${{ inputs.preview_branch_name }} | ||
K8S_ENV_NAME: development | ||
shell: bash | ||
- name: Update the kustomize file of the preview environment | ||
run: |- | ||
cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} | ||
check_deployment_file=$(preview_deployment_file=$preview_branch_name-deployment.yaml yq '(.resources[] | select (test(env(preview_deployment_file)))' kustomization.yaml) | ||
if [[ -z $check_deployment_file ]];then | ||
echo "Entries Not found for $preview_branch_name-deployment.yaml. Adding Entry for $preview_branch_name-deployment.yaml." | ||
preview_deployment_file=$preview_branch_name-deployment.yaml yq -i '.resources += env(preview_deployment_file)' kustomization.yaml | ||
else | ||
echo "Entries found for $preview_branch_name-deployment.yaml. No action required." | ||
fi | ||
check_service_file=$(preview_service_file=$preview_branch_name-service.yaml yq '(.resources[] | select (test(env(preview_service_file)))' kustomization.yaml) | ||
if [[ -z $check_service_file ]];then | ||
echo "Entries Not found for $preview_branch_name-service.yaml. Adding Entry for $preview_branch_name-service.yaml." | ||
preview_service_file=$preview_branch_name-service.yaml yq -i '.resources += env(preview_service_file)' kustomization.yaml | ||
else | ||
echo "Entries found for $preview_branch_name-service.yaml. No action required." | ||
fi | ||
env: | ||
K8S_ENV_NAME: development | ||
preview_branch_name: ${{ inputs.preview_branch_name }} | ||
shell: bash | ||
- name: Update the ingress file of the preview environment path | ||
run: |- | ||
cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} | ||
preview_path=$preview_branch_name | ||
check_path=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) | ||
if [[ -z $check_path ]]; then | ||
echo "No Entries found /$preview_branch_name in ingress path. Adding the required path." | ||
preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths +=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml | ||
else | ||
echo "Entries found for /$preview_branch_name in path ingress.yaml. No action required." | ||
fi | ||
git config --local user.email "86783263+ultimateai-bot@users.noreply.github.com" | ||
git add $preview_branch_name-deployment.yaml | ||
git add $preview_branch_name-service.yaml | ||
git config --local user.name "ultimateai-bot" | ||
git commit -m "Adding $preview_branch_name-deployment.yaml file with ${IMAGE_NAME}:${TAGS} & $preview_branch_name-service.yaml file" -a | ||
git push ${REMOTE_REPO} HEAD:main --force | ||
env: | ||
REMOTE_REPO: https://${{ inputs.github_token }}@github.com/ultimateai/k8s-manifests.git | ||
K8S_ENV_NAME: development | ||
preview_branch_name: ${{ inputs.preview_branch_name }} | ||
TAGS: ${{ inputs.image_tag }} | ||
shell: bash |