diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..d5ccd95
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,6 @@
+.git/
+.next/
+node_modules/
+posts/
+.env/
+
diff --git a/.drone.yml b/.drone.yml
new file mode 100644
index 0000000..5de4c2e
--- /dev/null
+++ b/.drone.yml
@@ -0,0 +1,4 @@
+kind: template
+load: bust_docker_template.yaml
+name: microblog
+data: {}
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..0d66bd7
--- /dev/null
+++ b/Dockerfile
@@ -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"]
diff --git a/app/page.tsx b/app/page.tsx
index f156029..1e0e06e 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -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 (
);
}
diff --git a/app/postCard.tsx b/app/postCard.tsx
deleted file mode 100644
index 835c0bf..0000000
--- a/app/postCard.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-const PostCard = () => {
- return ;
-};
-
-export default PostCard;
diff --git a/app/posts.tsx b/app/posts.tsx
index f5e23e6..5f3bba3 100644
--- a/app/posts.tsx
+++ b/app/posts.tsx
@@ -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 = ({ posts }) => {
+const Posts = () => {
+ const c = cookies();
+
+ const posts = use(getPosts());
+
return (
<>
{posts.map((p) => (
diff --git a/lib/getPosts.tsx b/lib/getPosts.tsx
index cf215c4..8a2d78a 100644
--- a/lib/getPosts.tsx
+++ b/lib/getPosts.tsx
@@ -12,6 +12,25 @@ export type Post = {
};
export const getPosts = cache(async (): Promise => {
+ const updatePosts = async () => {
+ return new Promise((resolve, reject) => {
+ exec(
+ `(cd ${process.env.POSTS_DIR}; git pull --rebase)`,
+ (error, stdout, stderr) => {
+ if (error) {
+ console.warn(error);
+ reject(
+ 'could not update posts stderr: ' + stderr + 'stdout: ' + stdout,
+ );
+ return;
+ }
+
+ resolve(true);
+ },
+ );
+ });
+ };
+
await updatePosts();
return new Promise((resolve, reject) => {
@@ -28,22 +47,3 @@ export const getPosts = cache(async (): Promise => {
});
});
});
-
-const updatePosts = async () => {
- return new Promise((resolve, reject) => {
- exec(
- `(cd ${process.env.POSTS_DIR}; git pull --rebase)`,
- (error, stdout, stderr) => {
- if (error) {
- console.warn(error);
- reject(
- 'could not update posts stderr: ' + stderr + 'stdout: ' + stdout,
- );
- return;
- }
-
- resolve(true);
- },
- );
- });
-};
diff --git a/next.config.js b/next.config.js
index 593a397..92e3ca9 100755
--- a/next.config.js
+++ b/next.config.js
@@ -2,6 +2,7 @@
const nextConfig = {
reactStrictMode: true, // Recommended for the `pages` directory, default in `app`.
swcMinify: true,
+ output: 'standalone',
experimental: {
// Required:
appDir: true,
diff --git a/package.json b/package.json
index 605b1a6..2a184e9 100644
--- a/package.json
+++ b/package.json
@@ -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"
diff --git a/yarn.lock b/yarn.lock
index cdb52a9..7c29255 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -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"