-
Notifications
You must be signed in to change notification settings - Fork 1
Add support for Docker #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,6 @@ Thumbs.db | |
# Vite | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* | ||
|
||
# Docker | ||
*data* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
FROM oven/bun:1 as builder | ||
|
||
WORKDIR /app | ||
|
||
# Copy package.json and install dependencies | ||
COPY package.json bun.lockb* ./ | ||
RUN bun install --frozen-lockfile | ||
|
||
# Copy the rest of the application | ||
COPY . . | ||
|
||
# Create a modified codefort.ts for build time to avoid connection attempts | ||
RUN mkdir -p /app/src/lib/server/tmp | ||
RUN echo '// Mock codefort client for build\n\ | ||
import { CODEFORT_URL } from "$env/static/private";\n\ | ||
\n\ | ||
async function getLanguages() {\n\ | ||
return [{ id: "javascript", name: "JavaScript" }];\n\ | ||
}\n\ | ||
\n\ | ||
export const languages = await getLanguages();\n\ | ||
\n\ | ||
export async function execute(language, code, stdin, compileTimeout, compileMemoryLimit, runTimeout, runMemoryLimit) {\n\ | ||
return { exitCode: 0, stdout: "", stderr: "", stats: { compile: null, run: { realTime: 0 } } };\n\ | ||
}' > /app/src/lib/server/tmp/mock-codefort.ts | ||
|
||
# Backup original file and use mock | ||
RUN cp /app/src/lib/server/codefort.ts /app/src/lib/server/codefort.ts.orig | ||
RUN cp /app/src/lib/server/tmp/mock-codefort.ts /app/src/lib/server/codefort.ts | ||
|
||
# Create .env file for build | ||
RUN echo "CODEFORT_URL=\"http://codefort:3000\"" > .env | ||
RUN echo "DATABASE_URL=\"postgres://happyjudge:happyjudge@postgres:5432/happyjudge\"" >> .env | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this not re-use the .env provided by the user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately i couldnt figure out a way to mount a file. docker was keep confusing it to a directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it in |
||
|
||
# Make sure SvelteKit processes the environment variables | ||
RUN bun run prepare | ||
|
||
# Build the application | ||
RUN bun run build | ||
|
||
# Restore original codefort.ts | ||
RUN cp /app/src/lib/server/codefort.ts.orig /app/src/lib/server/codefort.ts | ||
|
||
FROM oven/bun:1-slim as runner | ||
|
||
RUN apt-get update && apt-get install -y netcat-traditional && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
# Copy built application and necessary files from builder stage | ||
COPY --from=builder /app/build ./build | ||
COPY --from=builder /app/package.json ./ | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/src/lib/server/codefort.ts ./src/lib/server/codefort.ts | ||
# Copy database schema and migration tools | ||
COPY --from=builder /app/src/lib/server/db ./src/lib/server/db | ||
COPY --from=builder /app/drizzle.config.ts ./ | ||
|
||
# Set environment variables | ||
ENV NODE_ENV=production | ||
ENV PORT=3001 | ||
|
||
# Push database schema | ||
ENV DATABASE_URL=postgres://happyjudge:happyjudge@postgres:5432/happyjudge | ||
RUN bun run db:push --force | ||
|
||
RUN echo '#!/bin/sh\n\ | ||
# Wait for PostgreSQL to be ready\n\ | ||
until nc -z postgres 5432; do\n\ | ||
echo "Waiting for PostgreSQL to start..."\n\ | ||
sleep 1\n\ | ||
done\n\ | ||
\n\ | ||
# Push database schema\n\ | ||
echo "Initializing database schema..."\n\ | ||
bun run db:push --force\n\ | ||
\n\ | ||
# Start the application\n\ | ||
exec bun ./build' > /app/start.sh | ||
|
||
RUN chmod +x /app/start.sh | ||
|
||
# Expose the port | ||
EXPOSE 3001 | ||
|
||
# Run the startup script | ||
CMD ["/app/start.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
services: | ||
happyjudge: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "3001:3001" | ||
environment: | ||
- CODEFORT_URL=http://codefort:3000 | ||
- DATABASE_URL=postgres://happyjudge:happyjudge@postgres:5432/happyjudge | ||
depends_on: | ||
- postgres | ||
restart: unless-stopped | ||
# volumes: | ||
# - ./.env:/app/.env:ro | ||
networks: | ||
- judge-network | ||
|
||
postgres: | ||
image: postgres:16-alpine | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
- POSTGRES_USER=happyjudge | ||
- POSTGRES_PASSWORD=happyjudge | ||
- POSTGRES_DB=happyjudge | ||
volumes: | ||
- ./postgres_data:/var/lib/postgresql/data:rw | ||
restart: unless-stopped | ||
networks: | ||
- judge-network | ||
|
||
networks: | ||
judge-network: | ||
name: judge-network | ||
external: true |
Uh oh!
There was an error while loading. Please reload this page.