diff --git a/.env.example b/.env.example index 2b1531e..0631423 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,5 @@ DATABASE_URL="postgres://root:mysecretpassword@localhost:5432/local" +POSTGRES_USER=root +POSTGRES_PASSWORD=mysecretpassword +POSTGRES_DB=local +PROJECT_TOKEN=CHROMATIC_PROJECT_TOKEN diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..83b00fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# Use Node.js 18 alpine as base image +FROM node:18-alpine AS base + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package.json ./ + +# Install dependencies +RUN npm install + +# Copy source code +COPY . . + +# Build the application +RUN npm run build + +# Production stage +FROM node:18-alpine AS production + +WORKDIR /app + +# Copy package files +COPY package.json ./ + +# Install only production dependencies +RUN npm install --only=production + +# Copy built application from build stage +COPY --from=base /app/build ./build +COPY --from=base /app/static ./static +COPY --from=base /app/package.json ./ + +# Expose port +EXPOSE 3000 + +# Set environment +ENV NODE_ENV=production +ENV PORT=3000 + +# Start the application +CMD ["node", "build"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5ec5392..9bc7d25 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,26 @@ -services: - db: - image: postgres - restart: always - ports: - - 5432:5432 - environment: - POSTGRES_USER: root - POSTGRES_PASSWORD: mysecretpassword - POSTGRES_DB: local - volumes: - - pgdata:/var/lib/postgresql/data + services: + db: + image: postgres + restart: always + ports: + - 5432:5432 + env_file: + - .env + environment: + POSTGRES_USER: ${POSTGRES_USER:-root} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-mysecretpassword} + POSTGRES_DB: ${POSTGRES_DB:-local} + volumes: + - pgdata:/var/lib/postgresql/data + app: + build: . + ports: + - 3000:3000 + env_file: + - .env + environment: + DATABASE_URL: postgres://${POSTGRES_USER:-root}:${POSTGRES_PASSWORD:-mysecretpassword}@db:5432/${POSTGRES_DB:-local} + depends_on: + - db volumes: pgdata: