ci: self-hosted runner 직접 실행 (SSH 불필요) + root 모드 sudo 자동 스킵
Deploy / deploy (push) Failing after 0s

This commit is contained in:
chpark
2026-04-23 01:20:50 +09:00
parent d05685935d
commit 49639252bf
2 changed files with 43 additions and 28 deletions
+27 -22
View File
@@ -1,4 +1,4 @@
name: Deploy via SSH name: Deploy
on: on:
push: push:
@@ -6,25 +6,30 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
remote-deploy: deploy:
runs-on: ubuntu-latest runs-on: self-hosted
steps: steps:
- name: Trigger remote deploy on server - name: Sync repo
uses: appleboy/ssh-action@v1.0.3 run: |
with: cd /home/chpark
host: ${{ secrets.SSH_HOST }} if [ ! -d insurance/.git ]; then
port: ${{ secrets.SSH_PORT || 22 }} git clone https://git.junggomoa.com/chpark/insurance.git
username: ${{ secrets.SSH_USER }} fi
password: ${{ secrets.SSH_PASSWORD }} cd insurance
command_timeout: 20m git fetch origin
script: | git reset --hard "origin/${GITHUB_REF##*/}"
set -e
cd /home/chpark - name: Deploy to k3s
if [ ! -d insurance/.git ]; then run: |
git clone https://git.junggomoa.com/chpark/insurance.git cd /home/chpark/insurance
fi chmod +x scripts/deploy-remote.sh
cd insurance bash scripts/deploy-remote.sh
git fetch origin
git reset --hard origin/master - name: Show status
chmod +x scripts/deploy-remote.sh if: always()
bash scripts/deploy-remote.sh run: |
export KUBECONFIG=/home/chpark/.kube/config
kubectl -n insurance get pods,svc 2>&1 || true
echo ""
echo "🚀 Web: https://insurance.junggomoa.com"
echo "🔌 API: https://api.insurance.junggomoa.com"
+16 -6
View File
@@ -1,11 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
export KUBECONFIG=/home/chpark/.kube/config export KUBECONFIG="${KUBECONFIG:-/home/chpark/.kube/config}"
SUDO_PASS="${SUDO_PASS:-qlalfqjsgh11}"
sudo_run() { # root 실행 시엔 sudo 생략, 일반 유저면 비번으로 sudo
echo "$SUDO_PASS" | sudo -S bash -c "$1" if [ "$(id -u)" -eq 0 ]; then
} sudo_run() { bash -c "$1"; }
else
SUDO_PASS="${SUDO_PASS:-qlalfqjsgh11}"
sudo_run() { echo "$SUDO_PASS" | sudo -S bash -c "$1"; }
fi
# CI(root) 환경에서 kubeconfig 없으면 k3s 것으로 대체
if [ ! -r "$KUBECONFIG" ]; then
if [ -r /etc/rancher/k3s/k3s.yaml ]; then
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
fi
fi
cd /home/chpark cd /home/chpark
if [ -d insurance/.git ]; then if [ -d insurance/.git ]; then
@@ -37,7 +47,7 @@ echo "[*] Applying Kubernetes manifests"
kubectl apply -f deploy/k8s/namespace.yaml kubectl apply -f deploy/k8s/namespace.yaml
SECRETS_FILE=/home/chpark/.insurance-secrets SECRETS_FILE=/home/chpark/.insurance-secrets
if [ -f "$SECRETS_FILE" ]; then if [ -r "$SECRETS_FILE" ]; then
set -a; source "$SECRETS_FILE"; set +a set -a; source "$SECRETS_FILE"; set +a
fi fi
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-$(openssl rand -hex 24)}" POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-$(openssl rand -hex 24)}"