Skip to content

Commit acf985c

Browse files
committed
feat: update deployment workflow to enhance VM setup and Nginx configuration; streamline SSH key handling and add Docker Compose deployment
1 parent 1e5d3d0 commit acf985c

File tree

1 file changed

+21
-54
lines changed

1 file changed

+21
-54
lines changed

.github/workflows/deploy.yml

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ jobs:
164164
- name: Verify VM Connection
165165
env:
166166
ORACLE_VM_IP: ${{ secrets.ORACLE_VM_IP }}
167+
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
167168
run: |
168-
echo "Verifying VM connection..."
169-
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ssh_key.pem
169+
echo "$SSH_KEY" > ssh_key.pem
170170
chmod 600 ssh_key.pem
171-
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -i ssh_key.pem opc@${ORACLE_VM_IP} echo "VM connection successful" || exit 1
171+
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "echo VM connection successful"
172172
173173
- name: Deploy to Oracle VM
174174
env:
@@ -178,58 +178,25 @@ jobs:
178178
run: |
179179
echo "$SSH_KEY" > ssh_key.pem
180180
chmod 600 ssh_key.pem
181-
182-
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} <<EOF
183-
cd ~/music-analytics/vm-deploy || exit 1
184-
echo "${{ secrets.OCI_AUTH_TOKEN }}" | docker login ${{ secrets.OCI_REGISTRY }} -u ${{ secrets.OCI_USERNAME }} --password-stdin || exit 1
185-
export ORACLE_EXTERNAL_HOSTNAME=${{ secrets.ORACLE_VM_IP }}
186-
export DOCKER_REGISTRY=${{ secrets.OCI_REGISTRY }}
187-
docker-compose pull || exit 1
188-
docker-compose up -d || exit 1 server {
189-
listen 443 ssl;
190-
server_name _;
191-
192-
ssl_certificate /etc/nginx/ssl/nginx.crt;
193-
ssl_certificate_key /etc/nginx/ssl/nginx.key;
194-
195-
# Enable detailed logging
196-
access_log /var/log/nginx/music-analytics-access.log;
197-
error_log /var/log/nginx/music-analytics-error.log;
198-
199-
location / {
200-
# CORS headers inside location block
201-
add_header 'Access-Control-Allow-Origin' 'https://musicanalytics.netlify.app' always;
202-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
203-
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;
204-
205-
# Proxy settings
206-
proxy_pass http://localhost:8080;
207-
proxy_set_header Host $host;
208-
proxy_set_header X-Real-IP $remote_addr;
209-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
210-
proxy_set_header X-Forwarded-Proto $scheme;
211-
212-
# Handle OPTIONS requests
213-
if ($request_method = 'OPTIONS') {
214-
add_header 'Access-Control-Allow-Origin' 'https://musicanalytics.netlify.app' always;
215-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
216-
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;
217-
add_header 'Access-Control-Max-Age' 1728000;
218-
add_header 'Content-Type' 'text/plain charset=UTF-8';
219-
add_header 'Content-Length' 0;
220-
return 204;
221-
}
222-
}
223-
}
224181
225-
server {
226-
listen 80;
227-
server_name _;
228-
return 301 https://$host$request_uri;
229-
}
230-
docker logout ${{ secrets.OCI_REGISTRY }}
231-
echo "Deployment completed successfully"
232-
EOF
182+
# Create directory structure on VM
183+
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "mkdir -p ~/music-analytics/nginx ~/music-analytics/vm-deploy"
184+
185+
# Copy Nginx config and setup script to VM
186+
scp -o StrictHostKeyChecking=no -i ssh_key.pem cloud-deploy/nginx/music-analytics.conf opc@${ORACLE_VM_IP}:~/music-analytics/nginx/
187+
scp -o StrictHostKeyChecking=no -i ssh_key.pem cloud-deploy/nginx/setup-nginx.sh opc@${ORACLE_VM_IP}:~/music-analytics/nginx/
188+
189+
# Copy Docker Compose file to VM
190+
scp -o StrictHostKeyChecking=no -i ssh_key.pem cloud-deploy/docker-compose.direct.yml opc@${ORACLE_VM_IP}:~/music-analytics/vm-deploy/docker-compose.yml
191+
192+
# Make setup script executable
193+
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "chmod +x ~/music-analytics/nginx/setup-nginx.sh"
194+
195+
# Run setup script
196+
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "~/music-analytics/nginx/setup-nginx.sh"
197+
198+
# Deploy Docker services
199+
ssh -o StrictHostKeyChecking=no -i ssh_key.pem opc@${ORACLE_VM_IP} "cd ~/music-analytics/vm-deploy && docker login ${DOCKER_REGISTRY} -u ${OCI_USERNAME} -p ${OCI_AUTH_TOKEN} && export ORACLE_EXTERNAL_HOSTNAME=${ORACLE_VM_IP} && export DOCKER_REGISTRY=${DOCKER_REGISTRY} && docker-compose pull && docker-compose up -d && docker logout ${DOCKER_REGISTRY}"
233200
234201
rm -f ssh_key.pem
235202

0 commit comments

Comments
 (0)