Skip to content

Commit f25f85b

Browse files
committed
Deploy to hetzner
1 parent 3132153 commit f25f85b

File tree

6 files changed

+91
-18
lines changed

6 files changed

+91
-18
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
README.md
6+
.next
7+
.git

.github/workflows/deploy.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
name: Deploy to Vercel
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- master
78

8-
env:
9-
NODE_VERSION: 22
10-
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
11-
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
12-
HUSKY: 0
13-
149
concurrency:
1510
group: ${{ github.workflow }}-${{ github.ref }}
1611

1712
jobs:
1813
deploy:
1914
runs-on: ubuntu-latest
2015

16+
environment: production
17+
2118
steps:
2219
- name: Checkout repository
2320
uses: actions/checkout@v4
2421

25-
- name: Set up Node.js
26-
uses: actions/setup-node@v4
27-
with:
28-
node-version: ${{ env.NODE_VERSION }}
29-
30-
- name: Install Vercel CLI
31-
run: npm install -g vercel
32-
33-
- name: Deploy to Vercel
34-
run: vercel deploy --no-wait --prod --token=${{ secrets.VERCEL_TOKEN }}
22+
- name: Setup docker
23+
uses: docker/setup-docker-action@v4
24+
25+
- name: Configure SSH
26+
run: |
27+
mkdir -p ~/.ssh
28+
chmod 700 ~/.ssh
29+
echo "${{ secrets.HETZNER_HOST_SSH_KEY }}" > ~/.ssh/id_rsa
30+
chmod 600 ~/.ssh/id_rsa
31+
ssh-keyscan -H ${{ secrets.HETZNER_HOST }} >> ~/.ssh/known_hosts
32+
chmod 644 ~/.ssh/known_hosts
33+
34+
- name: Deploy
35+
run: docker compose up --build -d --remove-orphans
36+
env:
37+
DOCKER_HOST: ssh://${{ secrets.REMOTE_DOCKER_HOST }}
38+
COMPOSE_BAKE: true

Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# syntax=docker.io/docker/dockerfile:1
2+
3+
FROM node:22-alpine AS base
4+
5+
# Install dependencies only when needed
6+
FROM base AS deps
7+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8+
RUN apk add --no-cache libc6-compat
9+
WORKDIR /app
10+
11+
# Install dependencies based on the preferred package manager
12+
COPY package.json package-lock.json* .npmrc* source.config.ts ./
13+
RUN npm ci
14+
15+
# Rebuild the source code only when needed
16+
FROM base AS builder
17+
WORKDIR /app
18+
COPY --from=deps /app/node_modules ./node_modules
19+
COPY . .
20+
21+
# Next.js collects completely anonymous telemetry data about general usage.
22+
# Learn more here: https://nextjs.org/telemetry
23+
# Uncomment the following line in case you want to disable telemetry during the build.
24+
ENV NEXT_TELEMETRY_DISABLED=1
25+
26+
RUN npm run genapi
27+
# Build the Next.js app
28+
RUN npm run build
29+
30+
# Production image, copy all the files and run next
31+
FROM base AS runner
32+
WORKDIR /app
33+
34+
ENV NODE_ENV=production
35+
ENV NEXT_TELEMETRY_DISABLED=1
36+
37+
RUN addgroup --system --gid 1001 nodejs
38+
RUN adduser --system --uid 1001 nextjs
39+
40+
COPY --from=builder /app/public ./public
41+
42+
# Automatically leverage output traces to reduce image size
43+
# https://nextjs.org/docs/advanced-features/output-file-tracing
44+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
45+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
46+
47+
USER nextjs
48+
49+
EXPOSE 3500
50+
51+
ENV PORT=3500
52+
53+
# server.js is created by next build from the standalone output
54+
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
55+
ENV HOSTNAME="0.0.0.0"
56+
CMD ["node", "server.js"]

compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
docs:
3+
build: .
4+
ports:
5+
- 3500:3500

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config = {
77
reactStrictMode: true,
88
basePath: '/docs',
99
assetPrefix: '/docs-static',
10+
output: 'standalone',
1011
async redirects() {
1112
return [
1213
{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"genapi": "node ./scripts/generate-docs.js",
77
"prebuild": "npm run genapi",
88
"build": "next build",
9-
"dev": "rm -rf .next && next dev --turbopack --port 7575",
9+
"dev": "rm -rf .next && next dev --turbopack --port 3500",
1010
"start": "next start",
1111
"postinstall": "fumadocs-mdx",
12-
"prepare": "husky && npm run genapi"
12+
"prepare": "husky"
1313
},
1414
"dependencies": {
1515
"fast-glob": "^3.3.3",

0 commit comments

Comments
 (0)