Skip to content

Commit cc3caa0

Browse files
committed
updates ..
1 parent 555cc22 commit cc3caa0

File tree

1 file changed

+93
-29
lines changed

1 file changed

+93
-29
lines changed

scripts/deploy_cloud_app.sh

Lines changed: 93 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,114 @@
11
#!/bin/bash
22
set -e
33

4-
# Get current branch name
5-
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
4+
SCRIPT_PATH=$(realpath "$(dirname $(realpath "${BASH_SOURCE[0]}"))")
5+
source ${SCRIPT_PATH}/build_utils.sh
6+
7+
function show_help() {
8+
echo "Usage: $0 [options]"
9+
echo "Options:"
10+
echo " -b, --branch <branch> Checkout branch"
11+
echo " --set-as-default Set as default"
12+
echo " --skip-confirmation Skip confirmation"
13+
echo " --help Show help"
14+
}
15+
16+
# Parse command line arguments
17+
CHECKOUT_BRANCH=
18+
SET_AS_DEFAULT=false
19+
SKIP_CONFIRMATION=false
20+
while [[ $# -gt 0 ]]; do
21+
case $1 in
22+
-b|--branch)
23+
CHECKOUT_BRANCH="$2"
24+
shift 2
25+
;;
26+
--set-as-default)
27+
SET_AS_DEFAULT=true
28+
shift
29+
;;
30+
--skip-confirmation)
31+
SKIP_CONFIRMATION=true
32+
shift
33+
;;
34+
--help)
35+
show_help
36+
exit 0
37+
;;
38+
*)
39+
echo "Unknown option: $1"
40+
show_help
41+
exit 1
42+
;;
43+
esac
44+
done
45+
646

47+
# Checkout current branch in a new temporary directory
48+
# only popd when exiting the script
49+
TMP_DIR=$(mktemp -d)
50+
trap 'popd > /dev/null && rm -rf ${TMP_DIR}' EXIT
51+
msg_info "Copying repository to a new temporary directory ${TMP_DIR} ..."
52+
git fetch origin ${CHECKOUT_BRANCH}:${CHECKOUT_BRANCH}
53+
git clone . ${TMP_DIR}
54+
cp ${SCRIPT_PATH}/versioned.patch ${TMP_DIR}
55+
msg_info "Checking out branch ${CHECKOUT_BRANCH} ..."
56+
pushd ${TMP_DIR} > /dev/null
57+
git checkout ${CHECKOUT_BRANCH}
58+
59+
60+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
761
# Verify branch name matches release/x.x.x or release/x.x.x-dev...
8-
if [[ ! $CURRENT_BRANCH =~ ^release/[0-9]+\.[0-9]+\.[0-9]+(-dev[0-9]+)?$ ]]; then
9-
echo "✗ Error: Current branch '$CURRENT_BRANCH' does not match required pattern"
10-
echo " Expected: release/x.x.x OR release/x.x.x-dev20241104123632"
62+
if [[ ! $CURRENT_BRANCH =~ ^(release|release-cloud-app)/[0-9]+\.[0-9]+\.[0-9]+(-dev[0-9]+)?$ ]]; then
63+
msg_err "Current branch '$CURRENT_BRANCH' does not match required pattern"
64+
msg_err "Expected: release/x.x.x OR release/x.x.x-dev20241104123632"
1165
exit 1
1266
fi
1367

14-
# Extract version from branch name (remove "release/" prefix)
68+
GIT_COMMIT=$(git rev-parse HEAD)
69+
BUILD_TIMESTAMP=$(date -u +%FT%T%z)
1570
VERSION=${CURRENT_BRANCH#release/}
16-
17-
echo "Current branch: $CURRENT_BRANCH"
18-
echo "Version: $VERSION"
19-
echo ""
71+
VERSION=${VERSION#release-cloud-app/}
72+
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-dev[0-9]+)?$ ]]; then
73+
msg_err "Version '$VERSION' does not match required pattern"
74+
msg_err "Expected: x.x.x OR x.x.x-dev20241104123632"
75+
exit 1
76+
fi
2077

2178
# Change to ui directory
2279
cd ui
2380

24-
# Ask for confirmation
25-
read -p "Do you want to deploy the cloud app to production? (y/N): " -n 1 -r
26-
echo ""
27-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
28-
echo "Deployment cancelled."
29-
exit 0
81+
if [ "$SET_AS_DEFAULT" = true ]; then
82+
# Build for root dist
83+
msg_info "Building for root dist..."
84+
npm ci
85+
npm run build:prod
3086
fi
3187

32-
# Build for root dist
33-
echo ""
34-
echo "Building for root dist..."
35-
npm ci
36-
npm run build:prod
37-
3888
# Build for versioned dist/v/VERSION
39-
echo ""
40-
echo "Building for dist/v/${VERSION}..."
89+
msg_info "Building for dist/v/${VERSION}..."
4190
npm ci
4291
npm run build:prod -- --base=/v/${VERSION}/ --outDir dist/v/${VERSION}
4392

44-
# Deploy to production
93+
# Ask for confirmation
94+
if [ "$SKIP_CONFIRMATION" = false ]; then
95+
read -p "Do you want to deploy the cloud app to production? (y/N): " -n 1 -r
4596
echo ""
46-
echo "Deploying to r2://jetkvm-cloud-app..."
47-
rclone copyto dist r2://jetkvm-cloud-app
97+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
98+
msg_err "Deployment cancelled."
99+
exit 0
100+
fi
101+
fi
48102

49-
echo ""
50-
echo "✓ Successfully deployed v${VERSION} to production"
103+
# Deploy to production
104+
msg_info "Deploying to r2://jetkvm-cloud-app..."
105+
rclone copyto \
106+
--progress \
107+
--stats=1s \
108+
--header-upload="x-amz-meta-jetkvm-version: ${VERSION}" \
109+
--header-upload="x-amz-meta-jetkvm-build-ref: ${GIT_COMMIT}" \
110+
--header-upload="x-amz-meta-jetkvm-build-timestamp: ${BUILD_TIMESTAMP}" \
111+
dist \
112+
r2://jetkvm-cloud-app
113+
114+
msg_ok "Successfully deployed v${VERSION} to production"

0 commit comments

Comments
 (0)