Skip to content

Commit

Permalink
docker included
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiDaniel committed Jan 9, 2025
1 parent c4d9d9e commit 74ddeac
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
node_modules
npm-debug.log
Dockerfile
docker-compose.yml

# Ignore node_modules
node_modules

# Ignore logs
logs
*.log

# Ignore build output
.next
out

# Ignore environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Miscellaneous
.DS_Store
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# testing
/coverage

# Ignore logs
logs
*.log

# next.js
/.next/
/out/
Expand All @@ -34,6 +38,14 @@ yarn-error.log*
.vercel
.editorconfig



# Production
build/

# typescript
*.tsbuildinfo
next-env.d.ts

# Ignore local Docker files
docker-compose.override.yml
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# syntax=docker.io/docker/dockerfile:1

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 based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


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

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED=1

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

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

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# 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

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
2 changes: 1 addition & 1 deletion app/components/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function MainNav() {
<Link href="/" className="flex items-center space-x-44">
{/* <Icons.logo className="h-16 w-16" /> */}

<h1 className="font-extrabold text-3xl pb-2">StickeyLikeMickey🚀</h1>
<h1 className="font-extrabold text-3xl p-2">Stick with me</h1>

<span className="inline-block text-2xl font-bold">
{siteConfig.name}
Expand Down
33 changes: 33 additions & 0 deletions cache-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const cache = new Map();

module.exports = class CacheHandler {
constructor(options) {
this.options = options;
}

async get(key) {
// This could be stored anywhere, like durable storage
return cache.get(key);
}

async set(key, data, ctx) {
// This could be stored anywhere, like durable storage
cache.set(key, {
value: data,
lastModified: Date.now(),
tags: ctx.tags,
});
}

async revalidateTag(tags) {
// tags is either a string or an array of strings
tags = [tags].flat();
// Iterate over all entries in the cache
for (let [key, value] of cache) {
// If the value's tags include the specified tag, delete this entry
if (value.tags.some((tag) => tags.include(tag))) {
cache.delete(key);
}
}
}
};
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
/* output: "standalone", */
/* cacheHandler: require.resolve("./cache-handler.js"),
cacheMaxMemorySize: 0, // disable default in-memory caching
*/
reactStrictMode: true,
images: {
domains: ["cdn.sanity.io"],
Expand Down

0 comments on commit 74ddeac

Please sign in to comment.