fix: dedicated pre-build image pipeline

This commit is contained in:
talatops 2026-03-30 10:58:50 +05:00
parent 5b44f6a4c1
commit e8fa4a87ac
2 changed files with 53 additions and 4 deletions

View File

@ -85,7 +85,7 @@ jobs:
- name: Copy deployment files to server
run: |
# Copy docker-compose (app + Postgres), and .env
scp -i ssh_key.pem -o StrictHostKeyChecking=no docker-compose.yml ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:${{ env.REMOTE_DIR }}/docker-compose.yml
scp -i ssh_key.pem -o StrictHostKeyChecking=no docker-compose.ec2.yml ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:${{ env.REMOTE_DIR }}/docker-compose.ec2.yml
scp -i ssh_key.pem -o StrictHostKeyChecking=no .env ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:${{ env.REMOTE_DIR }}/.env
# Copy application image tar
@ -123,14 +123,14 @@ jobs:
# Rolling update with docker compose (app + Postgres)
echo "=== ROLLING UPDATE (docker compose up -d) ==="
if ! docker compose -f docker-compose.yml --env-file .env up -d --no-build --remove-orphans; then
if ! docker compose -f docker-compose.ec2.yml --env-file .env up -d --remove-orphans; then
echo "ERROR: Deployment failed"
docker compose -f docker-compose.yml down || true
docker compose -f docker-compose.ec2.yml down || true
exit 1
fi
echo "✅ Deployment successful! Current services:"
docker compose -f docker-compose.yml --env-file .env ps
docker compose -f docker-compose.ec2.yml --env-file .env ps
# Final cleanup (preserve volumes; prune dangling images only)
docker system prune -f --volumes=false || true

49
docker-compose.ec2.yml Normal file
View File

@ -0,0 +1,49 @@
services:
db:
# Use a Postgres image with pgvector preinstalled so we can enable the `vector` extension
image: pgvector/pgvector:pg17
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_DB:-dropshipping}
ports:
- "5444:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
# Ensure the pgvector extension is created on first database init
- ./prisma/init-pgvector.sql:/docker-entrypoint-initdb.d/init-pgvector.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
app:
# IMPORTANT: EC2 deploy copies only the compose file + env + image tar.
# Do not include `build:` here; otherwise Compose will look for a Dockerfile on EC2.
image: ${IMAGE_NAME:-junohub-app}:latest
restart: always
ports:
- "3000:3000"
env_file:
- .env
environment:
# Override DATABASE_URL to use internal docker network hostname
DATABASE_URL: postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-password}@db:5432/${POSTGRES_DB:-dropshipping}?schema=public
NODE_ENV: production
volumes:
- ./public/uploads/supplier-products:/app/public/uploads/supplier-products
depends_on:
db:
condition: service_healthy
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
volumes:
postgres_data: