Skip to content

Commit

Permalink
chore: 分离docker编译和运行环境
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Nov 13, 2024
1 parent 9e1cda2 commit 60bcdba
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ out
/wrangler-test.toml
/dist/index.cjs
/dist/index.d.ts
/dist/src
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
FROM node:alpine

FROM node:alpine AS build
WORKDIR /app
COPY package.json tsconfig.json ./
COPY src src
COPY package.json tsconfig.json vite.config.ts ./
RUN npm install
COPY src src
RUN npm run build:local


FROM node:alpine AS production
WORKDIR /app
COPY package.json ./
RUN npm install --omit=dev
COPY --from=build /app/dist ./dist
EXPOSE 8787
CMD ["npm", "run", "start:local"]
CMD ["npm", "run", "start:dist"]
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ services:
volumes:
- ./config.json:/app/config.json:ro # change `./config.json` to your local path
- ./wrangler.toml:/app/wrangler.toml:ro # change `./wrangler.toml` to your local path
network_mode: "host" # If you access the proxy port based on the host
entrypoint: ["npm", "run", "start:dist"]
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chatgpt-telegram-workers",
"type": "module",
"version": "1.9.4",
"version": "1.10.0",
"description": "The easiest and quickest way to deploy your own ChatGPT Telegram bot is to use a single file and simply copy and paste it. There is no need for any dependencies, local development environment configuration, domain names, or servers.",
"author": "tbxark <[email protected]>",
"license": "MIT",
Expand All @@ -21,20 +21,21 @@
],
"scripts": {
"lint": "eslint --fix *.js *.ts src plugins scripts",
"version": "tsx ./scripts/plugins/version/main.ts",
"version": "tsx src/vite/version/main.ts",
"build": "vite build",
"build:local": "vite build",
"build:local": "ENTRY=src/entry/local/index.ts vite build",
"build:docker": "docker build -t chatgpt-telegram-workers:latest .",
"build:dockerx": "docker build --platform linux/amd64,linux/arm64 -t tbxark/chatgpt-telegram-workers:latest --push .",
"build:vercel": "ENTRY=src/entry/vercel/index.ts vite build",
"build:pack": "TYPES=true FORMATS=es,cjs vite build",
"deploy:dist": "wrangler deploy",
"deploy:build": "npm run build && wrangler deploy",
"deploy:vercel": "vercel deploy --prod",
"deploy:plugin": "vite build -c plugins/vite.config.ts && wrangler pages deploy plugins --project-name=interpolate-test --branch=main",
"start:dist": "node dist/index.js",
"start:dist": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml node dist/index.js",
"start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx src/entry/local/index.ts",
"start:debug": "wrangler dev --local",
"prepare:vercel": "tsx ./scripts/plugins/vercel/setenv.ts",
"prepare:vercel": "tsx src/vite/vercel/setenv.ts",
"wrangler": "wrangler",
"test": "tsx ./src/agent/index.test.ts"
},
Expand Down
4 changes: 2 additions & 2 deletions src/config/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BUILD_TIMESTAMP = 1731464647;
export const BUILD_VERSION = 'fe9ef45';
export const BUILD_TIMESTAMP = 1731468421;
export const BUILD_VERSION = '9e1cda2';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs/promises';
import { parse } from 'toml';
import { ENV } from '../../../src/config/env';
import { ENV } from '../../config/env';

export function createVercelPlugin(vercelPath: string, tomlPath: string, removeUnused = true) {
return {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 29 additions & 18 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
import type { LibraryFormats, Plugin } from 'vite';
import * as path from 'node:path';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import { nodeExternals } from 'rollup-plugin-node-externals';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import dts from 'vite-plugin-dts';
import { createVersionPlugin } from './scripts/plugins/version';
import { createVersionPlugin } from './src/vite/version';

const {
TYPES = 'false',
FORMATS = 'es',
ENTRY = 'src/entry/core/index.ts',
} = process.env;

const plugins: Plugin[] = [
nodeResolve({
browser: false,
preferBuiltins: true,
}),
cleanup({
comments: 'none',
extensions: ['js', 'ts'],
}),
checker({
typescript: true,
}),
nodeExternals(),
createVersionPlugin(path.resolve(__dirname)),
];

if (TYPES === 'true') {
plugins.push(
dts(),
);
}

export default defineConfig({
plugins: [
nodeResolve({
preferBuiltins: true,
}),
cleanup({
comments: 'none',
extensions: ['js', 'ts'],
}),
checker({
typescript: true,
}),
dts({
rollupTypes: true,
}),
createVersionPlugin(path.resolve(__dirname)),
],
plugins,
build: {
target: 'esnext',
lib: {
entry: path.resolve(__dirname, ENTRY),
fileName: 'index',
formats: ['es', 'cjs'],
formats: FORMATS.split(',') as LibraryFormats[],
},
minify: false,
outDir: path.resolve(__dirname, 'dist'),
Expand Down

0 comments on commit 60bcdba

Please sign in to comment.