Skip to content

Commit

Permalink
Add Docker support for API documentation with build and deployment co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
joao-vasconcelos committed Dec 26, 2024
1 parent bbae761 commit d2f2937
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,47 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@master
with:
push: true
context: .
file: ./apps/${{ env.MODULE_KEY }}/Dockerfile
tags: ghcr.io/carrismetropolitana/api-${{ env.MODULE_KEY }}:${{ github.ref_name }}

# # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #

api-docs:
name: docs (NextJS)
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Set module key
run: |
echo "MODULE_KEY=docs" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@main

- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Login to GitHub Container Registry
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@master
with:
Expand Down
67 changes: 67 additions & 0 deletions apps/docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# # # # # # # # #

FROM node:22.6-alpine3.20 AS base

# # # # # # # # #


# PHASE 1
# Install dependencies only when needed.

FROM base AS dependencies

RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json ./

RUN npm install --omit-dev --force \
&& npm cache clean --force


# # # # # # # # #


# PHASE 2
# Rebuild the source code only when needed.

FROM base AS builder

WORKDIR /app

COPY --from=dependencies /app/node_modules ./node_modules
COPY . .

RUN npx @helperkits/bumper bump

RUN npm run build


# # # # # # # # #


# PHASE 3
# Setup the final Docker image with only the required files.

FROM base AS runner

WORKDIR /app

ENV NODE_ENV=production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME=0.0.0.0

CMD ["node", "server.js"]
18 changes: 18 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ services:
- POSTGRES_USER=networkdbuser
- POSTGRES_PASSWORD=networkdbpassword


# # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #

docs:
image: ghcr.io/carrismetropolitana/api-docs:alpha
deploy:
restart_policy:
condition: on-failure
delay: 30s
resources:
limits:
memory: 500mb
logging:
options:
max-size: '1m'
max-file: '1'

# # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #

Expand Down

0 comments on commit d2f2937

Please sign in to comment.