fix: deploy Storybook from immutable source archive
This commit is contained in:
1 parent
4d597a1650
commit
9118c2c602
4 files changed
+40
-14
No files matched your search
@@ -14,18 +14,26 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out workflow commit
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare SSH credentials
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_KNOWN_HOSTS: ${{ vars.DEPLOY_KNOWN_HOSTS }}
|
||||
run: |
|
||||
test -n "$DEPLOY_SSH_KEY"
|
||||
test -n "$DEPLOY_KNOWN_HOSTS"
|
||||
install -d -m 700 "$HOME/.ssh"
|
||||
printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/deploy_key"
|
||||
chmod 600 "$HOME/.ssh/deploy_key"
|
||||
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$HOME/.ssh/deploy_known_hosts"
|
||||
chmod 600 "$HOME/.ssh/deploy_known_hosts"
|
||||
|
||||
- name: Update checkout and deploy on host
|
||||
- name: Package source checkout
|
||||
run: git archive --format=tar.gz --output="$RUNNER_TEMP/hmdesign-storybook-$GITHUB_SHA.tar.gz" "$GITHUB_SHA"
|
||||
|
||||
- name: Transfer source and deploy on host
|
||||
env:
|
||||
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
|
||||
@@ -37,19 +45,34 @@ jobs:
|
||||
test -n "$DEPLOY_PATH"
|
||||
test -n "$DEPLOY_PORT"
|
||||
DEPLOY_PATH_B64="$(printf '%s' "$DEPLOY_PATH" | base64 | tr -d '\n')"
|
||||
ARCHIVE="$RUNNER_TEMP/hmdesign-storybook-$GITHUB_SHA.tar.gz"
|
||||
REMOTE_ARCHIVE="/tmp/hmdesign-storybook-$GITHUB_SHA.tar.gz"
|
||||
ssh_options=(
|
||||
-i "$HOME/.ssh/deploy_key"
|
||||
-p "$DEPLOY_PORT"
|
||||
-o BatchMode=yes
|
||||
-o StrictHostKeyChecking=yes
|
||||
-o UserKnownHostsFile="$HOME/.ssh/deploy_known_hosts"
|
||||
)
|
||||
scp_options=(
|
||||
-i "$HOME/.ssh/deploy_key"
|
||||
-P "$DEPLOY_PORT"
|
||||
-o BatchMode=yes
|
||||
-o StrictHostKeyChecking=yes
|
||||
-o UserKnownHostsFile="$HOME/.ssh/deploy_known_hosts"
|
||||
)
|
||||
scp "${scp_options[@]}" "$ARCHIVE" "$DEPLOY_USER@$DEPLOY_HOST:$REMOTE_ARCHIVE"
|
||||
ssh \
|
||||
-i "$HOME/.ssh/deploy_key" \
|
||||
-p "$DEPLOY_PORT" \
|
||||
-o BatchMode=yes \
|
||||
-o StrictHostKeyChecking=yes \
|
||||
-o UserKnownHostsFile="$HOME/.ssh/deploy_known_hosts" \
|
||||
"${ssh_options[@]}" \
|
||||
"$DEPLOY_USER@$DEPLOY_HOST" \
|
||||
"DEPLOY_PATH_B64=$DEPLOY_PATH_B64 bash -se" <<'REMOTE'
|
||||
"DEPLOY_PATH_B64=$DEPLOY_PATH_B64 RELEASE_SHA=$GITHUB_SHA bash -se" <<'REMOTE'
|
||||
set -euo pipefail
|
||||
DEPLOY_PATH="$(printf '%s' "$DEPLOY_PATH_B64" | base64 -d)"
|
||||
cd "$DEPLOY_PATH"
|
||||
git fetch origin main
|
||||
git checkout main
|
||||
git pull --ff-only origin main
|
||||
docker compose down && STORYBOOK_PORT=6024 docker compose up -d --build
|
||||
RELEASE_DIR="$DEPLOY_PATH/.storybook-deploy/releases/$RELEASE_SHA"
|
||||
mkdir -p "$RELEASE_DIR"
|
||||
tar -xzf "/tmp/hmdesign-storybook-$RELEASE_SHA.tar.gz" -C "$RELEASE_DIR"
|
||||
rm -f "/tmp/hmdesign-storybook-$RELEASE_SHA.tar.gz"
|
||||
cd "$RELEASE_DIR"
|
||||
STORYBOOK_PORT=6024 docker compose build
|
||||
STORYBOOK_PORT=6024 docker compose up -d --no-build --remove-orphans
|
||||
REMOTE
|
||||
Reference in new issue
Block a user