From cbc2e4f1474ef2bbb28234924e3b369560a2017e Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 6 Jan 2026 20:45:02 -0600 Subject: [PATCH] Build coturn-dns and use it --- bitbucket-pipelines.yml | 21 +++++++++++- docker/coturn-dns/pod-node-register.py | 47 ++++++++++++++++---------- k8s/coturn-dns/values-staging.yaml | 2 +- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 1da50c6..c3f32c9 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -169,4 +169,23 @@ pipelines: - pipe: atlassian/kubectl-run:1.1.2 variables: KUBE_CONFIG: $KUBE_CONFIG_STG - KUBECTL_COMMAND: '-n coturn-dns rollout status -w deployment/coturn-dns' \ No newline at end of file + KUBECTL_COMMAND: '-n coturn-dns rollout status -w deployment/coturn-dns' + custom: + build-and-push-coturn-dns: + - variables: + - name: VERSION + default: "1.0.10" + - step: + name: Build and Push coturn-dns + image: google/cloud-sdk:alpine + script: + # Authenticating with the service account key file + - echo $GCLOUD_API_KEYFILE | base64 -d > ./gcloud-api-key.json + - gcloud auth activate-service-account --key-file gcloud-api-key.json + - gcloud config set project $GCLOUD_PROJECT + - cat ./gcloud-api-key.json | docker login -u _json_key --password-stdin https://gcr.io + # Build and Push Docker image + - docker build . --file docker/coturn-dns/Dockerfile --tag "gcr.io/${GCLOUD_PROJECT}/coturn-dns:${VERSION}" + - docker push "gcr.io/${GCLOUD_PROJECT}/coturn-dns:${VERSION}" + services: + - docker diff --git a/docker/coturn-dns/pod-node-register.py b/docker/coturn-dns/pod-node-register.py index 36a3a08..dcf0151 100644 --- a/docker/coturn-dns/pod-node-register.py +++ b/docker/coturn-dns/pod-node-register.py @@ -18,33 +18,46 @@ def validIPAddress(IP: str) -> str: return "Invalid" while(True): - ips=[] + ips_set = set() pods = v1.list_namespaced_pod(namespace="coturn") for i in pods.items: + if not i.spec.node_name: + continue node_status = v1.read_node(name=i.spec.node_name) for adr in node_status.status.addresses: # only collect IPv4 addresses, because we are only updating A records here if adr.type=="ExternalIP" and validIPAddress(adr.address) == "IPv4": - ips.append({'Value': adr.address}) + ips_set.add(adr.address) + ips = [{'Value': ip} for ip in sorted(list(ips_set))] print("Node IPs: "+str(ips)) + if not ips: + print("No IPs found to update. Sleeping.") + time.sleep(60) + continue + client = boto3.client('route53') - response = client.change_resource_record_sets( - HostedZoneId=HOSTED_ZONE, - ChangeBatch= { - 'Comment': 'COTURN NODES', - 'Changes': [ - { - 'Action': 'UPSERT', - 'ResourceRecordSet': { - 'Name': COTURN_DOMAIN_NAME, - 'Type': 'A', - 'TTL': 300, - 'ResourceRecords': ips - } - }] - }) + try: + response = client.change_resource_record_sets( + HostedZoneId=HOSTED_ZONE, + ChangeBatch= { + 'Comment': 'COTURN NODES', + 'Changes': [ + { + 'Action': 'UPSERT', + 'ResourceRecordSet': { + 'Name': COTURN_DOMAIN_NAME, + 'Type': 'A', + 'TTL': 300, + 'ResourceRecords': ips + } + }] + }) + print("Successfully updated Route53: " + str(response['ChangeInfo']['Id'])) + except Exception as e: + print(f"Error updating Route53: {e}") + time.sleep(60) \ No newline at end of file diff --git a/k8s/coturn-dns/values-staging.yaml b/k8s/coturn-dns/values-staging.yaml index 62b29d2..fca764e 100644 --- a/k8s/coturn-dns/values-staging.yaml +++ b/k8s/coturn-dns/values-staging.yaml @@ -1,3 +1,3 @@ domain: "staging.video.jamkazam.com" # The docker image tag for coturn-dns in GCR -coturn_dns_image_tag: 1.0.9 +coturn_dns_image_tag: 1.0.10