feat: add deployment stuff

This commit is contained in:
2024-12-16 16:41:29 +01:00
parent 099c777f3b
commit 48bcbf6bc5
5 changed files with 134 additions and 3 deletions

33
.dockerignore Normal file
View File

@@ -0,0 +1,33 @@
# Ignore node_modules and build output
node_modules
.next
out
# Ignore logs and temporary files
*.log
*.tmp
*.swp
# Ignore local environment files
.env.local
.env.development.local
.env.test.local
.env.production.local
# Ignore Docker files
Dockerfile
docker-compose.yml
# Ignore git files
.git
.gitignore
# Ignore editor directories and files
.vscode
.idea
*.sublime-project
*.sublime-workspace
# Ignore other unnecessary files
README.md
dev/

54
.github/workflows/docker.yml vendored Normal file
View File

@@ -0,0 +1,54 @@
name: Publish Docker image
on:
push:
branches:
- main
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: srizan10/echospace
tags: latest
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Emit a webhook to the server
env:
AUTH_HEADER: ${{ secrets.WHSERVER_TOKEN }}
run: |
curl -X POST \
-H "Authorization: $AUTH_HEADER" \
https://webhooks.srizan.dev/hooks/echospace

44
Dockerfile Normal file
View File

@@ -0,0 +1,44 @@
# Stage 1: Building the code
FROM node:lts-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json yarn.lock ./
# Install dependencies
RUN yarn install --frozen-lockfile
# Copy app files
COPY . .
# Build app
RUN yarn build
# Stage 2: Production
FROM node:lts-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Copy necessary files
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/package.json ./
COPY --from=builder /app/yarn.lock ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/prisma ./prisma
# Install production dependencies only
RUN yarn install --frozen-lockfile --production && \
yarn cache clean
# Remove unnecessary files
RUN rm -rf /app/.git \
/app/.next/cache \
/app/README.md
EXPOSE 3000
CMD ["yarn", "start"]

View File

@@ -5,7 +5,7 @@
"scripts": { "scripts": {
"dev": "docker compose --file dev/docker-compose.yml up -d && next dev", "dev": "docker compose --file dev/docker-compose.yml up -d && next dev",
"build": "prisma generate && next build", "build": "prisma generate && next build",
"start": "next start", "start": "prisma migrate deploy && next start",
"lint": "next lint", "lint": "next lint",
"db:generate": "prisma generate", "db:generate": "prisma generate",
"db:migrate": "prisma migrate dev --name", "db:migrate": "prisma migrate dev --name",

View File

@@ -10,8 +10,8 @@ import { ThemeProvider } from "@/lib/providers/ThemeProvider";
const inter = Inter({ subsets: ["latin"] }); const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = { export const metadata: Metadata = {
title: "stack", title: "Echospace",
description: "The tech stack for your next(.js) project.", description: "User feedback for developers.",
}; };
export default async function RootLayout({ export default async function RootLayout({