optimize docker deployment

This commit is contained in:
musistudio
2025-09-03 09:58:09 +08:00
parent 5761e165fd
commit e670302e9e
3 changed files with 43 additions and 47 deletions

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM node:20-alpine
RUN npm install -g @musistudio/claude-code-router
EXPOSE 3456
CMD ["ccr", "start"]

View File

@@ -1,24 +0,0 @@
FROM node:20-alpine
WORKDIR /app
# Copy all files
COPY . .
# Install pnpm globally
RUN npm install -g pnpm
# Install dependencies
RUN pnpm install --frozen-lockfile
# Fix rollup optional dependencies issue
RUN cd ui && npm install
# Build the entire project including UI
RUN pnpm run build
# Expose port
EXPOSE 3456
# Start the router service
CMD ["node", "dist/cli.js", "start"]

View File

@@ -83,25 +83,38 @@ export const readConfigFile = async () => {
} catch (readError: any) { } catch (readError: any) {
if (readError.code === "ENOENT") { if (readError.code === "ENOENT") {
// Config file doesn't exist, prompt user for initial setup // Config file doesn't exist, prompt user for initial setup
const name = await question("Enter Provider Name: "); try {
const APIKEY = await question("Enter Provider API KEY: "); // Initialize directories
const baseUrl = await question("Enter Provider URL: "); await initDir();
const model = await question("Enter MODEL Name: ");
const config = Object.assign({}, DEFAULT_CONFIG, { // Backup existing config file if it exists
Providers: [ const backupPath = await backupConfigFile();
{ if (backupPath) {
name, console.log(
api_base_url: baseUrl, `Backed up existing configuration file to ${backupPath}`
api_key: APIKEY, );
models: [model], }
}, const config = {
], PORT: 3456,
Router: { Providers: [],
default: `${name},${model}`, Router: {},
}, }
}); // Create a minimal default config file
await writeConfigFile(config); await writeConfigFile(config);
return config; console.log(
"Created minimal default configuration file at ~/.claude-code-router/config.json"
);
console.log(
"Please edit this file with your actual configuration."
);
return config
} catch (error: any) {
console.error(
"Failed to create default configuration:",
error.message
);
process.exit(1);
}
} else { } else {
console.error(`Failed to read config file at ${CONFIG_FILE}`); console.error(`Failed to read config file at ${CONFIG_FILE}`);
console.error("Error details:", readError.message); console.error("Error details:", readError.message);