Skip to content

Commit a751503

Browse files
added nginx setup
1 parent 04a116e commit a751503

3 files changed

Lines changed: 151 additions & 34 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,29 @@ jobs:
209209
exit 1
210210
fi
211211
212-
# Run the simplified deployment script
213-
echo "Executing zero-downtime deployment..."
214-
if ./scripts/deploy.sh --version "${{secrets.PACKAGE_VERSION}}"; then
215-
echo "✅ Deployment successful"
216-
else
217-
echo "❌ Deployment failed - automatic rollback should have occurred"
218-
exit 1
219-
fi
212+
# Navigate to the executeme directory on the VPS.
213+
cd ~/${{secrets.PACKAGE_NAME}}
214+
215+
# make sure we are in executeme directory
216+
ls -a
217+
218+
# Pull the latest code from the 'main' branch of the GitHub repository.
219+
git pull origin main
220+
221+
# Check git status to make sure everything is up to date
222+
# git status
223+
224+
# Execute your bash script.
225+
bash ./scripts/simple-deploy.sh
226+
227+
# # Run the simplified deployment script
228+
# echo "Executing zero-downtime deployment..."
229+
# if ./scripts/deploy.sh --version "${{secrets.PACKAGE_VERSION}}"; then
230+
# echo "✅ Deployment successful"
231+
# else
232+
# echo "❌ Deployment failed - automatic rollback should have occurred"
233+
# exit 1
234+
# fi
220235
221236
# Cleanup
222237
docker logout
@@ -225,29 +240,29 @@ jobs:
225240
echo "🎉 DEPLOYMENT COMPLETED SUCCESSFULLY!"
226241
DEPLOY_EOF
227242
228-
- name: Verify Deployment ✅
229-
run: |
230-
echo "Verifying deployment..."
231-
ssh deploy-server bash << 'VERIFY_EOF'
232-
cd ~/${{secrets.PACKAGE_NAME}}
233-
234-
echo "=== Running deployment status check ==="
235-
./scripts/deploy.sh status
236-
237-
echo "=== Testing endpoint directly ==="
238-
if curl -f -s --connect-timeout 5 --max-time 10 "http://localhost:${{secrets.PORT}}/" | grep -q '"status":"ok"'; then
239-
echo "🎉 Endpoint health check passed! Service is responding with status: ok"
240-
else
241-
echo "❌ Endpoint health check failed!"
242-
exit 1
243-
fi
244-
245-
echo "=== Final verification ==="
246-
echo "Deployment verified successfully!"
247-
VERIFY_EOF
248-
249-
- name: Cleanup 🧹
250-
if: always()
251-
run: |
252-
rm -rf ~/.ssh/deploy_key* ~/.ssh/config
253-
rm -f .env
243+
# - name: Verify Deployment ✅
244+
# run: |
245+
# echo "Verifying deployment..."
246+
# ssh deploy-server bash << 'VERIFY_EOF'
247+
# cd ~/${{secrets.PACKAGE_NAME}}
248+
249+
# echo "=== Running deployment status check ==="
250+
# ./scripts/deploy.sh status
251+
252+
# echo "=== Testing endpoint directly ==="
253+
# if curl -f -s --connect-timeout 5 --max-time 10 "http://localhost:${{secrets.PORT}}/" | grep -q '"status":"ok"'; then
254+
# echo "🎉 Endpoint health check passed! Service is responding with status: ok"
255+
# else
256+
# echo "❌ Endpoint health check failed!"
257+
# exit 1
258+
# fi
259+
260+
# echo "=== Final verification ==="
261+
# echo "Deployment verified successfully!"
262+
# VERIFY_EOF
263+
264+
# - name: Cleanup 🧹
265+
# if: always()
266+
# run: |
267+
# rm -rf ~/.ssh/deploy_key* ~/.ssh/config
268+
# rm -f .env

