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) {
if (readError.code === "ENOENT") {
// Config file doesn't exist, prompt user for initial setup
const name = await question("Enter Provider Name: ");
const APIKEY = await question("Enter Provider API KEY: ");
const baseUrl = await question("Enter Provider URL: ");
const model = await question("Enter MODEL Name: ");
const config = Object.assign({}, DEFAULT_CONFIG, {
Providers: [
{
name,
api_base_url: baseUrl,
api_key: APIKEY,
models: [model],
},
],
Router: {
default: `${name},${model}`,
},
});
try {
// Initialize directories
await initDir();
// Backup existing config file if it exists
const backupPath = await backupConfigFile();
if (backupPath) {
console.log(
`Backed up existing configuration file to ${backupPath}`
);
}
const config = {
PORT: 3456,
Providers: [],
Router: {},
}
// Create a minimal default config file
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 {
console.error(`Failed to read config file at ${CONFIG_FILE}`);
console.error("Error details:", readError.message);