Use the product and image name for the chart, release, namespace, secrets, container and rendered file paths. The application package and local config paths keep their existing names. Bump the chart to 0.1.2 so the new chart name and paths are a distinct release. CI now publishes oci://gitea.tap-tap.win/taptap/charts/audiomanager.
99 lines
3.3 KiB
Bash
Executable File
99 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Builds and pushes the application image from the local machine, and can
|
|
# optionally deploy the Helm chart to the current kube context.
|
|
#
|
|
# CI also builds and pushes the image (see .gitea/workflows/ci.yaml). This
|
|
# script is the local alternative, mainly for releases that also deploy with
|
|
# --deploy.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
IMAGE="${IMAGE:-gitea.tap-tap.win/taptap/audiomanager}"
|
|
NAMESPACE="${NAMESPACE:-audiomanager}"
|
|
RELEASE="${RELEASE:-audiomanager}"
|
|
USERS_SECRET="${USERS_SECRET:-audiomanager-users}"
|
|
USERS_FILE="${USERS_FILE:-$ROOT/config/users.yaml}"
|
|
PULL_SECRET="${PULL_SECRET:-audiomanager-registry}"
|
|
DOCKER_CONFIG_FILE="${DOCKER_CONFIG_FILE:-$HOME/.docker/config.json}"
|
|
|
|
TAG=""
|
|
DEPLOY=0
|
|
PUSH=1
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: scripts/release.sh [options]
|
|
|
|
Options:
|
|
--tag TAG Image tag (default: git short SHA)
|
|
--deploy Run helm upgrade --install after pushing
|
|
--no-push Build only, do not push
|
|
-h, --help Show this help
|
|
|
|
Environment:
|
|
IMAGE Image repository (default: gitea.tap-tap.win/taptap/audiomanager)
|
|
NAMESPACE Kubernetes namespace (default: audiomanager)
|
|
RELEASE Helm release name (default: audiomanager)
|
|
USERS_SECRET Secret holding users.yaml (default: audiomanager-users)
|
|
USERS_FILE Path to users.yaml for --deploy (default: config/users.yaml)
|
|
PULL_SECRET Image pull secret name (default: audiomanager-registry)
|
|
DOCKER_CONFIG_FILE Docker config used for the pull secret
|
|
(default: ~/.docker/config.json)
|
|
EOF
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--tag) TAG="${2:?--tag requires a value}"; shift 2 ;;
|
|
--deploy) DEPLOY=1; shift ;;
|
|
--no-push) PUSH=0; shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) echo "Unknown argument: $1" >&2; usage >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
TAG="${TAG:-$(git -C "$ROOT" rev-parse --short HEAD)}"
|
|
|
|
echo "Building $IMAGE:$TAG"
|
|
docker build -t "$IMAGE:$TAG" -t "$IMAGE:latest" "$ROOT"
|
|
|
|
if [[ $PUSH -eq 1 ]]; then
|
|
echo "Pushing $IMAGE:$TAG and $IMAGE:latest"
|
|
if ! docker push "$IMAGE:$TAG"; then
|
|
echo "Push failed. Run 'docker login gitea.tap-tap.win' and retry." >&2
|
|
exit 1
|
|
fi
|
|
docker push "$IMAGE:latest"
|
|
fi
|
|
|
|
if [[ $DEPLOY -eq 1 ]]; then
|
|
echo "Deploying $RELEASE to namespace $NAMESPACE with image tag $TAG"
|
|
|
|
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
if [[ -f "$USERS_FILE" ]]; then
|
|
kubectl -n "$NAMESPACE" create secret generic "$USERS_SECRET" \
|
|
--from-file=users.yaml="$USERS_FILE" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
else
|
|
echo "No users file at $USERS_FILE; assuming secret $USERS_SECRET already exists."
|
|
fi
|
|
|
|
helm_args=(--set image.tag="$TAG" --set users.existingSecret="$USERS_SECRET")
|
|
|
|
if [[ -f "$DOCKER_CONFIG_FILE" ]]; then
|
|
kubectl -n "$NAMESPACE" create secret generic "$PULL_SECRET" \
|
|
--type=kubernetes.io/dockerconfigjson \
|
|
--from-file=.dockerconfigjson="$DOCKER_CONFIG_FILE" \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
helm_args+=(--set "imagePullSecrets[0].name=$PULL_SECRET")
|
|
else
|
|
echo "No Docker config at $DOCKER_CONFIG_FILE; assuming an image pull secret is configured."
|
|
fi
|
|
|
|
helm upgrade --install "$RELEASE" "$ROOT/charts/audiomanager" \
|
|
--namespace "$NAMESPACE" \
|
|
"${helm_args[@]}"
|
|
fi
|