Skip to content

Reindex data on production environment #32

Reindex data on production environment

Reindex data on production environment #32

Workflow file for this run

name: Reindex data
run-name: "Reindex data on ${{ inputs.environment }} environment"
on:
workflow_dispatch:
inputs:
environment:
description: "Target environment"
required: true
default: "dev"
type: choice
options:
- demo1
- production
- staging
workflow_call:
inputs:
environment:
type: string
jobs:
reindex:
environment: ${{ inputs.environment }}
env:
namespace: opencrvs-${{ inputs.environment }}
runs-on:
- self-hosted
- k8s
- ${{ inputs.environment }}
steps:
- name: Get helm release values and Quote specific fields that are commonly numeric
run: |
helm get values opencrvs -n ${namespace} -ojson | \
jq '
if has("image") and (.image | has("tag")) and (.image.tag | type == "number") then
.image.tag = (.image.tag | tostring)
else . end |
if has("version") and (.version | type == "number") then
.version = (.version | tostring)
else . end |
if has("service") and (.service | has("port")) and (.service.port | type == "number") then
.service.port = (.service.port | tostring)
else . end
' > ${namespace}.json
- name: Create job elasticsearch-reindex from helm template and apply it
run: |
kubectl delete job -n ${namespace} --ignore-not-found=true elasticsearch-reindex
helm template -f ${namespace}.json \
--namespace ${namespace} \
-s templates/elasticsearch-reindex-job.yaml \
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply --wait -n ${namespace} -f -
- name: Checking elasticsearch-reindex job status
run: |
while true; do
kubectl wait --for=condition=ready pod -ljob-name=elasticsearch-reindex --timeout=300s -n ${namespace} && \
kubectl logs job/elasticsearch-reindex --all-containers -f -n ${namespace} && \
touch /tmp/logs_stramed-${namespace}-elasticsearch-reindex.txt || break;
sleep 10; done &
echo "---------------------- Waiting for job completion ----------------------"
kubectl wait --for=condition=complete job/elasticsearch-reindex -n ${namespace} --timeout=600s; status=$? || true
[ $status -ne 0 ] && kubectl get pods -n ${namespace} --show-labels && kubectl describe pod -ljob-name=${job_name} -n ${namespace};
[ ! -f /tmp/logs_stramed-${namespace}-elasticsearch-reindex.txt ] && kubectl logs job/elasticsearch-reindex --all-containers -n ${namespace} || \
rm -vf /tmp/logs_stramed-${namespace}-elasticsearch-reindex.txt
kill %1 2>/dev/null && echo "Stopped log streaming" || true
exit $status