From 921d3d4974d6bf96ad625ec806d4567972e8be6c Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 00:23:56 +0300 Subject: [PATCH 01/12] add docker install and usage flow Closes: gh-45 --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c94a1f8..99a0cd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,17 @@ jobs: Copy-Item $exe.FullName "artifacts/${{ matrix.artifact }}.exe" + - name: Smoke test executable + if: runner.os != 'Windows' + run: | + ./artifacts/${{ matrix.artifact }} --version + + - name: Smoke test executable + if: runner.os == 'Windows' + shell: pwsh + run: | + .\artifacts\${{ matrix.artifact }}.exe --version + - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -78,6 +89,18 @@ jobs: path: artifacts/* if-no-files-found: error + build-container: + name: Build container + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: docker build -t openleetcode:test . + + - name: Smoke test + run: docker run --rm openleetcode:test --version + discover-test-ranges: name: Discover test ranges runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a359a21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM haskell:9.8-bookworm AS build + +WORKDIR /src + +COPY cabal.project openleetcode.cabal ./ +COPY cli ./cli +COPY core ./core + +RUN cabal update \ + && cabal build exe:openleetcode \ + && exe="$(find dist-newstyle -type f -path '*/x/openleetcode/build/openleetcode/openleetcode' | head -n 1)" \ + && test -n "$exe" \ + && install -D "$exe" /out/openleetcode + +FROM debian:bookworm-slim + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates libgmp10 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /work + +COPY --from=build /out/openleetcode /usr/local/bin/openleetcode + +ENTRYPOINT ["openleetcode"] From d2fca89dc4e866e5e58829b560fc29be0096e7fe Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 00:27:59 +0300 Subject: [PATCH 02/12] bullseye --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a359a21..381cbdd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM haskell:9.8-bookworm AS build +FROM haskell:9.8-slim-bullseye AS build WORKDIR /src @@ -12,7 +12,7 @@ RUN cabal update \ && test -n "$exe" \ && install -D "$exe" /out/openleetcode -FROM debian:bookworm-slim +FROM debian:bullseye-slim RUN apt-get update \ && apt-get install -y --no-install-recommends ca-certificates libgmp10 \ From 2ced735e0aecad24678d6c7d0f9023b61382afb0 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 02:45:54 +0300 Subject: [PATCH 03/12] compose --- Dockerfile | 2 +- README.md | 8 ++++++++ backends/piston/docker-compose.yml | 9 +++++++++ openleetcode.yml | 13 +++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 openleetcode.yml diff --git a/Dockerfile b/Dockerfile index 381cbdd..6210b18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends ca-certificates libgmp10 \ && rm -rf /var/lib/apt/lists/* -WORKDIR /work +WORKDIR /app COPY --from=build /out/openleetcode /usr/local/bin/openleetcode diff --git a/README.md b/README.md index 0efded0..396d35a 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,14 @@ irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | On Windows, the installer only installs the CLI. Bring Docker yourself and start the backend manually. +Docker: + +```sh +curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml +curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml +docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode submit ./solution.py --id 1 +``` + ## Backend openleetcode currently uses [Piston](/backends/piston/docker-compose.yml) as its execution backend. The default config points to: diff --git a/backends/piston/docker-compose.yml b/backends/piston/docker-compose.yml index 3e96207..314c4be 100644 --- a/backends/piston/docker-compose.yml +++ b/backends/piston/docker-compose.yml @@ -1,4 +1,13 @@ services: + openleetcode: + environment: + - OPENLEETCODE_BACKEND_URL=http://piston:2000 + depends_on: + piston: + condition: service_started + piston-installer: + condition: service_completed_successfully + piston: image: ghcr.io/engineer-man/piston:latest container_name: piston diff --git a/openleetcode.yml b/openleetcode.yml new file mode 100644 index 0000000..573fc84 --- /dev/null +++ b/openleetcode.yml @@ -0,0 +1,13 @@ +services: + openleetcode: + image: ghcr.io/therepanic/openleetcode:latest + stdin_open: true + tty: true + volumes: + - ./:/app + - openleetcode_data:/root/.config/openleetcode + environment: + OPENLEETCODE_BACKEND_URL: ${OPENLEETCODE_BACKEND_URL:-http://backend:2000} + +volumes: + openleetcode_data: From 3f664cb422b76c97e11aed7540f82d97d3ce56e4 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 02:48:03 +0300 Subject: [PATCH 04/12] bold --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 396d35a..57ccf19 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,13 @@ $ openleetcode submit ./solution.rs --title two-sum You need Docker for the execution backend. On Linux and macOS the installer will try to start the default Piston backend for you through Docker Compose. -Linux and macOS: +**Linux and macOS:** ```sh curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/install.sh | sh ``` -Windows PowerShell: +**Windows PowerShell:** ```powershell irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | iex @@ -47,7 +47,7 @@ irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | On Windows, the installer only installs the CLI. Bring Docker yourself and start the backend manually. -Docker: +**Docker:** ```sh curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml From 6a115969d8d87dc8376d94534ca5bdab7378f096 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 02:50:54 +0300 Subject: [PATCH 05/12] bold is shit --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 57ccf19..ee4b6e0 100644 --- a/README.md +++ b/README.md @@ -31,23 +31,21 @@ $ openleetcode submit ./solution.rs --title two-sum ## Install -You need Docker for the execution backend. On Linux and macOS the installer will try to start the default Piston backend for you through Docker Compose. +You need Docker for the execution backend. On Linux and macOS the installer will try to start the default Piston backend for you through Docker Compose. On Windows, the installer only installs the CLI. Bring Docker yourself and start the backend manually. -**Linux and macOS:** +Linux and macOS: ```sh curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/install.sh | sh ``` -**Windows PowerShell:** +Windows PowerShell: ```powershell irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | iex ``` -On Windows, the installer only installs the CLI. Bring Docker yourself and start the backend manually. - -**Docker:** +Docker: ```sh curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml From 1f7bf99b0cf570acf2068c293633991969d77d00 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 03:03:38 +0300 Subject: [PATCH 06/12] disclaimer --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ee4b6e0..abafe58 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backen docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode submit ./solution.py --id 1 ``` +The first run installs runtimes and may take a while. + ## Backend openleetcode currently uses [Piston](/backends/piston/docker-compose.yml) as its execution backend. The default config points to: From ec7fff9646291a204e7f3d551ae426905b21c2f7 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 03:14:18 +0300 Subject: [PATCH 07/12] version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abafe58..9053e4b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Docker: ```sh curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml -docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode submit ./solution.py --id 1 +docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version ``` The first run installs runtimes and may take a while. From f32e7c642b46b354fca5149816c64f5c842b4be0 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 03:19:08 +0300 Subject: [PATCH 08/12] concrete --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9053e4b..07a0759 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backen docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version ``` -The first run installs runtimes and may take a while. +The first run may take a while while the backend installs runtimes. ## Backend From eeecfa4ec9329b9c26d84d3b73b3788ed6dca21c Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 03:51:50 +0300 Subject: [PATCH 09/12] nice? --- README.md | 8 +++++--- backends/piston/docker-compose.yml | 13 ++++--------- openleetcode.yml | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 07a0759..9a89bee 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,14 @@ irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | Docker: ```sh -curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml -curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml +curl -fsSL \ + -o openleetcode.yml https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml \ + -o piston.yml https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml +docker compose -f piston.yml up -d docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version ``` -The first run may take a while while the backend installs runtimes. +The backend may take a while to install runtimes on the first start. ## Backend diff --git a/backends/piston/docker-compose.yml b/backends/piston/docker-compose.yml index 314c4be..2c812d2 100644 --- a/backends/piston/docker-compose.yml +++ b/backends/piston/docker-compose.yml @@ -1,15 +1,10 @@ services: - openleetcode: - environment: - - OPENLEETCODE_BACKEND_URL=http://piston:2000 - depends_on: - piston: - condition: service_started - piston-installer: - condition: service_completed_successfully - piston: image: ghcr.io/engineer-man/piston:latest + networks: + default: + aliases: + - backend container_name: piston restart: unless-stopped privileged: true diff --git a/openleetcode.yml b/openleetcode.yml index 573fc84..3a895c5 100644 --- a/openleetcode.yml +++ b/openleetcode.yml @@ -7,7 +7,7 @@ services: - ./:/app - openleetcode_data:/root/.config/openleetcode environment: - OPENLEETCODE_BACKEND_URL: ${OPENLEETCODE_BACKEND_URL:-http://backend:2000} + OPENLEETCODE_BACKEND_URL: "http://backend:2000" volumes: openleetcode_data: From f9c4defba49866ac290bb8af9686c92a4b3601f6 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 03:53:42 +0300 Subject: [PATCH 10/12] more cool --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9a89bee..76d87aa 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,8 @@ irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | Docker: ```sh -curl -fsSL \ - -o openleetcode.yml https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml \ - -o piston.yml https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml +curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml +curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml docker compose -f piston.yml up -d docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version ``` From 994aec3e1e32a54f24bf2ac704cd15397718d172 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 04:22:33 +0300 Subject: [PATCH 11/12] add .dockerignore --- .dockerignore | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1ef5679 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +* +!Dockerfile +!.dockerignore +!cabal.project +!openleetcode.cabal +!cli/ +!cli/** +!core/ +!core/** From f316e9452fe6d155634f2d94d7c5bfbd5188ebd2 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Mon, 6 Jul 2026 05:00:46 +0300 Subject: [PATCH 12/12] label --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 6210b18..480b1b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,8 @@ RUN cabal update \ FROM debian:bullseye-slim +LABEL org.opencontainers.image.source="https://github.com/therepanic/openleetcode" + RUN apt-get update \ && apt-get install -y --no-install-recommends ca-certificates libgmp10 \ && rm -rf /var/lib/apt/lists/*