add Dockerfile

This commit is contained in:
Dawid Wysokiński 2021-04-14 20:11:35 +02:00
parent d45481d5fa
commit 69c0977640
5 changed files with 52 additions and 9 deletions

37
Dockerfile Normal file
View File

@ -0,0 +1,37 @@
# Install dependencies only when needed
FROM node:alpine 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
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ENV BUILDING_PROCESS true
RUN yarn build
# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV BUILDING_PROCESS false
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY .env .env.production ./
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
RUN chown -R nextjs:nodejs /app/.next
USER nextjs
EXPOSE 3000
CMD ["yarn", "start"]

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://zdamegzaminzawodowy.pl</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-04-13T15:59:54.800Z</lastmod></url>
<url><loc>https://zdamegzaminzawodowy.pl/polityka-prywatnosci</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-04-13T15:59:54.800Z</lastmod></url>
<url><loc>https://zdamegzaminzawodowy.pl</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-04-14T17:52:07.298Z</lastmod></url>
<url><loc>https://zdamegzaminzawodowy.pl/polityka-prywatnosci</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-04-14T17:52:07.298Z</lastmod></url>
</urlset>

View File

@ -55,6 +55,8 @@ const getQualificationsFromProfessions = (
return Array.from(map.values());
};
export const REVALIDATE = 60;
export const getStaticProps: GetStaticProps = async () => {
const pageProps: IndexPageProps = {
professions: [],
@ -78,7 +80,7 @@ export const getStaticProps: GetStaticProps = async () => {
return {
props: pageProps,
revalidate: 60,
revalidate: REVALIDATE,
};
};

View File

@ -53,6 +53,10 @@ export const getStaticPaths: GetStaticPaths = async () => {
};
};
const SUGGESTIONS_LIMIT = 6;
const REVALIDATE_ERROR = 600;
const REVALIDATE_SUCCESS = 10;
export const getStaticProps: GetStaticProps<
TestPageProps,
TestPageParams
@ -69,7 +73,7 @@ export const getStaticProps: GetStaticProps<
},
};
if (!params) return { notFound: true, revalidate: 600 };
if (!params) return { notFound: true, revalidate: REVALIDATE_ERROR };
const limit = parseInt(params.limit);
const slug = params.slug.trim();
if (
@ -84,7 +88,7 @@ export const getStaticProps: GetStaticProps<
query: { ...params, limit: QUESTIONS[QUESTIONS.length - 1] },
}),
},
revalidate: 600,
revalidate: REVALIDATE_ERROR,
};
}
@ -102,7 +106,7 @@ export const getStaticProps: GetStaticProps<
Pick<Query, 'generateTest' | 'similarQualifications'>,
QueryGenerateTestSimilarQualificationsArgs
>(QUERY_GENERATE_TEST_SIMILAR_QUALIFICATIONS, {
limitSuggestions: 6,
limitSuggestions: SUGGESTIONS_LIMIT,
qualificationID: qualification.id,
limitTest: limit,
skipSuggestions: false,
@ -115,10 +119,10 @@ export const getStaticProps: GetStaticProps<
}
return {
props,
revalidate: 20,
revalidate: REVALIDATE_SUCCESS,
};
} catch (e) {
return { notFound: true, revalidate: 600 };
return { notFound: true, revalidate: REVALIDATE_ERROR };
}
};

View File

@ -2,7 +2,7 @@ import { GraphQLClient } from 'graphql-request';
const getApiURI = () => {
return (
(typeof window === 'undefined'
(typeof window === 'undefined' && process.env.BUILDING_PROCESS !== 'true'
? process.env.SERVER_API_URI
: process.env.NEXT_PUBLIC_API_URI) ?? 'http://localhost:8080/graphql'
);