-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add Docker support with CLI improvements #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef5639c
chore: add cli build
rsbh ea4dd53
feat: use local next binary instead of npx
rsbh 4363e1c
fix: add util to resolve content folder
rsbh 8fa3471
feat: add dockerfile
rsbh ae8c5a0
chore: remove content dir
rsbh ffc998c
chore: add dockerignore
rsbh 14060a3
fix: address PR review feedback
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| node_modules | ||
| **/node_modules | ||
| .next | ||
| **/.next | ||
| .git | ||
| *.log | ||
| **/.source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| FROM node:24-slim AS base | ||
| ENV PNPM_HOME="/pnpm" | ||
| ENV PATH="$PNPM_HOME:$PATH" | ||
| RUN corepack enable | ||
|
|
||
| # --- deps --- | ||
| FROM base AS deps | ||
| WORKDIR /app | ||
| COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./ | ||
| COPY packages/chronicle/package.json ./packages/chronicle/ | ||
| RUN pnpm install --frozen-lockfile --filter @raystack/chronicle | ||
|
|
||
| # --- build CLI --- | ||
| FROM base AS builder | ||
| WORKDIR /app/packages/chronicle | ||
| COPY --from=deps /app /app | ||
| COPY packages/chronicle ./ | ||
| RUN pnpm build:cli | ||
|
|
||
| # --- runner --- | ||
| FROM base AS runner | ||
| WORKDIR /app/packages/chronicle | ||
|
|
||
| COPY --from=builder /app /app | ||
|
|
||
| RUN chmod +x bin/chronicle.js | ||
| RUN ln -s /app/packages/chronicle/bin/chronicle.js /usr/local/bin/chronicle | ||
|
|
||
| RUN mkdir -p /app/content && ln -s /app/content /app/packages/chronicle/content | ||
| RUN chown -R node:node /app | ||
|
|
||
| VOLUME /app/content | ||
| USER node | ||
|
|
||
| ENV CHRONICLE_CONTENT_DIR=./content | ||
| WORKDIR /app/packages/chronicle | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENTRYPOINT ["chronicle"] | ||
| CMD ["dev", "--port", "3000"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "name": "chronicle", | ||
| "private": true, | ||
| "packageManager": "pnpm@9.15.0", | ||
| "packageManager": "pnpm@10.6.2", | ||
| "engines": { | ||
| "node": ">=24" | ||
| "node": ">=22" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,31 @@ | ||
| import { Command } from 'commander' | ||
| import { spawn } from 'child_process' | ||
| import path from 'path' | ||
| import { fileURLToPath } from 'url' | ||
| import chalk from 'chalk' | ||
| import { loadCLIConfig } from '../utils' | ||
| import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '../utils' | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| const packageRoot = path.resolve(__dirname, '../../..') | ||
| declare const PACKAGE_ROOT: string | ||
|
|
||
| const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') | ||
|
|
||
| export const buildCommand = new Command('build') | ||
| .description('Build for production') | ||
| .action(() => { | ||
| const { contentDir } = loadCLIConfig() | ||
| .option('-c, --content <path>', 'Content directory') | ||
| .action((options) => { | ||
| const contentDir = resolveContentDir(options.content) | ||
| loadCLIConfig(contentDir) | ||
|
|
||
| console.log(chalk.cyan('Building for production...')) | ||
| console.log(chalk.gray(`Content: ${contentDir}`)) | ||
|
|
||
| spawn('npx', ['next', 'build'], { | ||
| const child = spawn(nextBin, ['build'], { | ||
| stdio: 'inherit', | ||
| shell: true, | ||
| cwd: packageRoot, | ||
| cwd: PACKAGE_ROOT, | ||
| env: { | ||
| ...process.env, | ||
| CHRONICLE_CONTENT_DIR: contentDir, | ||
| }, | ||
| }) | ||
|
|
||
| attachLifecycleHandlers(child) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,32 @@ | ||
| import { Command } from 'commander' | ||
| import { spawn } from 'child_process' | ||
| import path from 'path' | ||
| import { fileURLToPath } from 'url' | ||
| import chalk from 'chalk' | ||
| import { loadCLIConfig } from '../utils' | ||
| import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '../utils' | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| const packageRoot = path.resolve(__dirname, '../../..') | ||
| declare const PACKAGE_ROOT: string | ||
|
|
||
| const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') | ||
|
|
||
| export const devCommand = new Command('dev') | ||
| .description('Start development server') | ||
| .option('-p, --port <port>', 'Port number', '3000') | ||
| .option('-c, --content <path>', 'Content directory') | ||
| .action((options) => { | ||
| const { contentDir } = loadCLIConfig() | ||
| const contentDir = resolveContentDir(options.content) | ||
| loadCLIConfig(contentDir) | ||
|
|
||
| console.log(chalk.cyan('Starting dev server...')) | ||
| console.log(chalk.gray(`Content: ${contentDir}`)) | ||
|
|
||
| spawn('npx', ['next', 'dev', '-p', options.port], { | ||
| const child = spawn(nextBin, ['dev', '-p', options.port], { | ||
| stdio: 'inherit', | ||
| shell: true, | ||
| cwd: packageRoot, | ||
| cwd: PACKAGE_ROOT, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| env: { | ||
| ...process.env, | ||
| CHRONICLE_CONTENT_DIR: contentDir, | ||
| }, | ||
| }) | ||
|
|
||
| attachLifecycleHandlers(child) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,32 @@ | ||
| import { Command } from 'commander' | ||
| import { spawn } from 'child_process' | ||
| import path from 'path' | ||
| import { fileURLToPath } from 'url' | ||
| import chalk from 'chalk' | ||
| import { loadCLIConfig } from '../utils' | ||
| import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '../utils' | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| const packageRoot = path.resolve(__dirname, '../../..') | ||
| declare const PACKAGE_ROOT: string | ||
|
|
||
| const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') | ||
|
|
||
| export const startCommand = new Command('start') | ||
| .description('Start production server') | ||
| .option('-p, --port <port>', 'Port number', '3000') | ||
| .option('-c, --content <path>', 'Content directory') | ||
| .action((options) => { | ||
| const { contentDir } = loadCLIConfig() | ||
| const contentDir = resolveContentDir(options.content) | ||
| loadCLIConfig(contentDir) | ||
|
|
||
| console.log(chalk.cyan('Starting production server...')) | ||
| console.log(chalk.gray(`Content: ${contentDir}`)) | ||
|
|
||
| spawn('npx', ['next', 'start', '-p', options.port], { | ||
| const child = spawn(nextBin, ['start', '-p', options.port], { | ||
| stdio: 'inherit', | ||
| shell: true, | ||
| cwd: packageRoot, | ||
| cwd: PACKAGE_ROOT, | ||
| env: { | ||
| ...process.env, | ||
| CHRONICLE_CONTENT_DIR: contentDir, | ||
| }, | ||
| }) | ||
|
|
||
| attachLifecycleHandlers(child) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './config' | ||
| export * from './process' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import type { ChildProcess } from 'child_process' | ||
|
|
||
| export function attachLifecycleHandlers(child: ChildProcess) { | ||
| child.on('close', (code) => process.exit(code ?? 0)) | ||
| process.on('SIGINT', () => child.kill('SIGINT')) | ||
| process.on('SIGTERM', () => child.kill('SIGTERM')) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { defineConfig } from 'tsup' | ||
| import path from 'path' | ||
| import { fileURLToPath } from 'url' | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
|
||
| export default defineConfig({ | ||
| entry: ['src/cli/index.ts'], | ||
| format: ['esm'], | ||
| outDir: 'dist/cli', | ||
| target: 'node22', | ||
| clean: true, | ||
| sourcemap: false, | ||
| define: { | ||
| PACKAGE_ROOT: JSON.stringify(path.resolve(__dirname)), | ||
| }, | ||
|
rsbh marked this conversation as resolved.
|
||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.