.github/workflows/nginx-setup.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: 🚀 Deploy NGINX HTTPS Reverse Proxy 🔐
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Deployment VPS"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
deploy:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: 📥 Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: 🔧 Setup and load environment
19+
uses: ./.github/actions/setup-and-load-env
20+
with:
21+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
22+
PACKAGE_NAME: ${{ secrets.PACKAGE_NAME }}
23+
PACKAGE_VERSION: ${{ secrets.PACKAGE_VERSION }}
24+
EMAIL: ${{ secrets.EMAIL }}
25+
BASE_URL: ${{ secrets.BASE_URL }}
26+
PORT: ${{ secrets.PORT }}
27+
IMAGE_TAG: ${{ secrets.IMAGE_TAG }}
28+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
29+
GIT_TOKEN: ${{ secrets.EXECUTE_ME_GITHUB_TOKEN }}
30+
VPS_HOST: ${{ secrets.VPS_HOST }}
31+
VPS_USER: ${{ secrets.VPS_USER }}
32+
VPS_SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
33+
34+
- name: 📋 Verify environment variables
35+
run: |
36+
echo "Package name: $PACKAGE_NAME"
37+
echo "Package version: $PACKAGE_VERSION"
38+
echo "Docker image: $IMAGE_TAG"
39+
echo "✅ Environment variables are accessible"
40+
41+
- name: 🔐 Setup SSH
42+
run: |
43+
mkdir -p ~/.ssh
44+
chmod 700 ~/.ssh
45+
echo "${{secrets.VPS_SSH_PRIVATE_KEY}}" | tr -d '\r' > ~/.ssh/deploy_key
46+
chmod 600 ~/.ssh/deploy_key
47+
ssh-keyscan -H ${{secrets.VPS_HOST}} >> ~/.ssh/known_hosts
48+
49+
cat > ~/.ssh/config << EOF
50+
Host deploy-server
51+
HostName ${{secrets.VPS_HOST}}
52+
User ${{secrets.VPS_USER}}
53+
IdentityFile ~/.ssh/deploy_key
54+
StrictHostKeyChecking no
55+
EOF
56+
chmod 600 ~/.ssh/config
57+
58+
- name: 🚀 Test SSH Connection
59+
run: ssh deploy-server "echo '✅ SSH connection successful'"
60+
61+
- name: 📁 Debug scripts directory
62+
run: ls -al ./scripts
63+
64+
- name: 🧪 Run NGINX Setup Script on VPS
65+
run: |
66+
echo "🚀 Preparing to run setup-nginx.sh on VPS"
67+
68+
ssh deploy-server "bash -s" <<EOF
69+
set -e
70+
cd ~/${{secrets.PACKAGE_NAME}}
71+
72+
for file in scripts/generate-self-signed-cert.sh scripts/setup-nginx.sh; do
73+
if [ ! -f "$file" ]; then
74+
echo "❌ $file not found. Will copy from runner."
75+
exit 10
76+
else
77+
echo "✅ $(basename "$file") found on VPS"
78+
fi
79+
done
80+
EOF
81+
82+
# Check exit code; if 10, then copy scripts directory
83+
if [ $? -eq 10 ]; then
84+
echo "📤 Copying scripts directory to VPS..."
85+
scp -r ./scripts deploy-server:~/${{secrets.PACKAGE_NAME}}/
86+
fi
87+
88+
echo "🔐 Generate CERT"
89+
ssh deploy-server "cd ~/${{secrets.PACKAGE_NAME}}/scripts && chmod +x generate-self-signed-cert.sh && ./generate-self-signed-cert.sh"
90+
91+
echo "🚀 Running setup-nginx.sh on VPS..."
92+
ssh deploy-server "cd ~/${{secrets.PACKAGE_NAME}}/scripts && chmod +x setup-nginx.sh && ./setup-nginx.sh"

scripts/simple-deploy.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## delete all containers including its volumes use
2+
docker stop $(docker ps -a -q) # stop all container
3+
4+
docker rm -vf $(docker ps -aq) # rm all container
5+
6+
## delete all the images
7+
docker rmi -f $(docker images -aq)
8+
9+
## create container with new force command
10+
docker compose --profile prod up --force-recreate

0 commit comments

Comments
 (0)