From 48bcbf6bc521e303b3a30013cc75c89c6b855c1a Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:41:29 +0100 Subject: [PATCH] feat: add deployment stuff --- .dockerignore | 33 ++++++++++++++++++++++ .github/workflows/docker.yml | 54 ++++++++++++++++++++++++++++++++++++ Dockerfile | 44 +++++++++++++++++++++++++++++ package.json | 2 +- src/app/layout.tsx | 4 +-- 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d518964 --- /dev/null +++ b/.dockerignore @@ -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/ \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..6e6263d --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5bfe548 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/package.json b/package.json index 21fe120..792555c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "docker compose --file dev/docker-compose.yml up -d && next dev", "build": "prisma generate && next build", - "start": "next start", + "start": "prisma migrate deploy && next start", "lint": "next lint", "db:generate": "prisma generate", "db:migrate": "prisma migrate dev --name", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3083758..ce81f52 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -10,8 +10,8 @@ import { ThemeProvider } from "@/lib/providers/ThemeProvider"; const inter = Inter({ subsets: ["latin"] }); export const metadata: Metadata = { - title: "stack", - description: "The tech stack for your next(.js) project.", + title: "Echospace", + description: "User feedback for developers.", }; export default async function RootLayout({