From 10c9123aad6bc2e7edfefcdef611ab4d99f747ef Mon Sep 17 00:00:00 2001 From: BrandonLeiva Date: Tue, 21 Apr 2026 17:08:36 -0400 Subject: [PATCH 1/3] feat: add deployment pipeline --- .dockerignore | 7 ++++ .github/workflow/deploy.yaml | 69 ++++++++++++++++++++++++++++++++++++ Dockerfile | 14 ++++++++ next.config.ts | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflow/deploy.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e8f8b65 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.next +.git +.github +*.md +.env* +.DS_Store \ No newline at end of file diff --git a/.github/workflow/deploy.yaml b/.github/workflow/deploy.yaml new file mode 100644 index 0000000..ba67c00 --- /dev/null +++ b/.github/workflow/deploy.yaml @@ -0,0 +1,69 @@ +name: CI/CD Bennu Code + +on: + push: + branches: + - feat/ci-cd + +env: + GIT_USERNAME: ${{ github.actor }} + GIT_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + IMAGE_TAG: latest + DOCKERFILE: ${{ secrets.DOCKERFILE || './Dockerfile' }} + IMAGE_NAME: ghcr.io/${{ github.repository }} + IMAGE_REGISTRY_URL: ${{ secrets.IMAGE_REGISTRY_URL || 'https://ghcr.io' }} + IMAGE_REGISTRY_USER: ${{ secrets.IMAGE_REGISTRY_USER || github.actor }} + IMAGE_REGISTRY_PASSWORD: ${{ secrets.IMAGE_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }} + +jobs: + build-and-push: + name: Build & Push Docker Image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout código + uses: actions/checkout@v4 + + - name: Login a GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.IMAGE_REGISTRY_URL }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + - name: Build & Push imagen + uses: docker/build-push-action@v5 + with: + context: . + file: ${{ env.DOCKERFILE }} + push: true + tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + deploy: + name: Deploy en EC2 + runs-on: ubuntu-latest + needs: build-and-push + + steps: + - name: Deploy via SSH + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin + + docker pull ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + docker stop bennu-code || true + docker rm bennu-code || true + + docker run -d \ + --name bennu-code \ + --restart always \ + -p 3000:3000 \ + ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5a18b0f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:20-alpine + +RUN npm install -g pnpm + +WORKDIR /app + +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +COPY . . +RUN pnpm build + +EXPOSE 3000 +CMD ["node", ".next/standalone/server.js"] \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 24e7a37..8919db6 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next" const nextConfig: NextConfig = { - output: "export", + output: "standalone", } export default nextConfig From 1dbca9f2fa3c57e114e65baa9e077ae26a180874 Mon Sep 17 00:00:00 2001 From: BrandonLeiva Date: Tue, 21 Apr 2026 17:13:42 -0400 Subject: [PATCH 2/3] fix: correct workflows route --- .github/{workflow => workflows}/deploy.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/deploy.yaml (100%) diff --git a/.github/workflow/deploy.yaml b/.github/workflows/deploy.yaml similarity index 100% rename from .github/workflow/deploy.yaml rename to .github/workflows/deploy.yaml From e5d86f3333b8a457be2dcf4588161d21dadb781f Mon Sep 17 00:00:00 2001 From: BrandonLeiva Date: Tue, 21 Apr 2026 18:03:46 -0400 Subject: [PATCH 3/3] fix: version actions/checkout --- .github/workflows/deploy.yaml | 6 ++--- Dockerfile | 42 ++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index ba67c00..7dfb766 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -25,17 +25,17 @@ jobs: steps: - name: Checkout código - uses: actions/checkout@v4 + uses: actions/checkout@v4.2.2 - name: Login a GHCR - uses: docker/login-action@v3 + uses: docker/login-action@v3.4.0 with: registry: ${{ env.IMAGE_REGISTRY_URL }} username: ${{ env.IMAGE_REGISTRY_USER }} password: ${{ env.IMAGE_REGISTRY_PASSWORD }} - name: Build & Push imagen - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ${{ env.DOCKERFILE }} diff --git a/Dockerfile b/Dockerfile index 5a18b0f..fd70a4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,40 @@ -FROM node:20-alpine - -RUN npm install -g pnpm - +FROM node:24-alpine3.22 AS deps + +RUN apk add --no-cache libc6-compat WORKDIR /app - + +RUN npm install -g pnpm + COPY package.json pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile - + + +FROM node:24-alpine3.22 AS builder +WORKDIR /app + +RUN npm install -g pnpm + +COPY --from=deps /app/node_modules ./node_modules COPY . . + RUN pnpm build - +RUN cp -r .next/static .next/standalone/.next/static + + +FROM node:24-alpine3.22 AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV PORT=3000 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + EXPOSE 3000 -CMD ["node", ".next/standalone/server.js"] \ No newline at end of file + +CMD ["node", "server.js"] \ No newline at end of file