Skip to content

Commit 4d162b9

Browse files
committed
Use frontend/Dockerfile.prod for fly
1 parent 7026055 commit 4d162b9

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
build:
44
context: ./frontend
55
dockerfile: Dockerfile
6+
# dockerfile: Dockerfile.prod
67
ports:
78
- "3000:3000"
89
volumes:

frontend/Dockerfile.prod

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
# Build stage
21
FROM node:18-alpine AS builder
32

3+
# Define build arguments
4+
ARG NEXT_PUBLIC_API_URL
5+
ARG NEXT_PUBLIC_POCKETBASE_URL
6+
ARG NEXT_PUBLIC_SEARCH_URL
7+
ARG NEXT_PUBLIC_MEILI_URL
8+
49
WORKDIR /app
510

11+
# Set environment variables for build time
12+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
13+
ENV NEXT_PUBLIC_POCKETBASE_URL=${NEXT_PUBLIC_POCKETBASE_URL}
14+
ENV NEXT_PUBLIC_SEARCH_URL=${NEXT_PUBLIC_SEARCH_URL}
15+
ENV NEXT_PUBLIC_MEILI_URL=${NEXT_PUBLIC_MEILI_URL}
16+
617
# Install dependencies
718
COPY package.json package-lock.json ./
819
RUN npm ci
@@ -11,26 +22,43 @@ RUN npm ci
1122
COPY . .
1223

1324
# Build the application
14-
ENV NEXT_TELEMETRY_DISABLED 1
1525
RUN npm run build
1626

17-
# Production stage
27+
# Production image
1828
FROM node:18-alpine AS runner
19-
2029
WORKDIR /app
2130

22-
ENV NODE_ENV=production
23-
ENV NEXT_TELEMETRY_DISABLED 1
31+
ENV NODE_ENV production
32+
33+
# Pass build arguments to runtime environment variables
34+
ARG NEXT_PUBLIC_API_URL
35+
ARG NEXT_PUBLIC_POCKETBASE_URL
36+
ARG NEXT_PUBLIC_SEARCH_URL
37+
ARG NEXT_PUBLIC_MEILI_URL
2438

25-
# Copy necessary files from builder
39+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
40+
ENV NEXT_PUBLIC_POCKETBASE_URL=${NEXT_PUBLIC_POCKETBASE_URL}
41+
ENV NEXT_PUBLIC_SEARCH_URL=${NEXT_PUBLIC_SEARCH_URL}
42+
ENV NEXT_PUBLIC_MEILI_URL=${NEXT_PUBLIC_MEILI_URL}
43+
44+
# Add non-root user for security
45+
RUN addgroup --system --gid 1001 nodejs
46+
RUN adduser --system --uid 1001 nextjs
47+
48+
# Copy only necessary files from builder stage
2649
COPY --from=builder /app/next.config.ts ./
27-
COPY --from=builder /app/package.json ./
2850
COPY --from=builder /app/public ./public
29-
COPY --from=builder /app/.next/standalone ./
30-
COPY --from=builder /app/.next/static ./.next/static
51+
COPY --from=builder /app/package.json ./package.json
52+
53+
# Copy the built application
54+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
55+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
56+
57+
# Set the correct permissions
58+
USER nextjs
3159

32-
# Expose the port
60+
# Expose the port the app runs on
3361
EXPOSE 3000
3462

35-
# Start the application
36-
CMD ["node", "server.js"]
63+
# Command to run the application in production mode
64+
CMD ["node", "server.js"]

frontend/fly.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ app = "localmart-frontend"
22
primary_region = "ewr" # Change this to your preferred region
33

44
[build]
5-
# dockerfile = "Dockerfile.prod"
6-
dockerfile = "Dockerfile"
5+
dockerfile = "Dockerfile.prod"
6+
# dockerfile = "Dockerfile"
7+
[build.args]
8+
NEXT_PUBLIC_API_URL = "https://localmart-backend.fly.dev"
9+
NEXT_PUBLIC_POCKETBASE_URL = "https://localmart-pocketbase.fly.dev"
10+
NEXT_PUBLIC_SEARCH_URL = "https://localmart-search.fly.dev"
11+
NEXT_PUBLIC_MEILI_URL = "https://localmart-meilisearch.fly.dev"
712

813
[env]
914
NODE_ENV = "production"

python-backend/localmart_backend/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,15 @@ async def delete_payment_method(card_id: str, authorization: str = Header(None))
865865
raise HTTPException(status_code=401, detail="Invalid token")
866866

867867
# Get the card from PocketBase
868-
card = pb(token).pb.collection('payment_methods').get_one(card_id)
868+
card = pb(token).get_one('payment_methods', card_id)
869869
if not card or card.user != user.id:
870870
raise HTTPException(status_code=404, detail="Card not found")
871871

872872
# Delete the payment method from Stripe
873873
stripe.PaymentMethod.detach(card.stripe_payment_method_id)
874874

875875
# Delete the card from PocketBase
876-
pb(token).pb.collection('payment_methods').delete(card_id)
876+
pb(token).delete('payment_methods', card_id)
877877

878878
return {"status": "success"}
879879

@@ -1179,7 +1179,7 @@ async def delete_store_item(store_id: str, item_id: str, request: Request):
11791179
raise HTTPException(status_code=404, detail="Item not found in store")
11801180

11811181
# Delete the item
1182-
pb(token).collection('store_items').delete(item_id)
1182+
pb(token).delete('store_items', item_id)
11831183
return {"success": True}
11841184
except Exception as e:
11851185
raise HTTPException(status_code=400, detail=str(e))

0 commit comments

Comments
 (0)