Skip to content

Commit da8648d

Browse files
feat: deploy to digital ocean (#195)
1 parent 8e583c2 commit da8648d

File tree

5 files changed

+149
-3
lines changed

5 files changed

+149
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
permissions:
7+
packages: write
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout master
14+
uses: actions/checkout@v3
15+
16+
- name: Install doctl
17+
uses: digitalocean/action-doctl@v2
18+
with:
19+
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
20+
21+
- name: Log in to the Container registry
22+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
23+
with:
24+
registry: https://ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v6
30+
with:
31+
push: true
32+
tags: ghcr.io/apollorion/manifestsio:$(echo $GITHUB_SHA | head -c7)
33+
34+
- name: Update deployment file
35+
run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|<IMAGE>|ghcr.io/apollorion/manifestsio:'${TAG}'|' deployment.yaml
36+
37+
- name: Log in to DigitalOcean
38+
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 1200 ${{ secrets.DIGITALOCEAN_CLUSTER_ID }}
39+
40+
- name: Deploy to DigitalOcean Kubernetes
41+
run: kubectl apply -f deployment.yaml
42+
43+
- name: Verify deployment
44+
run: kubectl -n manifestsio rollout status deployment/manifestsio

Dockerfile

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

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# Manifests.io
22

3-
[![Netlify Status](https://api.netlify.com/api/v1/badges/99772608-03b1-45d2-a943-8ee47bb82a8c/deploy-status)](https://app.netlify.com/sites/manifestsio/deploys)
4-
53
Easy to use online kubernetes documentation.
64

75
## Important URLS
86
- Production: www.manifests.io
97

10-
118
## Devving this repo
129
1. clone this repository
1310
2. `cd manifests.io`

deployment.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: manifestsio
5+
---
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
name: manifestsio
10+
namespace: manifestsio
11+
spec:
12+
replicas: 2
13+
selector:
14+
matchLabels:
15+
app: manifestsio
16+
template:
17+
metadata:
18+
labels:
19+
app: manifestsio
20+
spec:
21+
containers:
22+
- name: manifestsio
23+
image: <IMAGE>
24+
ports:
25+
- containerPort: 3000
26+
---
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: manifestsio
31+
namespace: manifestsio
32+
spec:
33+
type: ClusterIP
34+
ports:
35+
- name: http
36+
protocol: TCP
37+
port: 3000
38+
targetPort: 3000
39+
selector:
40+
app: manifestsio

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
output: "standalone",
34
reactStrictMode: true,
45
headers: async () => {
56
return [

0 commit comments

Comments
 (0)