Преглед на файлове

feature: add workout_cool service to docker compose file (#49)

* add workout_cool service to docker compose file

* connect to postgres not localhost

* update docker file to ensure sample files can be added optionally

* copy sample exercise to image and update setup.sh script to import seed data based on env

* update readme with setup instructions for docker compose
Norris Oduro преди 1 месец
родител
ревизия
0c9c4b7d2c
променени са 6 файла, в които са добавени 37 реда и са изтрити 10 реда
  1. 5 2
      .env.example
  2. 3 1
      Dockerfile
  3. 1 1
      Makefile
  4. 13 0
      README.md
  5. 11 1
      docker-compose.yml
  6. 4 5
      scripts/setup.sh

+ 5 - 2
.env.example

@@ -27,11 +27,14 @@ NEXT_PUBLIC_FACEBOOK_PIXEL_ID="123456789"
 # Options: development, production, test
 NODE_ENV="development"
 
-#SMTP Configuration 
-# Using MailHog for example. https://github.com/mailhog/MailHog 
+#SMTP Configuration
+# Using MailHog for example. https://github.com/mailhog/MailHog
 SMTP_HOST=localhost
 SMTP_PORT=1025
 SMTP_USER=
 SMTP_PASS=
 SMTP_FROM="Workout Cool <noreply@workout.cool>"
 SMTP_SECURE=false
+
+# Whether to seed sample data on startup
+SEED_SAMPLE_DATA=true

+ 3 - 1
Dockerfile

@@ -15,6 +15,7 @@ COPY --from=deps /app/node_modules ./node_modules
 COPY --from=deps /app/prisma ./prisma
 COPY . .
 COPY .env.example .env
+
 RUN pnpm run build
 
 # Production image, copy only necessary files
@@ -26,8 +27,9 @@ COPY --from=builder /app/.next ./.next
 COPY --from=builder /app/node_modules ./node_modules
 COPY --from=builder /app/package.json ./package.json
 COPY --from=builder /app/prisma ./prisma
+COPY --from=builder /app/data ./data
 
-COPY scripts/setup.sh /app/setup.sh
+COPY scripts /app
 RUN chmod +x /app/setup.sh
 
 ENTRYPOINT ["/app/setup.sh"]

+ 1 - 1
Makefile

@@ -13,7 +13,7 @@ help:
 
 # Start Postgres with Docker Compose
 up:
-	docker compose up -d
+	docker compose up -d postgres
 
 # Stop Docker Compose
 down:

+ 13 - 0
README.md

@@ -222,6 +222,8 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
 
 ## Deployment / Self-hosting
 
+To seed the database with the sample exercises, set the `SEED_SAMPLE_DATA` env variable to `true`.
+
 ### Using Docker
 
 ```bash
@@ -232,6 +234,17 @@ docker build -t yourusername/workout-cool .
 docker run -p 3000:3000 --env-file .env.production yourusername/workout-cool
 ```
 
+### Using Docker Compose
+
+#### DATABASE_URL
+Update the `host` to point to the `postgres` service instead of `localhost`
+`DATABASE_URL=postgresql://username:password@postgres:5432/workout_cool`
+
+```bash
+docker compose up -d
+```
+
+
 ### Manual Deployment
 
 ```bash

+ 11 - 1
docker-compose.yml

@@ -2,7 +2,7 @@ services:
   postgres:
     image: postgres:15
     ports:
-      - "5432:5432"
+      - "${DB_PORT:-5432}:5432"
     environment:
       POSTGRES_USER: username
       POSTGRES_PASSWORD: password
@@ -15,5 +15,15 @@ services:
       timeout: 5s
       retries: 5
 
+  workout_cool:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    ports:
+      - "${APP_PORT:-3000}:3000"
+    depends_on:
+      postgres:
+        condition: service_healthy
+    env_file: .env
 volumes:
   pgdata:

+ 4 - 5
scripts/setup.sh

@@ -6,17 +6,16 @@ npx prisma migrate deploy
 echo "Generating Prisma client..."
 npx prisma generate
 
-
-if [ "$NODE_ENV" != "production" ]; then
-  echo "Non-production environment detected, importing sample data..."
+if [ "$SEED_SAMPLE_DATA" = "true"  ]; then
+  echo "Seed sample data enabled, importing sample data..."
     # Import exercises if CSV exists
     if [ -f "./data/sample-exercises.csv" ]; then
-        npx tsx scripts/import-exercises-with-attributes.ts ./sample-data/exercises.csv
+        npx tsx import-exercises-with-attributes.ts ./data/sample-exercises.csv
     else
         echo "No exercises sample data found, skipping import."
     fi
 else
-  echo "Production environment, skipping sample data import."
+  echo "Skipping sample data import."
 fi
 
 echo "Starting the app..."