Skip to content

Commit

Permalink
Merge pull request #112 from serafuku/docker-ci
Browse files Browse the repository at this point in the history
👷 Docker github action
  • Loading branch information
Squarecat-meow authored Dec 18, 2024
2 parents 790bb8b + 9c648a9 commit 29cea38
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

.git
.gitignore
.github
Dockerfile
local_db_data
local_redis_data
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and push docker image

on:
workflow_dispatch:
push:
branches:
- 'main'
- 'develop'
tags:
- 'v**'
release:
types: [published, released, edited]
pull_request:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64
cache-from: type=registry,ref=${{env.REGISTRY}}/${{env.IMAGE_NAME}}:build-cache
cache-to: type=registry,ref=${{env.REGISTRY}}/${{env.IMAGE_NAME}}:build-cache,mode=max,image-manifest=true,oci-mediatypes=true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
RUN npm ci


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY --link --from=deps /app/node_modules ./node_modules
COPY --link . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED=1
ENV NEXT_TELEMETRY_DISABLED=1

RUN npx prisma generate
RUN npm run build
Expand All @@ -41,14 +40,14 @@ RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs


COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
COPY --chown=nextjs:nodejs package.json .
COPY --chown=nextjs:nodejs package-lock.json .
COPY --chown=nextjs:nodejs prisma ./prisma
COPY --chown=nextjs:nodejs paths-bootstrap.js .
COPY --link --from=builder --chown=1001:1001 /app/public ./public
COPY --link --from=builder --chown=1001:1001 /app/node_modules ./node_modules
COPY --link --from=builder --chown=1001:1001 /app/.next ./.next
COPY --link --from=builder --chown=1001:1001 /app/dist ./dist
COPY --link --from=builder --chown=1001:1001 /app/package.json .
COPY --link --from=builder --chown=1001:1001 /app/package-lock.json .
COPY --link --from=builder --chown=1001:1001 /app/prisma ./prisma
COPY --link --from=builder --chown=1001:1001 /app/paths-bootstrap.js .

USER nextjs

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ cp config/docker.env.example config/docker.env
# copy example compose file
cp docker-compose-example.yml docker-compose.yml

# docker image version config
# Set it to latest, or specific version like v1.3.4
echo 'NEO_QUESDON_VERSION=v1.3.4' > .env

# Edit config file
vim config/docker.env

# Compose build
docker compose build
# Compose pull
docker compose pull

# Deploy
docker compose up -d
Expand Down
7 changes: 4 additions & 3 deletions docker-compose-example.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
image: ghcr.io/serafuku/neo-quesdon:${NEO_QUESDON_VERSION:-latest}
# build:
# context: .
# dockerfile: Dockerfile
depends_on:
- db
- redis
Expand Down

0 comments on commit 29cea38

Please sign in to comment.