@@ -1,14 +1,14 @@
|
|||||||
# Push to main → rsync this repo into arkieproject/backend on ark-library-backend-1, rebuild api.
|
# Push to main → scp backend sources to ark-library-backend-1, rebuild api.
|
||||||
#
|
#
|
||||||
# Gitea repo secrets (Settings → Actions → Secrets):
|
# Gitea repo secrets (Settings → Actions → Secrets):
|
||||||
# DEPLOY_SSH_KEY — PEM private key for ec2-user@ark-library-backend-1 (no passphrase)
|
# DEPLOY_SSH_KEY — PEM private key for ec2-user@ark-library-backend-1 (no passphrase)
|
||||||
#
|
#
|
||||||
# Optional secrets (override defaults):
|
# Optional secrets (override defaults):
|
||||||
# DEPLOY_HOST — SSH host (default ark-library-backend-1; use IP/hostname if the runner has no ~/.ssh/config alias)
|
# DEPLOY_HOST — SSH host (default ark-library-backend-1)
|
||||||
# DEPLOY_USER — default ec2-user
|
# DEPLOY_USER — default ec2-user
|
||||||
# REMOTE_REPO — default /home/ec2-user/arkieproject
|
# REMOTE_REPO — default /home/ec2-user/arkieproject
|
||||||
#
|
#
|
||||||
# Runner must reach the host (Tailscale, VPC, or public IP). Add the matching public key to authorized_keys on the server.
|
# Runner must reach the host. Server needs ${REMOTE_REPO}/.env and deploy/ (bootstrap via deploy/sync-admin.sh).
|
||||||
|
|
||||||
name: Deploy API
|
name: Deploy API
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ jobs:
|
|||||||
echo "DEPLOY_HOST=${DEPLOY_HOST:-ark-library-backend-1}" >> "$GITHUB_ENV"
|
echo "DEPLOY_HOST=${DEPLOY_HOST:-ark-library-backend-1}" >> "$GITHUB_ENV"
|
||||||
echo "DEPLOY_USER=${DEPLOY_USER:-ec2-user}" >> "$GITHUB_ENV"
|
echo "DEPLOY_USER=${DEPLOY_USER:-ec2-user}" >> "$GITHUB_ENV"
|
||||||
echo "REMOTE_REPO=${REMOTE_REPO:-/home/ec2-user/arkieproject}" >> "$GITHUB_ENV"
|
echo "REMOTE_REPO=${REMOTE_REPO:-/home/ec2-user/arkieproject}" >> "$GITHUB_ENV"
|
||||||
|
echo "REMOTE_BACKEND=${REMOTE_REPO:-/home/ec2-user/arkieproject}/backend" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Configure SSH
|
- name: Configure SSH
|
||||||
env:
|
env:
|
||||||
@@ -47,23 +48,42 @@ jobs:
|
|||||||
printf '%s\n' "${DEPLOY_SSH_KEY}" > ~/.ssh/deploy_key
|
printf '%s\n' "${DEPLOY_SSH_KEY}" > ~/.ssh/deploy_key
|
||||||
chmod 600 ~/.ssh/deploy_key
|
chmod 600 ~/.ssh/deploy_key
|
||||||
ssh-keyscan -H "${DEPLOY_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
ssh-keyscan -H "${DEPLOY_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
|
cat >> ~/.ssh/config <<EOF
|
||||||
|
Host deploy-target
|
||||||
|
HostName ${DEPLOY_HOST}
|
||||||
|
User ${DEPLOY_USER}
|
||||||
|
IdentityFile ~/.ssh/deploy_key
|
||||||
|
StrictHostKeyChecking accept-new
|
||||||
|
ConnectTimeout 30
|
||||||
|
EOF
|
||||||
|
chmod 600 ~/.ssh/config
|
||||||
|
|
||||||
- name: Rsync backend sources
|
- name: Package backend sources
|
||||||
run: |
|
run: |
|
||||||
REMOTE_BACKEND="${REMOTE_REPO}/backend/"
|
tar czf /tmp/backend-deploy.tar.gz \
|
||||||
rsync -avz --delete \
|
--exclude='./.git' \
|
||||||
--exclude '.git' \
|
--exclude='./uploads' \
|
||||||
--exclude 'uploads' \
|
--exclude='./.env' \
|
||||||
--exclude '.env' \
|
--exclude='./.env.*' \
|
||||||
--exclude '.env.*' \
|
--exclude='./.DS_Store' \
|
||||||
--exclude '.DS_Store' \
|
--exclude='./.gitea' \
|
||||||
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new -o ConnectTimeout=30" \
|
-C . .
|
||||||
./ "${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_BACKEND}"
|
|
||||||
|
- name: Deploy backend sources (scp)
|
||||||
|
run: |
|
||||||
|
scp /tmp/backend-deploy.tar.gz deploy-target:/tmp/backend-deploy.tar.gz
|
||||||
|
ssh deploy-target bash -s <<REMOTE
|
||||||
|
set -euo pipefail
|
||||||
|
REMOTE_BACKEND="${REMOTE_BACKEND}"
|
||||||
|
mkdir -p "\${REMOTE_BACKEND}"
|
||||||
|
find "\${REMOTE_BACKEND}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
|
||||||
|
tar xzf /tmp/backend-deploy.tar.gz -C "\${REMOTE_BACKEND}"
|
||||||
|
rm -f /tmp/backend-deploy.tar.gz
|
||||||
|
REMOTE
|
||||||
|
|
||||||
- name: Rebuild and restart API container
|
- name: Rebuild and restart API container
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new -o ConnectTimeout=30 \
|
ssh deploy-target bash -s <<REMOTE
|
||||||
"${DEPLOY_USER}@${DEPLOY_HOST}" bash -s <<REMOTE
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cd "${REMOTE_REPO}"
|
cd "${REMOTE_REPO}"
|
||||||
if [[ ! -f .env ]]; then
|
if [[ ! -f .env ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user