diff --git a/web/backend/.gitignore b/web/backend/.gitignore index 995321f..71d6f22 100644 --- a/web/backend/.gitignore +++ b/web/backend/.gitignore @@ -1 +1,2 @@ +TODO.md jobs diff --git a/web/backend/Dockerfile b/web/backend/Dockerfile new file mode 100644 index 0000000..f3660a6 --- /dev/null +++ b/web/backend/Dockerfile @@ -0,0 +1,16 @@ +# Use official Julia image as base +FROM julia:1.11 +WORKDIR /app + +# Install project & dependencies +COPY Project.toml /app/Backend/ +COPY src /app/Backend/src +RUN julia --project=. -e 'using Pkg; Pkg.develop(path="Backend"); Pkg.add("HiGHS"); Pkg.precompile()' +COPY docker/startup.jl ./ + +# Set default environment variables +ENV UCJL_HOST="0.0.0.0" +ENV UCJL_PORT="9000" + +# Run the server +CMD ["julia", "--project=.", "startup.jl"] diff --git a/web/backend/Makefile b/web/backend/Makefile new file mode 100644 index 0000000..6d8588e --- /dev/null +++ b/web/backend/Makefile @@ -0,0 +1,5 @@ +docker-build: + docker build . -t ucjl-backend + +docker-run: + docker run --publish 9000:9000 --rm -it ucjl-backend \ No newline at end of file diff --git a/web/backend/docker/startup.jl b/web/backend/docker/startup.jl new file mode 100644 index 0000000..7f8e906 --- /dev/null +++ b/web/backend/docker/startup.jl @@ -0,0 +1,30 @@ +#!/usr/bin/env julia + +# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment +# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved. +# Released under the modified BSD license. See COPYING.md for more details. + +# Load required packages +using HiGHS +using Backend + +const UCJL_HOST = get(ENV, "HOST", "0.0.0.0") +const UCJL_PORT = parse(Int, get(ENV, "PORT", "9000")) + +println("Starting UnitCommitment Backend Server...") +println("Host: $UCJL_HOST") +println("Port: $UCJL_PORT") +println("Press Ctrl+C to stop the server") + +server = Backend.start_server(UCJL_HOST, UCJL_PORT; optimizer = HiGHS.Optimizer) +try + wait() +catch e + if e isa InterruptException + println("\nShutting down server...") + Backend.stop(server) + println("Server stopped") + else + rethrow(e) + end +end diff --git a/web/backend/src/server.jl b/web/backend/src/server.jl index 9335fb3..70afc6a 100644 --- a/web/backend/src/server.jl +++ b/web/backend/src/server.jl @@ -54,9 +54,9 @@ function submit(req, processor::JobProcessor) end function jobs_view(req) - # Extract job_id from URL path /jobs/{job_id}/view + # Extract job_id from URL path /api/jobs/{job_id}/view path_parts = split(req.target, '/') - job_id = path_parts[3] # /jobs/{job_id}/view -> index 3 + job_id = path_parts[4] # Construct job directory path job_dir = joinpath(basedir, "jobs", job_id) @@ -132,10 +132,10 @@ function start_server(host, port; optimizer) ) # Register /submit endpoint - HTTP.register!(router, "POST", "/submit", req -> submit(req, processor)) + HTTP.register!(router, "POST", "/api/submit", req -> submit(req, processor)) # Register job/*/view endpoint - HTTP.register!(router, "GET", "/jobs/*/view", jobs_view) + HTTP.register!(router, "GET", "/api/jobs/*/view", jobs_view) server = HTTP.serve!(router, host, port; verbose = false) return ServerHandle(server, processor) diff --git a/web/frontend/.env b/web/frontend/.env index 0a6ce97..07f3da8 100644 --- a/web/frontend/.env +++ b/web/frontend/.env @@ -1,2 +1,2 @@ FAST_REFRESH=false -REACT_APP_BACKEND_URL=http://localhost:9000 +REACT_APP_BACKEND_URL=http://localhost:9000/api diff --git a/web/frontend/Dockerfile b/web/frontend/Dockerfile index cec9084..84e8179 100644 --- a/web/frontend/Dockerfile +++ b/web/frontend/Dockerfile @@ -1,13 +1,6 @@ -# Build Stage -FROM node:18-alpine AS build +FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . -RUN npm run build - -# Production Stage -FROM nginx:stable-alpine AS production -COPY --from=build /app/build /usr/share/nginx/html -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] +CMD ["npm", "start"] diff --git a/web/frontend/Makefile b/web/frontend/Makefile new file mode 100644 index 0000000..3290c4d --- /dev/null +++ b/web/frontend/Makefile @@ -0,0 +1,5 @@ +docker-build: + docker build . -t ucjl-frontend + +docker-run: + docker run -e REACT_APP_BACKEND_URL=http://localhost:9000/api --publish 3000:3000 --rm -it ucjl-frontend \ No newline at end of file