-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (105 loc) · 4.33 KB
/
deploy.yml
File metadata and controls
129 lines (105 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Deploy Docs to Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Set up Tailscale
run: |
set -x
curl -fsSL https://tailscale.com/install.sh | sh
if [ $? -ne 0 ]; then echo "Tailscale installation failed"; exit 1; fi
sudo tailscale up --authkey=${{ secrets.TAILSCALE_AUTH_KEY }} --hostname=github-actions-docs-runner
if [ $? -ne 0 ]; then echo "Tailscale up failed"; exit 1; fi
tailscale status
if [ $? -ne 0 ]; then echo "Tailscale status check failed"; exit 1; fi
shell: bash
- name: Set up SSH
run: |
set -x
mkdir -p ~/.ssh
if [ $? -ne 0 ]; then echo "Failed to create .ssh directory"; exit 1; fi
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
if [ $? -ne 0 ]; then echo "Failed to write SSH private key"; exit 1; fi
chmod 600 ~/.ssh/id_rsa
if [ $? -ne 0 ]; then echo "Failed to set permissions on SSH private key"; exit 1; fi
eval $(ssh-agent -s)
if [ $? -ne 0 ]; then echo "Failed to start ssh-agent"; exit 1; fi
ssh-add ~/.ssh/id_rsa
if [ $? -ne 0 ]; then echo "Failed to add SSH key to agent"; exit 1; fi
shell: bash
- name: Check DNS Resolution
run: nslookup ${{ secrets.DEPLOY_HOST }}
shell: bash
- name: Check Network Connectivity
run: ping -c 4 ${{ secrets.DEPLOY_HOST }}
shell: bash
- name: Add host to known_hosts
run: |
set -x
echo "Adding host to known_hosts..."
mkdir -p ~/.ssh
touch ~/.ssh/known_hosts
ssh-keyscan -v -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
if [ $? -ne 0 ]; then echo "Failed to add host to known_hosts"; exit 1; fi
shell: bash
- name: Test SSH Connection
run: |
set -x
echo "Testing SSH connection..."
ssh -vvv ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} whoami
if [ $? -ne 0 ]; then echo "SSH connection test failed"; exit 1; fi
shell: bash
- name: Sync docs files to remote host
run: |
set -x
echo "Syncing docs.basekick.net files to remote host..."
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "sudo mkdir -p ${{ secrets.DEPLOY_PATH }} && sudo chown ${{ secrets.DEPLOY_USER }}:${{ secrets.DEPLOY_USER }} ${{ secrets.DEPLOY_PATH }}"
rsync -avz --checksum --delete \
--exclude '.git' \
--exclude 'node_modules' \
--exclude '.github' \
--exclude '*.log' \
--exclude '.DS_Store' \
--stats \
./build/ ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}
if [ $? -ne 0 ]; then echo "File sync failed"; exit 1; fi
shell: bash
- name: Copy docker-compose.yml and nginx.conf to server
run: |
set -x
echo "Copying docker-compose.yml and nginx.conf to server..."
scp docker-compose.yml ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/
if [ $? -ne 0 ]; then echo "Failed to copy docker-compose.yml"; exit 1; fi
scp nginx.conf ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/
if [ $? -ne 0 ]; then echo "Failed to copy nginx.conf"; exit 1; fi
shell: bash
- name: Deploy docs with Docker Compose
run: |
set -x
echo "Deploying docs.basekick.net (Docusaurus static site)..."
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << EOF
cd ${{ secrets.DEPLOY_PATH }}
# Restart docs container
sudo docker compose up -d docs
# Touch deployment timestamp
touch .last-deploy
# Show container status
sudo docker ps | grep docs
EOF
if [ $? -ne 0 ]; then echo "Deployment failed"; exit 1; fi
shell: bash