diff --git a/Dockerfile b/Dockerfile index 9dfbc51..a7efab9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 2ea7951..6fed9f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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} \ No newline at end of file diff --git a/init-db.sh b/init-db.sh new file mode 100755 index 0000000..d61afdf --- /dev/null +++ b/init-db.sh @@ -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