From 856df7522228098ac68d320a6fffda29ab45a731 Mon Sep 17 00:00:00 2001 From: ChrQR Date: Sat, 11 May 2024 00:45:03 +0200 Subject: [PATCH] added time to hourlycard and added dockerfile --- Dockerfile | 69 ++++++++++++++++++++++++++++ app/page.tsx | 2 +- components/HourlyCard/HourlyCard.tsx | 3 ++ components/HourlyCard/HourlyTime.tsx | 7 +++ components/WeatherNow.tsx | 5 +- next.config.mjs | 4 +- types/types.ts | 1 + 7 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 components/HourlyCard/HourlyTime.tsx diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12a0971 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +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* ./ +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 + +# 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" + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/next-config-js/output +CMD ["node", "server.js"] \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index 4dacdaa..bda70e1 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -22,7 +22,7 @@ export default function Home() { return (
-
+
diff --git a/components/HourlyCard/HourlyCard.tsx b/components/HourlyCard/HourlyCard.tsx index 855bed6..4f1270e 100644 --- a/components/HourlyCard/HourlyCard.tsx +++ b/components/HourlyCard/HourlyCard.tsx @@ -1,14 +1,17 @@ import { HourlyCardPropType } from "@/types/types" import WeatherIcon from "./WeatherIcon" import HourlyTemp from "./HourlyTemp" +import HourlyTime from "./HourlyTime"; export default function HourlyCard(props: HourlyCardPropType) { + const time = props.time; const weatherCode = props.weatherCode const temperature = props.temperature return (
+
) }; \ No newline at end of file diff --git a/components/HourlyCard/HourlyTime.tsx b/components/HourlyCard/HourlyTime.tsx new file mode 100644 index 0000000..cd48826 --- /dev/null +++ b/components/HourlyCard/HourlyTime.tsx @@ -0,0 +1,7 @@ +import { headers } from "next/headers"; + +export default function HourlyTime(props: {time: string}) { + return( +

{props.time}

+ ) +} \ No newline at end of file diff --git a/components/WeatherNow.tsx b/components/WeatherNow.tsx index c6f9632..1395dec 100644 --- a/components/WeatherNow.tsx +++ b/components/WeatherNow.tsx @@ -35,7 +35,7 @@ export default function WeatherNow() { }; }, [geoLocation]); return ( - <> +

Here is the current weather in {geoLocation.name}

@@ -49,10 +49,11 @@ export default function WeatherNow() { key={index} temperature={temp} weatherCode={weather.hourly.weather_code[index]} + time={weather.hourly.time[index]} /> ))}
- +
); } diff --git a/next.config.mjs b/next.config.mjs index 4678774..13928e0 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: "standalone" +}; export default nextConfig; diff --git a/types/types.ts b/types/types.ts index 6db1d1c..0e1b801 100644 --- a/types/types.ts +++ b/types/types.ts @@ -217,4 +217,5 @@ export interface WeatherContextType { export interface HourlyCardPropType { temperature: number; weatherCode: number; + time: string; } \ No newline at end of file