code-server / entrypoint.sh
nao80's picture
Update entrypoint.sh
cb72d1d verified
Raw History Blame Contribute Delete
1.28 kB
#!/bin/bash
# OCI設定の最適化
OCI_ENDPOINT="https://${OCI_NAMESPACE}.compat.objectstorage.${AWS_DEFAULT_REGION}.oraclecloud.com"
S3_BUCKET_URL="s3://${S3_BUCKET_NAME}/code-server-full-backup"
SYNC_DIR="/home/user/app/sync"
# AWS CLIの挙動をOCIに最適化
aws configure set default.s3.signature_version s3v4
# マルチパートアップロードの閾値を大きくしてMissingContentLengthを回避
aws configure set default.s3.multipart_threshold 1024MB
mkdir -p $SYNC_DIR/workspace $SYNC_DIR/user-data $SYNC_DIR/extensions
# 1. 起動時に復元
echo "📥 Restoring environment from OCI..."
aws s3 sync $S3_BUCKET_URL $SYNC_DIR --endpoint-url $OCI_ENDPOINT || echo "No backup found."
# 2. 定期バックアップ(MissingContentLength対策を追加)
(
while true; do
sleep 30
echo "📤 Snapshotting environment to OCI..."
# --no-guess-mime-type をつけると安定する場合があります
aws s3 sync $SYNC_DIR $S3_BUCKET_URL --delete --endpoint-url $OCI_ENDPOINT --no-guess-mime-type
done
) &
# 3. code-serverの起動
code-server \
--bind-addr 0.0.0.0:7860 \
--auth password \
--user-data-dir $SYNC_DIR/user-data \
--extensions-dir $SYNC_DIR/extensions \
--disable-telemetry \
$SYNC_DIR/workspace