mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
Merge pull request #67 from shumaiOne/feat/docker-hardening
refactor(docker): run as non-root bun user and add agent tools
This commit is contained in:
+29
-10
@@ -22,18 +22,37 @@ RUN bun run build.ts
|
|||||||
# Stage 2: Runner
|
# Stage 2: Runner
|
||||||
FROM oven/bun:1 AS runner
|
FROM oven/bun:1 AS runner
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install ffmpeg/ffprobe
|
# Install ffmpeg/ffprobe
|
||||||
COPY --from=mwader/static-ffmpeg:8.1 /ffmpeg /usr/local/bin/
|
COPY --from=mwader/static-ffmpeg:8.1 /ffmpeg /usr/local/bin/
|
||||||
COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
|
COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
|
||||||
|
|
||||||
# Install system dependencies for sandbox runtime
|
# Install system dependencies for sandbox runtime and agent
|
||||||
RUN apt-get update && apt-get install -y ripgrep bubblewrap socat && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
python3 \
|
||||||
|
make \
|
||||||
|
man-db \
|
||||||
|
curl \
|
||||||
|
dnsutils \
|
||||||
|
less \
|
||||||
|
jq \
|
||||||
|
bc \
|
||||||
|
unzip \
|
||||||
|
rsync \
|
||||||
|
ripgrep \
|
||||||
|
procps \
|
||||||
|
lsof \
|
||||||
|
socat \
|
||||||
|
ca-certificates \
|
||||||
|
bubblewrap \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy sharp/img from builder (they are native and already installed)
|
# Set up working directory and make it owned by the bun user
|
||||||
# COPY --from=builder /app/packages/transcode/node_modules/sharp ./node_modules/sharp
|
RUN mkdir -p /app/data && chown -R bun:bun /app
|
||||||
# COPY --from=builder /app/packages/transcode/node_modules/@img ./node_modules/@img
|
|
||||||
|
# Switch to the non-root bun user
|
||||||
|
USER bun
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Manually install temporalio packages and prisma
|
# Manually install temporalio packages and prisma
|
||||||
# These need native bindings or CLI access in the runner environment
|
# These need native bindings or CLI access in the runner environment
|
||||||
@@ -41,9 +60,9 @@ RUN bun add @temporalio/activity @temporalio/client @temporalio/worker @temporal
|
|||||||
bun add --dev --omit peer prisma sharp
|
bun add --dev --omit peer prisma sharp
|
||||||
|
|
||||||
# Copy build artifacts and prisma config
|
# Copy build artifacts and prisma config
|
||||||
COPY --from=builder /app/dist ./
|
COPY --chown=bun:bun --from=builder /app/dist ./
|
||||||
COPY --from=builder /app/packages/db/prisma ./packages/db/prisma
|
COPY --chown=bun:bun --from=builder /app/packages/db/prisma ./packages/db/prisma
|
||||||
COPY --from=builder /app/prisma.config.ts.prod ./prisma.config.ts
|
COPY --chown=bun:bun --from=builder /app/prisma.config.ts.prod ./prisma.config.ts
|
||||||
|
|
||||||
# Expose port (Bun Hono defaults to 3000)
|
# Expose port (Bun Hono defaults to 3000)
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { temporalWorkflow } from './bun-temporal-plugin'
|
|||||||
import * as worker from '@temporalio/worker'
|
import * as worker from '@temporalio/worker'
|
||||||
|
|
||||||
vi.mock('@temporalio/worker', () => ({
|
vi.mock('@temporalio/worker', () => ({
|
||||||
bundleWorkflowCode: vi.fn().mockResolvedValue({ code: 'mock-code', sourceMap: '' })
|
bundleWorkflowCode: vi.fn().mockResolvedValue({ code: 'mock-code', sourceMap: '' }),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe('temporalWorkflow plugin', () => {
|
describe('temporalWorkflow plugin', () => {
|
||||||
@@ -13,14 +13,14 @@ describe('temporalWorkflow plugin', () => {
|
|||||||
|
|
||||||
it('should register onLoad and configure webpackConfigHook with @temporalio/workflow alias', async () => {
|
it('should register onLoad and configure webpackConfigHook with @temporalio/workflow alias', async () => {
|
||||||
const plugin = temporalWorkflow()
|
const plugin = temporalWorkflow()
|
||||||
|
|
||||||
let onLoadCallback: ((...args: unknown[]) => unknown) | null = null
|
let onLoadCallback: ((...args: unknown[]) => unknown) | null = null
|
||||||
|
|
||||||
const mockBuild = {
|
const mockBuild = {
|
||||||
onResolve: vi.fn(),
|
onResolve: vi.fn(),
|
||||||
onLoad: vi.fn((opts, callback) => {
|
onLoad: vi.fn((opts, callback) => {
|
||||||
onLoadCallback = callback
|
onLoadCallback = callback
|
||||||
})
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run setup
|
// Run setup
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ export function temporalWorkflow(options: TemporalWorkflowPluginOptions = {}): B
|
|||||||
...config.resolve.alias,
|
...config.resolve.alias,
|
||||||
'@shumai/workflow-core':
|
'@shumai/workflow-core':
|
||||||
require.resolve('@shumai/workflow-core/src/workflow-utils.ts'),
|
require.resolve('@shumai/workflow-core/src/workflow-utils.ts'),
|
||||||
'@temporalio/workflow': dirname(
|
'@temporalio/workflow': dirname(require.resolve('@temporalio/workflow/package.json')),
|
||||||
require.resolve('@temporalio/workflow/package.json'),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
console.log('Webpack config aliases:', config.resolve.alias)
|
console.log('Webpack config aliases:', config.resolve.alias)
|
||||||
if (originalHook) {
|
if (originalHook) {
|
||||||
|
|||||||
Reference in New Issue
Block a user