trying to get nextjs to work
This commit is contained in:
parent
78b57dc4ad
commit
3ac968a63c
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
||||
.git/
|
||||
.next/
|
||||
node_modules/
|
||||
posts/
|
||||
.env/
|
||||
|
4
.drone.yml
Normal file
4
.drone.yml
Normal file
@ -0,0 +1,4 @@
|
||||
kind: template
|
||||
load: bust_docker_template.yaml
|
||||
name: microblog
|
||||
data: {}
|
57
Dockerfile
Normal file
57
Dockerfile
Normal file
@ -0,0 +1,57 @@
|
||||
FROM harbor.server.kjuulh.io/kjuulh/git-log:1667748666021 as git-log
|
||||
|
||||
FROM harbor.server.kjuulh.io/docker-proxy/library/node:16-alpine AS deps
|
||||
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
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 yarn global add pnpm && pnpm i --frozen-lockfile; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM harbor.server.kjuulh.io/docker-proxy/library/node:16-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
RUN yarn tailwind
|
||||
|
||||
RUN yarn build
|
||||
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM harbor.server.kjuulh.io/docker-proxy/library/node:16-alpine AS runner
|
||||
|
||||
RUN apk add git
|
||||
|
||||
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=git-log --chown=nextjs:nodejs /usr/bin/git-log /usr/bin/git-log
|
||||
|
||||
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"]
|
@ -1,14 +1,9 @@
|
||||
import { getPosts } from '@/lib/getPosts';
|
||||
import Posts from './posts';
|
||||
|
||||
export const revalidate = 10;
|
||||
|
||||
export default async function Page() {
|
||||
const posts = await getPosts();
|
||||
|
||||
return (
|
||||
<div className="space-y-6 pt-6">
|
||||
<Posts posts={posts} />
|
||||
<Posts />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
const PostCard = () => {
|
||||
return <div></div>;
|
||||
};
|
||||
|
||||
export default PostCard;
|
@ -1,14 +1,14 @@
|
||||
'use client-only';
|
||||
|
||||
import { Post } from '@/lib/getPosts';
|
||||
import { FC } from 'react';
|
||||
import { getPosts } from '@/lib/getPosts';
|
||||
import { cookies } from 'next/headers';
|
||||
import { use } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
|
||||
interface PostProps {
|
||||
posts: Post[];
|
||||
}
|
||||
const Posts: FC<PostProps> = ({ posts }) => {
|
||||
const Posts = () => {
|
||||
const c = cookies();
|
||||
|
||||
const posts = use(getPosts());
|
||||
|
||||
return (
|
||||
<>
|
||||
{posts.map((p) => (
|
||||
|
@ -12,23 +12,6 @@ export type Post = {
|
||||
};
|
||||
|
||||
export const getPosts = cache(async (): Promise<Post[]> => {
|
||||
await updatePosts();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`git-log --path ${process.env.POSTS_DIR}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
reject('could not load posts stderr: ' + stderr + 'stdout: ' + stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
const posts: Post[] = JSON.parse(stdout);
|
||||
|
||||
resolve(posts);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const updatePosts = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(
|
||||
@ -47,3 +30,20 @@ const updatePosts = async () => {
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
await updatePosts();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`git-log --path ${process.env.POSTS_DIR}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
reject('could not load posts stderr: ' + stderr + 'stdout: ' + stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
const posts: Post[] = JSON.parse(stdout);
|
||||
|
||||
resolve(posts);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,7 @@
|
||||
const nextConfig = {
|
||||
reactStrictMode: true, // Recommended for the `pages` directory, default in `app`.
|
||||
swcMinify: true,
|
||||
output: 'standalone',
|
||||
experimental: {
|
||||
// Required:
|
||||
appDir: true,
|
||||
|
@ -7,8 +7,7 @@
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"tailwind": "tailwindcss -i styles/globals.css -o styles/dist.css",
|
||||
"format": "prettier --write \"**/*.{js,ts,tsx,md}\"",
|
||||
"postinstall": "npm run tailwind"
|
||||
"format": "prettier --write \"**/*.{js,ts,tsx,md}\""
|
||||
},
|
||||
"prettier": {
|
||||
"arrowParens": "always",
|
||||
@ -24,6 +23,7 @@
|
||||
"react-dom": "18.2.0",
|
||||
"react-markdown": "8.0.3",
|
||||
"remark-gfm": "3.0.1",
|
||||
"server-only": "0.0.1",
|
||||
"styled-components": "6.0.0-beta.2",
|
||||
"styled-jsx": "5.1.0",
|
||||
"use-count-up": "3.0.1"
|
||||
|
@ -3636,6 +3636,11 @@ semver@^7.3.7:
|
||||
dependencies:
|
||||
lru-cache "^6.0.0"
|
||||
|
||||
server-only@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/server-only/-/server-only-0.0.1.tgz#0f366bb6afb618c37c9255a314535dc412cd1c9e"
|
||||
integrity sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==
|
||||
|
||||
shallowequal@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
|
||||
|
Loading…
Reference in New Issue
Block a user