mirror of
https://github.com/jakobkordez/ham-reserve.git
synced 2025-05-15 16:20:29 +00:00
Dockerize
This commit is contained in:
parent
eb29ab1b31
commit
fae4c25164
25
compose.yaml
Normal file
25
compose.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# mongo:
|
||||
# image: mongo
|
||||
# expose:
|
||||
# - '27017:27017'
|
||||
# volumes:
|
||||
# - ~/mongo/data:/data/db
|
||||
api:
|
||||
build: ./nest-api
|
||||
ports:
|
||||
- '3001:3001'
|
||||
env_file: .env.production.local
|
||||
# environment:
|
||||
# MONGODB_URI: mongodb://mongo:27017/ham-reserve
|
||||
# depends_on:
|
||||
# - mongo
|
||||
frontend:
|
||||
build:
|
||||
context: ./next-app
|
||||
args:
|
||||
API_BASE_URL: http://api:3001
|
||||
ports:
|
||||
- '3000:3000'
|
6
nest-api/.dockerignore
Normal file
6
nest-api/.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
node_modules/
|
||||
dist/
|
||||
.env*
|
||||
.gitignore
|
36
nest-api/Dockerfile
Normal file
36
nest-api/Dockerfile
Normal file
@ -0,0 +1,36 @@
|
||||
FROM node:20-alpine AS deps
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY --chown=node:node package.json yarn.lock ./
|
||||
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
COPY --chown=node:node . .
|
||||
|
||||
USER node
|
||||
|
||||
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY --chown=node:node package.json yarn.lock ./
|
||||
COPY --chown=node:node --from=deps /usr/src/app/node_modules ./node_modules
|
||||
COPY --chown=node:node . .
|
||||
|
||||
RUN yarn build
|
||||
|
||||
ENV NODE_ENV production
|
||||
|
||||
RUN yarn install --production --frozen-lockfile
|
||||
|
||||
USER node
|
||||
|
||||
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
COPY --from=builder /usr/src/app/node_modules ./node_modules
|
||||
COPY --from=builder /usr/src/app/dist ./dist
|
||||
|
||||
CMD [ "node", "dist/main.js" ]
|
6
next-app/.dockerignore
Normal file
6
next-app/.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
node_modules/
|
||||
.next/
|
||||
.env*
|
||||
.gitignore
|
52
next-app/Dockerfile
Normal file
52
next-app/Dockerfile
Normal file
@ -0,0 +1,52 @@
|
||||
FROM node:20-alpine AS deps
|
||||
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
ARG API_BASE_URL
|
||||
ENV API_BASE_URL=$API_BASE_URL
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
RUN yarn build
|
||||
|
||||
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV production
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Set the correct permission for prerender cache
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT 3000
|
||||
# set hostname to localhost
|
||||
ENV HOSTNAME "0.0.0.0"
|
||||
|
||||
CMD ["node", "server.js"]
|
@ -1,8 +1,12 @@
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3001'
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: 'standalone',
|
||||
|
||||
rewrites: async () => [{
|
||||
source: '/api/:path*',
|
||||
destination: 'http://localhost:3001/:path*' // Proxy to Backend
|
||||
destination: `${apiBaseUrl}/:path*`
|
||||
}]
|
||||
}
|
||||
|
||||
|
@ -47,14 +47,12 @@ export const useAuthState = create(
|
||||
|
||||
if (accessToken) {
|
||||
const { exp } = jwtDecode(accessToken) as { exp: number };
|
||||
console.log('Access token exp', exp);
|
||||
if (Date.now() < exp * 1000) return true;
|
||||
else set({ accessToken: null });
|
||||
}
|
||||
|
||||
if (refreshToken) {
|
||||
const { exp } = jwtDecode(refreshToken) as { exp: number };
|
||||
console.log('Refresh token exp', exp);
|
||||
if (Date.now() < exp * 1000) {
|
||||
// Try to refresh
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user