Skip to content

Commit

Permalink
Add database initialization script and update Docker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mayura-andrew committed Dec 1, 2024
1 parent d2fc4cc commit bbeec76
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ RUN npm install
# (assuming your app is in the "src" directory of your project)
COPY . .

# Copy the init-db.sh script to the working directory
COPY init-db.sh /app/src/init-db.sh

# Make the init-db.sh script executable
RUN chmod +x /app/src/init-db.sh
# Make port 8080 available to the world outside this container
EXPOSE 8080

# Run the app when the container launches
CMD [ "npm", "start" ]

CMD [ "sh", "init-db.sh"]
22 changes: 17 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ services:
depends_on:
- db
environment:
- DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
- DB_HOST=db
- DB_PORT=5432
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
- JWT_SECRET=${JWT_SECRET}
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- GOOGLE_REDIRECT_URL=${GOOGLE_REDIRECT_URL}
- LINKEDIN_CLIENT_ID=${LINKEDIN_CLIENT_ID}
- LINKEDIN_CLIENT_SECRET=${LINKEDIN_CLIENT_SECRET}
- LINKEDIN_REDIRECT_URL=${LINKEDIN_REDIRECT_URL}
- CLIENT_URL=${CLIENT_URL}
- IMG_HOST=${IMG_HOST}
- SMTP_MAIL=${SMTP_MAIL}
- SMTP_PASS=${SMTP_PASS}
command: ["sh", "/app/src/init-db.sh"]
db:

image: postgres:15
ports:
- "5432:5432"

environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}

- POSTGRES_DB=${DB_NAME}
16 changes: 16 additions & 0 deletions init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a script to initialize the database for the first time when the container is started.
# It will wait for the database to be ready before running the migrations.
# Wait for the

echo "Database is ready. Running migrations..."

# Run the migrations
npm run sync:db
npm run migration:generate
npm run seed

echo "Migrations complete. Database is ready."

# Start the application

npm run dev

0 comments on commit bbeec76

Please sign in to comment.