diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..97aca2e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.env +node_modules \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6c67ea2..383d7ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ +.env node_modules /.cache /server/build /public/build /build -/app/styles +/app/styles \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d60f4c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,75 @@ +# base node image +FROM node:16-bullseye-slim as base + +ARG COMMIT_SHA + +# Install openssl for Prisma +RUN apt-get update && apt-get install -y openssl + +# Install all node_modules, including dev dependencies +FROM base as deps + +ARG COMMIT_SHA + +RUN mkdir /app +WORKDIR /app + +ADD package.json package-lock.json ./ +RUN npm install --production=false + +# Setup production node_modules +FROM base as production-deps + +ARG COMMIT_SHA + +RUN mkdir /app +WORKDIR /app + +COPY --from=deps /app/node_modules /app/node_modules +ADD package.json package-lock.json ./ +RUN npm prune --production + +# Build the app +FROM base as build + +ARG COMMIT_SHA +# RUN echo "build stage :>>>>>>>>>>>>>>>> COMMIT_SHA=$COMMIT_SHA" +# RUN echo "build stage :>>>>>>>>>>>>>>>> CSRF_KEY=$CSRF_KEY" + +# todo: KCD sets it only in last step? +ENV NODE_ENV=production + +RUN mkdir /app +WORKDIR /app + +COPY --from=deps /app/node_modules /app/node_modules + +# If we're using Prisma, uncomment to cache the prisma schema +# ADD prisma . +# RUN npx prisma generate + +ADD . . +RUN npm run build + +# Finally, build the production image with minimal footprint +FROM base + +ARG COMMIT_SHA +ENV COMMIT_SHA=$COMMIT_SHA +# ENV CSRF_KEY=$CSRF_KEY + +ENV NODE_ENV=production + +RUN mkdir /app +WORKDIR /app + +COPY --from=production-deps /app/node_modules /app/node_modules + +# Uncomment if using Prisma +# COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma + +COPY --from=build /app/build /app/build +COPY --from=build /app/public /app/public +ADD . . + +CMD ["npm", "run", "start"] diff --git a/app/app-context.ts b/app/app-context.ts new file mode 100644 index 0000000..29179b8 --- /dev/null +++ b/app/app-context.ts @@ -0,0 +1,8 @@ +import { createContext } from "react"; + +export const AppContext = createContext({ + // totalPathVisits: 0, + // path: "", + // setPageViewCountForPath: (path: string, visits: number) => {}, + setPageViewCountForPath: (visits: number) => {}, +}); diff --git a/app/components/age.tsx b/app/components/age.tsx new file mode 100644 index 0000000..51d6c12 --- /dev/null +++ b/app/components/age.tsx @@ -0,0 +1,28 @@ +import differenceInYears from "date-fns/differenceInYears"; + +type Props = { + year: number; + // note: JS Date so month starts at 0=January + month: number; + day: number; +}; + +export const Age = ({ year, month, day }: Props) => { + // based on https://stackoverflow.com/a/62375248/3484824 + // const years = Math.floor( + // (new Date().getTime() - new Date(1988, 0, 17).getTime()) / + // (1000 * 60 * 60 * 24 * 365), + // ); + // done: get birthday from some config or sthg? + const years = differenceInYears(new Date(), new Date(year, month, day)); + // return ; // todo: Research if `