From 295e2a2000b4135329da2a214760eea31c047cb0 Mon Sep 17 00:00:00 2001 From: Ori Hoch Date: Fri, 2 Feb 2024 13:47:51 +0200 Subject: [PATCH] add ci --- .github/workflows/ci.yml | 12 +++++++- README.md | 56 ++++++++++++++++++++++++++++++++++++++ cwm_worker_operator/cli.py | 4 +++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5015265..e3bf489 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CWM_WORKER_HELM_DEPLOY_KEY: ${{ secrets.CWM_WORKER_HELM_DEPLOY_KEY }} + CWM_WORKER_CLUSTER_DEPLOY_KEY: ${{ secrets.CWM_WORKER_CLUSTER_DEPLOY_KEY }} CWM_API_URL: ${{ secrets.CWM_API_URL }} CWM_API_KEY: ${{ secrets.CWM_API_KEY }} CWM_API_SECRET: ${{ secrets.CWM_API_SECRET }} @@ -88,7 +89,16 @@ jobs: if [ "$(uci github actions get-branch-name)" == "main" ]; then uci docker tag-push \ --source-tag-name cwm_worker_operator \ - --push-tag-name "ghcr.io/cloudwebmanage/cwm-worker-operator/cwm_worker_operator:latest" + --push-tag-name "ghcr.io/cloudwebmanage/cwm-worker-operator/cwm_worker_operator:latest" &&\ + uci git checkout \ + --github-repo-name CloudWebManage/cwm-worker-cluster \ + --branch-name master \ + --ssh-key "${CWM_WORKER_CLUSTER_DEPLOY_KEY}" \ + --path cwm-worker-cluster \ + --config-user-name cwm-worker-operator-ci &&\ + cd cwm-worker-cluster &&\ + bin/update_cluster_image.py cwm-worker-operator $GITHUB_SHA --git-commit &&\ + git push origin master fi - uses: 8398a7/action-slack@v3 diff --git a/README.md b/README.md index 2cac46a..1e6c688 100644 --- a/README.md +++ b/README.md @@ -210,3 +210,59 @@ kubectl port-forward service/cwm-worker-operator-redis-internal 6379 ``` For more details, refer to the [CI workflow](./.github/workflows/ci.yml). + +## Local Development on real cluster + +Follow the steps in Local Development section until Start Infrastructure, then continue with the following steps: + +```shell +# Set the cluster env vars depending on the cluster you want to connect to, you should only use dev / testing clusters +export CLUSTER_NAME=cwmc-eu-v2test +export CWM_ZONE=eu-test +export DNS_RECORDS_PREFIX=$CLUSTER_NAME + +# Get a fresh token from Vault +export VAULT_TOKEN= + +cd ../cwm-worker-cluster +eval "$(venv/bin/cwm-worker-cluster cluster connect $CLUSTER_NAME)" +popd >/dev/null + +# Optionally, enable full verbosity debugging +export DEBUG=yes +export DEBUG_VERBOSITY=10 + +# Set env vars to point to the Redis databases (we will start port-forwarding later) +export INGRESS_REDIS_PORT=6381 +export INTERNAL_REDIS_PORT=6382 +export METRICS_REDIS_PORT=6383 +export INTERNAL_REDIS_DB=0 +export METRICS_REDIS_DB=0 +``` + +Start port-forwarding to the Redis databases (you can run this multiple times if a forward was stopped): + +```shell +lsof -i:6381 >/dev/null || kubectl -n cwm-worker-ingress port-forward service/cwm-worker-ingress-operator-redis 6381:6379 >/dev/null 2>&1 & +lsof -i:6382 >/dev/null || kubectl -n cwm-operator port-forward service/cwm-worker-operator-redis-internal 6382:6379 >/dev/null 2>&1 & +lsof -i:6383 >/dev/null || kubectl -n cwm-operator port-forward service/cwm-worker-operator-redis-metrics 6383:6379 >/dev/null 2>&1 & +``` + +Stop the relevant operator daemones running on the cluster to prevent conflicts. First, disable argocd autosync, +then scale the relevant deployments to 0, for example: + +```shell +kubectl -n cwm-operator scale deployment deployer --replicas=0 +``` + +Now you can run operator commands for the relevant daemons, for example: + +``` +cwm-worker-operator deployer start_daemon --once +``` + +When done, terminate the background jobs: + +``` +kill $(jobs -p) +``` diff --git a/cwm_worker_operator/cli.py b/cwm_worker_operator/cli.py index 5f1d892..b562a08 100644 --- a/cwm_worker_operator/cli.py +++ b/cwm_worker_operator/cli.py @@ -176,3 +176,7 @@ def send_agg_metrics(worker_id, minutes_json): import json from cwm_worker_operator.cwm_api_manager import CwmApiManager CwmApiManager().send_agg_metrics(worker_id, json.loads(minutes_json)) + + +if __name__ == '__main__': + main()