11name : build and deploy
2-
32on :
43 push :
54 branches : ['dev']
6-
75jobs :
86 build :
97 runs-on : ubuntu-latest
10-
118 steps :
129 - name : Checkout (with submodules)
1310 uses : actions/checkout@v4
1411 with :
1512 submodules : true
1613 token : ${{ secrets.PAT_TOKEN }}
1714 fetch-depth : 0
18-
15+
1916 - name : Set up Node.js
2017 uses : actions/setup-node@v4
2118 with :
2219 node-version : ' 22'
23-
20+
2421 - name : Install dependencies
2522 run : npm ci
26-
23+
2724 - name : Build (Vite)
2825 run : npm run build
29-
26+
3027 - name : Add 404.html (SPA fallback)
3128 run : |
3229 cd dist
3330 cp index.html 404.html
34-
31+
3532 - name : Setup SSH configuration (bastion → target)
3633 run : |
3734 set -e
3835 eval "$(ssh-agent -s)"
3936 mkdir -p ~/.ssh && chmod 700 ~/.ssh
40-
41- # keys
37+
38+ # SSH 키 설정
4239 echo "${{ secrets.BASTION_KEY }}" > ~/.ssh/bastion.pem
4340 echo "${{ secrets.SERVER_KEY }}" > ~/.ssh/target.pem
4441 chmod 600 ~/.ssh/bastion.pem ~/.ssh/target.pem
4542 ssh-add ~/.ssh/bastion.pem
4643 ssh-add ~/.ssh/target.pem
47-
48- # known_hosts
49- ssh-keyscan -H ${{ secrets.BASTION_HOST }} >> ~/.ssh/known_hosts
50- ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
51- chmod 644 ~/.ssh/known_hosts
52-
53- # ssh config (ProxyJump)
44+
45+ # known_hosts 설정
46+ ssh-keyscan -H -t rsa,ed25519 ${{ secrets.BASTION_HOST }} >> ~/.ssh/known_hosts || {
47+ ssh-keyscan -t rsa ${{ secrets.BASTION_HOST }} >> ~/.ssh/known_hosts || {
48+ echo "Warning: Could not add bastion to known_hosts"
49+ }
50+ }
51+
52+ # SSH 설정 파일 생성
5453 cat > ~/.ssh/config << 'EOF'
5554 Host bastion
5655 HostName ${{ secrets.BASTION_HOST }}
5756 User ${{ secrets.BASTION_USER }}
5857 IdentityFile ~/.ssh/bastion.pem
5958 ServerAliveInterval 60
6059 ServerAliveCountMax 3
61-
60+ StrictHostKeyChecking no
61+ UserKnownHostsFile /dev/null
62+
6263 Host target
6364 HostName ${{ secrets.SERVER_HOST }}
6465 User ${{ secrets.SERVER_USERNAME }}
@@ -70,22 +71,30 @@ jobs:
7071 UserKnownHostsFile /dev/null
7172 EOF
7273 chmod 600 ~/.ssh/config
73-
74+
75+ echo "SSH configuration completed"
76+
7477 - name : Test SSH connections
75- run : |
76- ssh -F ~/.ssh/config bastion "echo 'bastion ok '"
77- ssh -F ~/.ssh/config target "echo 'target ok '"
78+ run :
79+ ssh -F ~/.ssh/config -o ConnectTimeout=10 bastion "echo 'bastion connection successful '"
80+ ssh -F ~/.ssh/config -o ConnectTimeout=15 target "echo 'target connection successful '"
7881
7982 - name : Upload dist via bastion & reload nginx
8083 run : |
8184 set -e
85+ echo "Preparing target directory..."
8286 ssh -F ~/.ssh/config target "
8387 mkdir -p ~/cra_web/dist &&
8488 rm -rf ~/cra_web/dist/*
8589 "
90+
91+ echo "Uploading files..."
8692 scp -F ~/.ssh/config -r ./dist/* target:~/cra_web/dist/
87-
93+
94+ echo "Testing and reloading nginx..."
8895 ssh -F ~/.ssh/config target "
8996 sudo nginx -t &&
9097 sudo systemctl reload nginx
9198 "
99+
100+ echo "Deployment completed successfully"
0 commit comments