2025-12-07 19:50:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
ENVIRONMENT=$1
|
|
|
|
|
|
|
|
|
|
if [ -z "$ENVIRONMENT" ]; then
|
|
|
|
|
echo "Usage: $0 <staging|production>"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-07 21:37:46 +00:00
|
|
|
# Define cleanup function to revert changes to applications.yaml
|
|
|
|
|
cleanup() {
|
|
|
|
|
if [ -f k8s/argocd/base/applications.yaml.bak ]; then
|
|
|
|
|
echo "Reverting k8s/argocd/base/applications.yaml..."
|
|
|
|
|
mv k8s/argocd/base/applications.yaml.bak k8s/argocd/base/applications.yaml
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
2025-12-07 19:50:51 +00:00
|
|
|
if [ "$ENVIRONMENT" == "staging" ]; then
|
|
|
|
|
echo "Deploying to STAGING..."
|
|
|
|
|
|
|
|
|
|
# Source activation script
|
2025-12-07 21:37:46 +00:00
|
|
|
if [ -f ~/bin/activate-stg ]; then
|
|
|
|
|
source ~/bin/activate-stg
|
2025-12-07 19:50:51 +00:00
|
|
|
else
|
2025-12-07 21:37:46 +00:00
|
|
|
echo "Error: ~/bin/activate-stg not found."
|
2025-12-07 19:50:51 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Set BITBUCKET_BRANCH
|
|
|
|
|
export BITBUCKET_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
|
if [ -z "$BITBUCKET_BRANCH" ]; then
|
|
|
|
|
export BITBUCKET_BRANCH="develop"
|
|
|
|
|
fi
|
|
|
|
|
echo "Using branch: $BITBUCKET_BRANCH"
|
|
|
|
|
|
2025-12-07 21:37:46 +00:00
|
|
|
# Template argocd/base/applications.yaml
|
2025-12-07 19:50:51 +00:00
|
|
|
# Template argocd/base/applications.yaml
|
|
|
|
|
echo "Templating k8s/argocd/base/applications.yaml..."
|
2025-12-07 21:37:46 +00:00
|
|
|
|
|
|
|
|
# Backup original file
|
|
|
|
|
cp k8s/argocd/base/applications.yaml k8s/argocd/base/applications.yaml.bak
|
|
|
|
|
|
|
|
|
|
# Perform substitution
|
|
|
|
|
envsubst < k8s/argocd/base/applications.yaml.bak > k8s/argocd/base/applications.yaml
|
2025-12-07 19:50:51 +00:00
|
|
|
|
|
|
|
|
# Apply Kustomize
|
|
|
|
|
echo "Applying Kustomize for staging..."
|
|
|
|
|
kubectl -n argocd apply -k k8s/argocd/overlays/staging
|
|
|
|
|
|
|
|
|
|
# Rollout restarts
|
|
|
|
|
echo "Restarting coturn deployments..."
|
|
|
|
|
kubectl -n coturn rollout restart deployment/coturn
|
|
|
|
|
kubectl -n coturn rollout status -w deployment/coturn
|
|
|
|
|
kubectl -n coturn-dns rollout restart deployment/coturn-dns
|
|
|
|
|
kubectl -n coturn-dns rollout status -w deployment/coturn-dns
|
|
|
|
|
|
|
|
|
|
elif [ "$ENVIRONMENT" == "production" ]; then
|
|
|
|
|
echo "Deploying to PRODUCTION..."
|
|
|
|
|
|
|
|
|
|
# Source activation script
|
2025-12-07 21:37:46 +00:00
|
|
|
if [ -f ~/bin/activate-prd ]; then
|
|
|
|
|
source ~/bin/activate-prd
|
2025-12-07 19:50:51 +00:00
|
|
|
else
|
2025-12-07 21:37:46 +00:00
|
|
|
echo "Error: ~/bin/activate-prd not found."
|
2025-12-07 19:50:51 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Apply Kustomize
|
|
|
|
|
echo "Applying Kustomize for production..."
|
|
|
|
|
kubectl -n argocd apply -k k8s/argocd/overlays/production
|
|
|
|
|
|
|
|
|
|
# Rollout restarts
|
|
|
|
|
echo "Restarting coturn deployments..."
|
|
|
|
|
kubectl -n coturn rollout restart deployment/coturn
|
|
|
|
|
kubectl -n coturn rollout status -w deployment/coturn
|
|
|
|
|
kubectl -n coturn-dns rollout restart deployment/coturn-dns
|
|
|
|
|
kubectl -n coturn-dns rollout status -w deployment/coturn-dns
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
echo "Invalid environment: $ENVIRONMENT. Must be 'staging' or 'production'."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Deployment complete!"
|