diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..41d0722 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,172 @@ +name: Release Helm Charts + +# Do not change this +concurrency: release-helm + +on: + workflow_dispatch: + push: + +jobs: + release: + runs-on: ubuntu-latest + outputs: + changed-charts: ${{ steps.get-changed-charts.outputs.changed-charts }} + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + path: 'src' + fetch-depth: 0 + + - name: Checkout + uses: actions/checkout@v4 + with: + path: 'dest' + ref: 'gh-pages' + fetch-depth: 0 + + - name: Install Helm + uses: azure/setup-helm@v1 + + - name: Set version to -prerelease on non-major branches + if: github.ref != 'refs/heads/main' + shell: bash + run: | + for chart in $(find . -type f -name 'Chart.yaml'); do + yq e '.version |= (. + "-prerelease")' ${chart} > tmp-Chart.yaml + mv tmp-Chart.yaml ${chart} + done + + - name: Sync README.md + if: github.ref == 'refs/heads/main' + shell: bash + run: | + cp src/README.md dest/README.md + + - name: debug stuff + shell: bash + run: | + find . + jq --version + + - name: Package Helm Charts + shell: bash + run: | + find . -type f -name 'Chart.yaml' | sed -r 's|/[^/]+$||' | sort | uniq | xargs -L 1 helm dep up + for d in `find ./src/* -type d -maxdepth 0 -not -name examples` ; do + echo "$d" + helm package "$d" -u -d dest + done + + - name: Push New Files + shell: bash + working-directory: dest + run: | + helm repo index . --url https://raw.githubusercontent.com/laerdallabs/livekit-helm/gh-pages/ + git config user.name "Helm Updater" + git config user.email "actions@users.noreply.github.com" + git add . + git commit -m "Updated from ref: $GITHUB_SHA" + git push + + - name: Identify Updated Charts + id: get-changed-charts + if: github.ref == 'refs/heads/main' + shell: bash + working-directory: src + run: | + changed_charts="$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep "Chart.yaml" | jq -R . | jq -sc .)" + echo "changed-charts=${changed_charts}" + echo "changed-charts=${changed_charts}" >> $GITHUB_OUTPUT + + create-releases: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' && needs.release.outputs.changed-charts != '[]' + needs: release + strategy: + matrix: + chart: ${{fromJson(needs.release.outputs.changed-charts)}} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout + uses: actions/checkout@v4 + with: + path: 'gh-pages' + ref: 'gh-pages' + fetch-depth: 0 + + - name: Set Release Vars + id: set-vars + run: | + chart_name="$(yq e '.name' ${{ matrix.chart }})" + chart_version="$(yq e '.version' ${{ matrix.chart }})" + chart_description="$(yq e '.description' ${{ matrix.chart }})" + release_tag="${chart_name}-${chart_version}" + + echo "chart_name=${chart_name}" + echo "chart_version=${chart_version}" + echo "chart_description=${chart_description}" + echo "release_tag=${release_tag}" + + echo "chart_name=${chart_name}" >> $GITHUB_OUTPUT + echo "chart_version=${chart_version}" >> $GITHUB_OUTPUT + echo "chart_description=${chart_description}" >> $GITHUB_OUTPUT + echo "release_tag=${release_tag}" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + + # Define the JSON payload + JSON_PAYLOAD=$(jq -n \ + --arg tag_name "${{ steps.set-vars.outputs.release_tag }}" \ + --arg body "${{ steps.set-vars.outputs.chart_description }}" \ + --arg name "${{ steps.set-vars.outputs.release_tag }}" \ + '{ + tag_name: $tag_name, + name: $name, + body: $body, + draft: false, + prerelease: false + }') + + # Make the API request + RESPONSE=$(curl -XPOST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + --data "$JSON_PAYLOAD" \ + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases") + + # Output the response (optional) + echo "$RESPONSE" + + - name: Upload Release Asset + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ASSET_PATH="gh-pages/${{ steps.set-vars.outputs.release_tag }}.tgz" + ASSET_NAME="$(basename ${ASSET_PATH})" + + # Retrieve the ID of the created release + RELEASE_ID="$( + curl -sH "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${{ steps.set-vars.outputs.release_tag }}" \ + | jq -r '.id' + )" + + # Get the correct upload URL for the asset + UPLOAD_URL="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=$(basename $ASSET_PATH)" + + # Upload the asset + curl -XPOST \ + --data-binary @"$ASSET_PATH" \ + -H "Authorization: token $GITHUB_TOKEN" \ + -H "Content-Type: application/octet-stream" \ + "$UPLOAD_URL" diff --git a/egress/templates/configmap.yaml b/egress/templates/configmap.yaml index 409929d..3c92e25 100644 --- a/egress/templates/configmap.yaml +++ b/egress/templates/configmap.yaml @@ -4,4 +4,9 @@ metadata: name: {{ include "egress.fullname" . }} data: config.yaml: | -{{ toYaml .Values.egress | indent 4 }} +{{- $config := deepCopy .Values.egress }} +{{- if .Values.apiSecretRef }} +{{- $config = unset $config "api_key" }} +{{- $config = unset $config "api_secret" }} +{{- end }} +{{ toYaml $config | indent 4 }} diff --git a/egress/templates/deployment.yaml b/egress/templates/deployment.yaml index 4a8808a..66f4305 100644 --- a/egress/templates/deployment.yaml +++ b/egress/templates/deployment.yaml @@ -20,6 +20,9 @@ spec: checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} labels: {{- include "egress.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} spec: serviceAccountName: {{ include "egress.serviceAccountName" . }} securityContext: @@ -37,6 +40,22 @@ spec: configMapKeyRef: name: {{ include "egress.fullname" . }} key: config.yaml + {{- if .Values.apiSecretRef }} + - name: LIVEKIT_API_KEY + valueFrom: + secretKeyRef: + name: {{ .Values.apiSecretRef }} + key: livekit-api-key + - name: LIVEKIT_API_SECRET + valueFrom: + secretKeyRef: + name: {{ .Values.apiSecretRef }} + key: livekit-api-secret + {{- end }} + {{- if .Values.egress.gst_debug }} + - name: GST_DEBUG + value: "{{ .Values.egress.gst_debug }}" + {{- end }} ports: {{- if .Values.egress.health_port }} - name: health diff --git a/egress/templates/hpa.yaml b/egress/templates/hpa.yaml index ed1651c..ef52e85 100644 --- a/egress/templates/hpa.yaml +++ b/egress/templates/hpa.yaml @@ -42,6 +42,43 @@ spec: {{- end }} {{- end }} {{- if .Values.autoscaling.custom }} + {{- $customType := default "Pods" .Values.autoscaling.custom.type }} + {{- $describedObject := default (dict) .Values.autoscaling.custom.describedObject }} + {{- if eq $customType "Object" }} + - type: Object + object: + {{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }} + describedObject: + apiVersion: {{ default "v1" (get $describedObject "apiVersion") }} + kind: {{ default "Namespace" (get $describedObject "kind") }} + name: {{ default .Release.Namespace (get $describedObject "name") }} + metric: + name: {{ .Values.autoscaling.custom.metricName }} + target: + type: Value + value: {{ .Values.autoscaling.custom.targetValue }} + {{- else }} + target: + apiVersion: {{ default "v1" (get $describedObject "apiVersion") }} + kind: {{ default "Namespace" (get $describedObject "kind") }} + name: {{ default .Release.Namespace (get $describedObject "name") }} + metricName: {{ .Values.autoscaling.custom.metricName }} + targetValue: {{ .Values.autoscaling.custom.targetValue }} + {{- end }} + {{- else if eq $customType "External" }} + - type: External + external: + {{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }} + metric: + name: {{ .Values.autoscaling.custom.metricName }} + target: + type: Value + value: {{ .Values.autoscaling.custom.targetValue }} + {{- else }} + metricName: {{ .Values.autoscaling.custom.metricName }} + targetValue: {{ .Values.autoscaling.custom.targetValue }} + {{- end }} + {{- else }} - type: Pods pods: {{- if semverCompare ">=1.23-0" .Capabilities.KubeVersion.GitVersion }} @@ -55,4 +92,5 @@ spec: targetAverageValue: {{ .Values.autoscaling.custom.targetAverageValue }} {{- end }} {{- end }} + {{- end }} {{- end }} diff --git a/livekit-server/templates/deployment.yaml b/livekit-server/templates/deployment.yaml index 7b35cee..8b0e390 100644 --- a/livekit-server/templates/deployment.yaml +++ b/livekit-server/templates/deployment.yaml @@ -28,6 +28,9 @@ spec: checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} labels: {{- include "livekit-server.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: diff --git a/livekit-server/values.yaml b/livekit-server/values.yaml index bcf6d51..195b65e 100644 --- a/livekit-server/values.yaml +++ b/livekit-server/values.yaml @@ -110,6 +110,11 @@ podAnnotations: sidecar.istio.io/inject: "false" linkerd.io/inject: disabled +podLabels: + {} + # environment: production + # tier: frontend + podSecurityContext: {} # fsGroup: 2000