79 lines
2.8 KiB
YAML
79 lines
2.8 KiB
YAML
name: Deploy Storybook
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: storybook-deployment
|
|
cancel-in-progress: false
|
|
|
|
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: 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 }}
|
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
|
|
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
|
|
run: |
|
|
test -n "$DEPLOY_HOST"
|
|
test -n "$DEPLOY_USER"
|
|
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 \
|
|
"${ssh_options[@]}" \
|
|
"$DEPLOY_USER@$DEPLOY_HOST" \
|
|
"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)"
|
|
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
|