Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Aug 3, 2024
2 parents 8c97ea9 + 8004367 commit 7f58771
Show file tree
Hide file tree
Showing 15 changed files with 473 additions and 146 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ node_modules
npm-debug.log
.next
.git
scripts
docs
.github
*.md
Expand Down
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
- [ ] 🐛 fix
- [ ] ♻️ refactor
- [ ] 💄 style
- [ ] 🔨 chore
- [ ] 👷 build
- [ ] ⚡️ perf
- [ ] 📝 docs
- [ ] 🔨 chore

#### 🔀 变更说明 | Description of Change

Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/docker-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Database Docker Image

on:
workflow_dispatch:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: lobehub/lobe-chat-database
tags: |
type=raw,value=latest
type=ref,event=tag
- 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 Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.database # 指定使用 Dockerfile.database 文件
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
61 changes: 54 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
## Base image for all the stages
FROM node:20-alpine AS base

ARG USE_CN_MIRROR

RUN \
# If you want to build docker in China, build with --build-arg USE_CN_MIRROR=true
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
sed -i "s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g" "/etc/apk/repositories"; \
fi \
# Add proxychains-ng package & update base package
&& apk update \
&& apk add --no-cache proxychains-ng \
&& apk upgrade --no-cache \
# Add user nextjs to run the app
addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
&& addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs \
&& chown -R nextjs:nodejs "/etc/proxychains" \
&& rm -rf /tmp/* /var/cache/apk/*

## Builder image, install all the dependencies and build the app
FROM base AS builder

ARG USE_NPM_CN_MIRROR
ARG USE_CN_MIRROR

ENV NEXT_PUBLIC_BASE_PATH=""

Expand Down Expand Up @@ -60,8 +72,8 @@ COPY package.json ./
COPY .npmrc ./

RUN \
# If you want to build docker in China, build with --build-arg USE_NPM_CN_MIRROR=true
if [ "${USE_NPM_CN_MIRROR:-false}" = "true" ]; then \
# If you want to build docker in China, build with --build-arg USE_CN_MIRROR=true
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \
npm config set registry "https://registry.npmmirror.com/"; \
fi \
Expand Down Expand Up @@ -108,7 +120,10 @@ ENV HOSTNAME="0.0.0.0" \
# General Variables
ENV ACCESS_CODE="" \
API_KEY_SELECT_MODE="" \
FEATURE_FLAGS=""
DEFAULT_AGENT_CONFIG="" \
SYSTEM_AGENT="" \
FEATURE_FLAGS="" \
PROXY_URL=""

# Model Variables
ENV \
Expand Down Expand Up @@ -161,4 +176,36 @@ USER nextjs

EXPOSE 3210/tcp

CMD ["node", "/app/server.js"]
CMD \
if [ -n "$PROXY_URL" ]; then \
# Set regex for IPv4
IP_REGEX="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$"; \
# Set proxychains command
PROXYCHAINS="proxychains -q"; \
# Parse the proxy URL
host_with_port="${PROXY_URL#*//}"; \
host="${host_with_port%%:*}"; \
port="${PROXY_URL##*:}"; \
protocol="${PROXY_URL%%://*}"; \
# Resolve to IP address if the host is a domain
if ! [[ "$host" =~ "$IP_REGEX" ]]; then \
nslookup=$(nslookup -q="A" "$host" | tail -n +3 | grep 'Address:'); \
if [ -n "$nslookup" ]; then \
host=$(echo "$nslookup" | tail -n 1 | awk '{print $2}'); \
fi; \
fi; \
# Generate proxychains configuration file
printf "%s\n" \
'localnet 127.0.0.0/255.0.0.0' \
'localnet ::1/128' \
'proxy_dns' \
'remote_dns_subnet 224' \
'strict_chain' \
'tcp_connect_time_out 8000' \
'tcp_read_time_out 15000' \
'[ProxyList]' \
"$protocol $host $port" \
> "/etc/proxychains/proxychains.conf"; \
fi; \
# Run the server
${PROXYCHAINS} node "/app/server.js";
170 changes: 170 additions & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
## Base image for all the stages
FROM node:20-alpine AS base

RUN \
# Add user nextjs to run the app
addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs

## Builder image, install all the dependencies and build the app
FROM base AS builder

ARG USE_NPM_CN_MIRROR

ENV KEY_VAULTS_SECRET="use-for-build" \
NEXT_PUBLIC_SERVICE_MODE="server" \
DATABASE_DRIVER="node" \
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres"

# Sentry
ENV NEXT_PUBLIC_SENTRY_DSN="" \
SENTRY_ORG="" \
SENTRY_PROJECT=""

# Posthog
ENV NEXT_PUBLIC_ANALYTICS_POSTHOG="" \
NEXT_PUBLIC_POSTHOG_HOST="" \
NEXT_PUBLIC_POSTHOG_KEY=""

# Umami
ENV NEXT_PUBLIC_ANALYTICS_UMAMI="" \
NEXT_PUBLIC_UMAMI_SCRIPT_URL="" \
NEXT_PUBLIC_UMAMI_WEBSITE_ID=""

# Node
ENV NODE_OPTIONS="--max-old-space-size=8192"

WORKDIR /app

COPY package.json ./
COPY .npmrc ./

RUN \
# If you want to build docker in China, build with --build-arg USE_NPM_CN_MIRROR=true
if [ "${USE_NPM_CN_MIRROR:-false}" = "true" ]; then \
export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \
npm config set registry "https://registry.npmmirror.com/"; \
fi \
# Set the registry for corepack
&& export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') \
# Enable corepack
&& corepack enable \
# Use pnpm for corepack
&& corepack use pnpm \
# Install the dependencies
&& pnpm i \
# Add sharp and db migration dependencies
&& mkdir -p /deps \
&& pnpm add sharp pg drizzle-orm --prefix /deps

COPY . .

# run build standalone for docker version
RUN npm run build:docker

## Application image, copy all the files for production
FROM scratch AS app

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

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /app/.next/standalone /app/
COPY --from=builder /app/.next/static /app/.next/static

# copy dependencies
COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm
COPY --from=builder /deps/node_modules/pg /app/node_modules/pg
COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm

# Copy database migrations
COPY --from=builder /app/src/database/server/migrations /app/migrations
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs

## Production image, copy all the files and run next
FROM base

# Copy all the files from app, set the correct permission for prerender cache
COPY --from=app --chown=nextjs:nodejs /app /app

ENV NODE_ENV="production"

# set hostname to localhost
ENV HOSTNAME="0.0.0.0" \
PORT="3210"

# General Variables
ENV API_KEY_SELECT_MODE="" \
FEATURE_FLAGS=""

# Database
ENV KEY_VAULTS_SECRET="" \
DATABASE_DRIVER="node" \
DATABASE_URL=""

# Next Auth
ENV NEXT_AUTH_SECRET="" \
ACCESS_CODE="" \
NEXTAUTH_URL="" \
NEXT_AUTH_SSO_PROVIDERS=""

# S3
ENV S3_ACCESS_KEY_ID="" \
S3_SECRET_ACCESS_KEY="" \
NEXT_PUBLIC_S3_DOMAIN="" \
S3_ENDPOINT="" \
S3_BUCKET=""

# Model Variables
ENV \
# Ai360
AI360_API_KEY="" \
# Anthropic
ANTHROPIC_API_KEY="" ANTHROPIC_PROXY_URL="" \
# Amazon Bedrock
AWS_ACCESS_KEY_ID="" AWS_SECRET_ACCESS_KEY="" AWS_REGION="" \
# Azure OpenAI
AZURE_API_KEY="" AZURE_API_VERSION="" AZURE_ENDPOINT="" AZURE_MODEL_LIST="" \
# Baichuan
BAICHUAN_API_KEY="" \
# DeepSeek
DEEPSEEK_API_KEY="" \
# Google
GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
# Groq
GROQ_API_KEY="" GROQ_PROXY_URL="" \
# Minimax
MINIMAX_API_KEY="" \
# Mistral
MISTRAL_API_KEY="" \
# Moonshot
MOONSHOT_API_KEY="" MOONSHOT_PROXY_URL="" \
# Novita
NOVITA_API_KEY="" \
# Ollama
OLLAMA_MODEL_LIST="" OLLAMA_PROXY_URL="" \
# OpenAI
OPENAI_API_KEY="" OPENAI_MODEL_LIST="" OPENAI_PROXY_URL="" \
# OpenRouter
OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \
# Perplexity
PERPLEXITY_API_KEY="" PERPLEXITY_PROXY_URL="" \
# Qwen
QWEN_API_KEY="" \
# Stepfun
STEPFUN_API_KEY="" \
# Taichu
TAICHU_API_KEY="" \
# TogetherAI
TOGETHERAI_API_KEY="" TOGETHERAI_MODEL_LIST="" \
# 01.AI
ZEROONE_API_KEY="" \
# Zhipu
ZHIPU_API_KEY=""

USER nextjs

EXPOSE 3210/tcp

# run migration , then run app
CMD ["sh", "-c", "node /app/docker.cjs && node /app/server.js"]
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
<!-- AGENT LIST -->

| Recent Submits | Description |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Code Snark Master](https://chat-preview.lobehub.com/market?agent=code-snark-master)<br/><sup>By **[leter](https://github.com/leter)** on **2024-07-29**</sup> | Specializes in sharp criticism of code, sarcastically pointing out inefficiencies and readability issues<br/>`tech-leadership` `code-review` `sarcastic-style` `programming-consultation` |
| [Unity Maestro](https://chat-preview.lobehub.com/market?agent=unity-maestro)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-07-29**</sup> | Expert Unity Game Development Companion<br/>`game-development` `unity` `software-engineering` |
| [C Program Learning Assistant](https://chat-preview.lobehub.com/market?agent=sichuan-university-941-c-programming-assistant)<br/><sup>By **[YBGuoYang](https://github.com/YBGuoYang)** on **2024-07-28**</sup> | Assist me in learning C program design<br/>`941` |
| [Brand Pioneer](https://chat-preview.lobehub.com/market?agent=brand-pioneer)<br/><sup>By **[SaintFresh](https://github.com/SaintFresh)** on **2024-07-25**</sup> | A brand development specialist, thought leader, brand strategy super-genius, and brand visionary. Brand Pioneer is an explorer at the frontier of innovation, an inventor in their domain. Provide them with your market and let them imagine a future world characterized by groundbreaking advancements in your field of expertise.<br/>`business` `brand-pioneer` `brand-development` `business-assistant` `brand-narrative` |

> 📊 Total agents: [<kbd>**309**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
| Recent Submits | Description |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Omnipedia](https://chat-preview.lobehub.com/market?agent=omnipedia)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-08-02**</sup> | Expert in providing high-quality, well-researched information on various topics, including history, science, literature, art, and more. Skilled in summarizing complex topics, assisting with research tasks, and offering creative prompts<br/>`artificial-intelligence` `information` `education` `communication` |
| [Code Snark Master](https://chat-preview.lobehub.com/market?agent=code-snark-master)<br/><sup>By **[leter](https://github.com/leter)** on **2024-07-29**</sup> | Specializes in sharp criticism of code, sarcastically pointing out inefficiencies and readability issues<br/>`tech-leadership` `code-review` `sarcastic-style` `programming-consultation` |
| [Unity Maestro](https://chat-preview.lobehub.com/market?agent=unity-maestro)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-07-29**</sup> | Expert Unity Game Development Companion<br/>`game-development` `unity` `software-engineering` |
| [C Program Learning Assistant](https://chat-preview.lobehub.com/market?agent=sichuan-university-941-c-programming-assistant)<br/><sup>By **[YBGuoYang](https://github.com/YBGuoYang)** on **2024-07-28**</sup> | Assist me in learning C program design<br/>`941` |

> 📊 Total agents: [<kbd>**310**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
<!-- AGENT LIST -->

Expand Down
Loading

0 comments on commit 7f58771

Please sign in to comment.