Skip to content

Commit 5eaa011

Browse files
committed
feat: improve SSH key handling in deployment workflow with enhanced error checks and debugging output
1 parent ede2e84 commit 5eaa011

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,34 @@ jobs:
131131
# Debug directory permissions
132132
ls -la ~ | grep .ssh
133133
134-
# Write the SSH key with proper error handling
134+
# Check if the SSH key secret is set
135135
if [ -z "${{ secrets.SSH_PRIVATE_KEY }}" ]; then
136136
echo "ERROR: SSH_PRIVATE_KEY secret is not set!"
137137
exit 1
138138
fi
139139
140-
# Use tee command for more reliable file writing
141-
echo "${{ secrets.SSH_PRIVATE_KEY }}" | tee ${{ env.SSH_KEY_PATH }} > /dev/null || {
142-
echo "ERROR: Failed to write SSH key file!"
140+
# Write SSH key file using direct redirection instead of tee
141+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ${{ env.SSH_KEY_PATH }}
142+
143+
# Check if the file was created
144+
if [ ! -f "${{ env.SSH_KEY_PATH }}" ]; then
145+
echo "ERROR: Failed to create SSH key file!"
143146
exit 1
144-
}
147+
fi
145148
146149
# Set proper permissions on the key file
147150
chmod 600 ${{ env.SSH_KEY_PATH }} || {
148151
echo "ERROR: Failed to set permissions on SSH key file!"
149152
exit 1
150153
}
151154
152-
# Verify the key was written correctly
153-
if [ ! -f "${{ env.SSH_KEY_PATH }}" ]; then
154-
echo "ERROR: Failed to create SSH key file!"
155-
exit 1
156-
fi
155+
# Verify file content (indirectly)
156+
key_size=$(stat -c %s ${{ env.SSH_KEY_PATH }})
157+
echo "SSH key file size: $key_size bytes"
157158
158-
# Verify permissions and file size
159-
ls -la ${{ env.SSH_KEY_PATH }}
160-
wc -l ${{ env.SSH_KEY_PATH }} || echo "Could not count lines in key file"
159+
if [ "$key_size" -lt 100 ]; then
160+
echo "WARNING: SSH key file seems too small, may be invalid"
161+
fi
161162
162163
# Add VM to known hosts - verify VM_IP_ADDRESS is set
163164
if [ -z "${{ secrets.VM_IP_ADDRESS }}" ]; then
@@ -170,9 +171,9 @@ jobs:
170171
exit 1
171172
}
172173
173-
# Test SSH connection
174+
# Test SSH connection (with verbose mode for debugging)
174175
echo "Testing SSH connection..."
175-
ssh -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} opc@${{ secrets.VM_IP_ADDRESS }} "echo SSH connection successful"
176+
ssh -v -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} opc@${{ secrets.VM_IP_ADDRESS }} "echo SSH connection successful"
176177
177178
- name: Deploy to Oracle VM
178179
run: |

0 commit comments

Comments
 (0)