File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,18 @@ jobs:
148148 needs : build_and_push_docker_image
149149 if : github.ref == 'refs/heads/main'
150150 steps :
151+ - name : Checkout code
152+ uses : actions/checkout@v4
153+
154+ - name : Copy docker-compose.yml to server
155+ 156+ with :
157+ host : ${{ secrets.SERVER_HOST }}
158+ username : ${{ secrets.SERVER_USER }}
159+ key : ${{ secrets.SERVER_SSH_KEY }}
160+ source : " docker-compose.yml,nginx.conf"
161+ target : " /root"
162+
151163 - name : Deploy to server
152164153165 with :
@@ -156,6 +168,26 @@ jobs:
156168 key : ${{ secrets.SERVER_SSH_KEY }}
157169 script : |
158170 cd /root
159- docker compose pull rails
160- docker compose up -d rails
171+ docker compose pull
172+ docker compose up -d
173+ # Clean up old images from ghcr.io registry (keep only the latest)
174+ docker images 'ghcr.io/oddsteam/dailynews-e-newspaper' --format '{{.ID}} {{.Tag}}' | grep -v 'latest' | awk '{print $1}' | xargs -r docker rmi -f || true
175+
176+ - name : Health check
177+ run : |
178+ echo "Waiting for services to start..."
179+ sleep 15
180+
181+ echo "Checking application health..."
182+ for i in {1..5}; do
183+ if curl -f -s http://${{ secrets.SERVER_HOST }}/up > /dev/null; then
184+ echo "✓ Health check passed!"
185+ exit 0
186+ fi
187+ echo "Attempt $i failed, retrying in 10 seconds..."
188+ sleep 10
189+ done
190+
191+ echo "✗ Health check failed after 5 attempts"
192+ exit 1
161193
You can’t perform that action at this time.
0 commit comments