@@ -12,65 +12,68 @@ jobs:
1212 steps :
1313 - name : Checkout code
1414 uses : actions/checkout@v3
15+
16+ # Cache SSH configuration
17+ - name : Cache SSH configuration
18+ uses : actions/cache@v3
19+ id : ssh-cache
20+ with :
21+ path : ~/.ssh
22+ key : ssh-config-${{ runner.os }}-v1
1523
1624 - name : Set up SSH
1725 uses :
webfactory/[email protected] 1826 with :
1927 ssh-private-key : ${{ secrets.SSH_PRIVATE_KEY }}
2028
2129 - name : Add server to known hosts
30+ if : steps.ssh-cache.outputs.cache-hit != 'true'
2231 run : |
2332 mkdir -p ~/.ssh
2433
2534 # Create SSH config file with custom port and user
26- echo "Creating SSH config file..."
2735 cat > ~/.ssh/config << EOF
2836 Host profullstack.com 104.36.23.197
2937 HostName 104.36.23.197
3038 User ubuntu
3139 Port 2048
40+ ControlMaster auto
41+ ControlPath ~/.ssh/control-%C
42+ ControlPersist 30s
3243 EOF
3344 chmod 600 ~/.ssh/config
3445
3546 # Run ssh-keyscan with the correct port
36- echo "Running ssh-keyscan with custom port..."
37- # The -p flag is for the port, -T disables pseudo-terminal allocation
3847 ssh-keyscan -p 2048 -T 60 104.36.23.197 > /tmp/known_hosts_entry
3948
4049 # Check if ssh-keyscan succeeded
4150 if [ -s /tmp/known_hosts_entry ]; then
42- echo "Successfully retrieved host key:"
43- cat /tmp/known_hosts_entry
44-
45- # Add the host key to known_hosts
4651 cat /tmp/known_hosts_entry >> ~/.ssh/known_hosts
4752 chmod 644 ~/.ssh/known_hosts
4853 else
49- echo "Failed to retrieve host key via ssh-keyscan, using provided key..."
5054 echo "${{ secrets.SERVER_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
5155 chmod 644 ~/.ssh/known_hosts
5256 fi
53-
54- # Verify the files exist and have content
55- ls -la ~/.ssh/
56- echo "Content of SSH config:"
57- cat ~/.ssh/config
58- echo "Lines in known_hosts:"
59- wc -l ~/.ssh/known_hosts
57+
58+ # Cache apt packages
59+ - name : Cache apt packages
60+ uses : actions/cache@v3
61+ id : apt-cache
62+ with :
63+ path : /var/cache/apt/archives
64+ key : apt-packages-${{ runner.os }}-${{ hashFiles('.github/workflows/deploy.yml') }}
6065
6166 - name : Install dependencies
6267 run : |
63- sudo apt-get update
64- sudo apt-get install -y rsync zsh curl file golang postgresql-client gnome-keyring dbus-x11
68+ sudo apt-get update -qq
69+ sudo apt-get install -y --no-install-recommends rsync zsh curl file golang postgresql-client gnome-keyring dbus-x11
6570
6671 # Set up dbus for gnome-keyring
67- echo "Setting up dbus and gnome-keyring..."
6872 mkdir -p ~/.cache
6973 dbus-launch --sh-syntax > ~/.cache/dbus-env
7074 source ~/.cache/dbus-env
7175
7276 # Initialize the keyring
73- echo "Initializing gnome-keyring..."
7477 echo -n "password" | gnome-keyring-daemon --unlock
7578
7679 # Export environment variables for subsequent steps
8083 run : |
8184 # Create .env file from GitHub secret
8285 echo "${{ secrets.ENV_FILE_CONTENT }}" > .env
83-
84- # Print confirmation (without showing the content for security)
8586 echo "Created .env file with $(grep -c '' .env) lines"
8687
8788 - name : Prepare for deployment
@@ -90,28 +91,14 @@ jobs:
9091 chmod +x ./bin/supabase-db.sh
9192 chmod +x ./bin/deploy.sh
9293 chmod +x ./bin/deploy-with-migrations.sh
93-
94- # Debug: Check .env file existence
95- echo "Checking .env file..."
96- if [ -f .env ]; then
97- echo ".env file exists with $(grep -c '' .env) lines"
98- else
99- echo ".env file does not exist"
100- fi
10194
10295 - name : Deploy to server with migrations
10396 run : |
104- # Print debug info
105- echo "Current directory: $(pwd)"
106- echo "Files in bin directory:"
107- ls -la ./bin
108-
10997 # Run deploy script with migrations
11098 ./bin/deploy-with-migrations.sh
11199
112100 # Run test script to verify deployment
113- echo "Running test script on remote server..."
114- ssh -p 2048 [email protected] "cd $DEPLOY_REMOTE_DIR && chmod +x bin/test-github-actions.sh && ./bin/test-github-actions.sh" 101+ ssh -p 2048 -o ControlMaster=auto -o ControlPath=~/.ssh/control-%C -o ControlPersist=30s [email protected] "cd $DEPLOY_REMOTE_DIR && chmod +x bin/test-github-actions.sh && ./bin/test-github-actions.sh" 115102 env :
116103 DEPLOY_REMOTE_HOST : 104.36.23.197
117104 DEPLOY_REMOTE_PORT : 2048
0 commit comments