Skip to content

Commit

Permalink
add Dockerfile (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigsanna authored Apr 26, 2024
1 parent f3251ef commit 61cb837
Show file tree
Hide file tree
Showing 8 changed files with 935 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.next/
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ARG APP_ENV
ARG GIGS_PROJECT
ARG GIGS_API_KEY

ENV APP_ENV=$APP_ENV
ENV GIGS_PROJECT=$GIGS_PROJECT
ENV GIGS_API_KEY=$GIGS_API_KEY

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# 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

CMD ["node", "server.js"]
3 changes: 3 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'
import { injectPrivateEnvVars } from '@/lib/utils'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -9,6 +10,8 @@ export const metadata: Metadata = {
description: 'By Gigs',
}

injectPrivateEnvVars()

export default function RootLayout({
children,
}: {
Expand Down
6 changes: 0 additions & 6 deletions lib/schemas/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ const validSubscriptionStatuses = ['pending', 'active', 'ended'] as const

type SubscriptionStatus = ElementOf<typeof validSubscriptionStatuses>

type Coverage = {
object: 'coverage'
id: string
name: string
countries: string[]
}
10 changes: 10 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ export const envVarsPresent = () => {

return !!gigsProject && !!gigsAPIKey
}

const privateEnvVars = {
APP_ENV: process.env.APP_ENV,
GIGS_PROJECT: process.env.GIGS_PROJECT,
GIGS_API_KEY: process.env.GIGS_API_KEY,
}

export function injectPrivateEnvVars() {
Object.assign(process.env, privateEnvVars)
}
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const nextConfig = {
]
: []
},
output: 'standalone',
}

module.exports = nextConfig
Loading

0 comments on commit 61cb837

Please sign in to comment.