Skip to content

Commit f035cba

Browse files
committed
2025.02.19 dockerfile
1 parent 489dc71 commit f035cba

File tree

7 files changed

+145
-7
lines changed

7 files changed

+145
-7
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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Deploy ui
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
jobs:
7+
build_and_deploy:
8+
if: github.actor == 'maslianok'
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
attestations: write
14+
id-token: write
15+
steps:
16+
# 1. Check out the code
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
20+
# 2. Set up Node (v18) and install pnpm
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '22'
25+
26+
- name: Install pnpm
27+
run: |
28+
npm install -g corepack@latest
29+
corepack enable
30+
corepack prepare pnpm@10 --activate
31+
32+
# 4. Log in to Docker Hub
33+
- name: Log in to Docker Hub
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Build and push Docker image
41+
uses: docker/build-push-action@v6
42+
with:
43+
file: ./Dockerfile
44+
push: true
45+
tags: ghcr.io/maslianok/gitranks-ui:latest
46+
build-args: |
47+
EXAMPLE_BUILD_VAR=aaa
48+
49+
# 4. SSH to droplet and deploy
50+
- name: SSH to droplet and deploy
51+
uses: appleboy/[email protected]
52+
with:
53+
host: ${{ vars.DO_IP }}
54+
username: root
55+
key: ${{ secrets.SSH_PRIVATE_KEY }}
56+
script: |
57+
echo ${{ secrets.GHCR_PAT }} | docker login ghcr.io -u maslianok --password-stdin
58+
59+
docker pull ghcr.io/maslianok/gitranks-ui:latest
60+
61+
docker stop gitranks-ui || true
62+
docker rm gitranks-ui || true
63+
64+
docker run -d \
65+
--restart=always \
66+
--name gitranks-ui \
67+
-e MONGODB_URI_AUTH='${{ secrets.MONGODB_URI_AUTH }}' \
68+
-e GRAPHQL_URI='${{ secrets.GRAPHQL_URI }}' \
69+
-e AUTH_SECRET='${{ secrets.AUTH_SECRET }}' \
70+
-e AUTH_GITHUB_SECRET='${{ secrets.AUTH_GITHUB_SECRET }}' \
71+
-e GRAPHQL_SECRET_KEY='${{ secrets.GRAPHQL_SECRET_KEY }}' \
72+
-e AUTH_GITHUB_ID='${{ vars.AUTH_GITHUB_ID }}' \
73+
-e URI='${{ vars.URI }}' \
74+
-e AUTH_TRUST_HOST=true \
75+
-p 3000:3000 \
76+
ghcr.io/maslianok/gitranks-ui:latest

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM node:22-alpine AS base
2+
3+
FROM base AS deps
4+
RUN apk update && apk add --no-cache libc6-compat
5+
WORKDIR /app
6+
COPY package.json pnpm-lock.yaml ./
7+
RUN npm install -g corepack@latest
8+
RUN corepack enable && corepack prepare pnpm@10 --activate
9+
RUN pnpm i --frozen-lockfile
10+
11+
FROM base AS builder
12+
WORKDIR /app
13+
COPY --from=deps /app/node_modules ./node_modules
14+
COPY . .
15+
RUN npm install -g corepack@latest
16+
RUN corepack enable && corepack prepare pnpm@10 --activate
17+
RUN pnpm build
18+
19+
FROM base AS runner
20+
WORKDIR /app
21+
ENV NODE_ENV production
22+
RUN addgroup --system --gid 1001 nodejs
23+
RUN adduser --system --uid 1001 nextjs
24+
COPY --from=builder /app/public ./public
25+
26+
# Set the correct permission for prerender cache
27+
RUN mkdir .next
28+
RUN chown nextjs:nodejs .next
29+
30+
# Automatically leverage output traces to reduce image size
31+
# https://nextjs.org/docs/advanced-features/output-file-tracing
32+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
33+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
34+
35+
USER nextjs
36+
37+
EXPOSE 3000
38+
39+
ENV PORT 3000
40+
ENV HOSTNAME "0.0.0.0"
41+
42+
CMD ["node", "server.js"]

app/page.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SigninButton from '@/components/signin-button/signin-button';
2+
import Link from 'next/link';
23

34
export default function Home() {
45
return (
@@ -7,15 +8,18 @@ export default function Home() {
78
<h1 className="text-6xl">GitRanks</h1>
89

910
<div className="flex gap-4 items-center flex-col sm:flex-row">
10-
<a className="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/by/owned-stars">
11+
<Link className="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/by/owned-stars">
1112
by owned stars
12-
</a>
13-
<a className="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/by/contributed-stars">
13+
</Link>
14+
<Link
15+
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
16+
href="/by/contributed-stars"
17+
>
1418
by contributed stars
15-
</a>
16-
<a className="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/by/followers">
19+
</Link>
20+
<Link className="flex items-center gap-2 hover:underline hover:underline-offset-4" href="/by/followers">
1721
by followers
18-
</a>
22+
</Link>
1923
</div>
2024
</main>
2125
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
nextapp:
3+
container_name: nextapp
4+
image: nextapp
5+
build: .
6+
ports:
7+
- '3000:3000'

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { NextConfig } from 'next';
22

33
const nextConfig: NextConfig = {
4+
output: 'standalone',
45
images: {
56
remotePatterns: [
67
{

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"codegen": "dotenv -e .env.local graphql-codegen"
10+
"codegen": "dotenv -e .env.local graphql-codegen",
11+
"standalone": "dotenv -e .env.local node .next/standalone/server.js"
1112
},
1213
"dependencies": {
1314
"@auth/mongodb-adapter": "^3.7.4",

0 commit comments

Comments
 (0)