Merge pull request 'chore: add deploy script for dev/prod CI releases' (#191) from chore/deploy-script-apply into main
Some checks failed
Build Docker Image / build (push) Failing after 1m20s
Some checks failed
Build Docker Image / build (push) Failing after 1m20s
This commit is contained in:
commit
7cb998561e
90
scripts/deploy.sh
Executable file
90
scripts/deploy.sh
Executable file
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
# Deploy Paper Dynasty Database API
|
||||
# Usage: ./scripts/deploy.sh <dev|prod> [commit]
|
||||
#
|
||||
# Dev: Force-updates the "dev" git tag → CI builds :dev Docker image
|
||||
# Prod: Creates CalVer tag + force-updates "latest" and "production" git tags
|
||||
# → CI builds :<calver>, :latest, :production Docker images
|
||||
set -euo pipefail
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
REMOTE="origin"
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <dev|prod> [commit]"
|
||||
echo ""
|
||||
echo " dev [commit] Force-update 'dev' tag on HEAD or specified commit"
|
||||
echo " prod [commit] Create CalVer + 'latest' + 'production' tags on HEAD or specified commit"
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ $# -lt 1 ]] && usage
|
||||
|
||||
ENV="$1"
|
||||
COMMIT="${2:-HEAD}"
|
||||
|
||||
SHA=$(git rev-parse "$COMMIT" 2>/dev/null) || {
|
||||
echo -e "${RED}Invalid commit: $COMMIT${NC}"
|
||||
exit 1
|
||||
}
|
||||
SHA_SHORT="${SHA:0:7}"
|
||||
|
||||
git fetch --tags "$REMOTE"
|
||||
|
||||
if ! git branch -a --contains "$SHA" 2>/dev/null | grep -qE '(^|\s)(main|remotes/origin/main)$'; then
|
||||
echo -e "${RED}Commit $SHA_SHORT is not on main. Aborting.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$ENV" in
|
||||
dev)
|
||||
echo -e "${YELLOW}Deploying to dev...${NC}"
|
||||
echo -e " Commit: ${SHA_SHORT}"
|
||||
|
||||
git tag -f dev "$SHA"
|
||||
git push "$REMOTE" dev --force
|
||||
|
||||
echo -e "${GREEN}Tagged ${SHA_SHORT} as 'dev' and pushed. CI will build :dev image.${NC}"
|
||||
;;
|
||||
|
||||
prod)
|
||||
echo -e "${YELLOW}Deploying to prod...${NC}"
|
||||
|
||||
YEAR=$(date -u +%Y)
|
||||
MONTH=$(date -u +%-m)
|
||||
PREFIX="${YEAR}.${MONTH}."
|
||||
|
||||
LAST_BUILD=$(git tag -l "${PREFIX}*" | sed "s/^${PREFIX}//" | sort -n | tail -1)
|
||||
BUILD=$((${LAST_BUILD:-0} + 1))
|
||||
CALVER="${PREFIX}${BUILD}"
|
||||
|
||||
echo -e " Commit: ${SHA_SHORT}"
|
||||
echo -e " Version: ${CALVER}"
|
||||
echo -e " Tags: ${CALVER}, latest, production"
|
||||
|
||||
read -rp "Proceed? [y/N] " confirm
|
||||
[[ "$confirm" =~ ^[Yy]$ ]] || {
|
||||
echo "Aborted."
|
||||
exit 0
|
||||
}
|
||||
|
||||
git tag "$CALVER" "$SHA"
|
||||
git tag -f latest "$SHA"
|
||||
git tag -f production "$SHA"
|
||||
|
||||
git push "$REMOTE" "$CALVER"
|
||||
git push "$REMOTE" latest --force
|
||||
git push "$REMOTE" production --force
|
||||
|
||||
echo -e "${GREEN}Tagged ${SHA_SHORT} as '${CALVER}', 'latest', 'production' and pushed.${NC}"
|
||||
echo -e "${GREEN}CI will build :${CALVER}, :latest, :production images.${NC}"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
Loading…
Reference in New Issue
Block a user