Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.next
.git
.github
*.md
.env*
.DS_Store
69 changes: 69 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -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.2.2

- name: Login a GHCR
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@v6
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 }}
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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", "server.js"]
2 changes: 1 addition & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextConfig } from "next"

const nextConfig: NextConfig = {
output: "export",
output: "standalone",
}

export default nextConfig
Loading