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/** 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..480b1b8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM haskell:9.8-slim-bullseye 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: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/* + +WORKDIR /app + +COPY --from=build /out/openleetcode /usr/local/bin/openleetcode + +ENTRYPOINT ["openleetcode"] diff --git a/README.md b/README.md index 0efded0..76d87aa 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $ 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: @@ -45,7 +45,16 @@ Windows 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: + +```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 piston.yml up -d +docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version +``` + +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 3e96207..2c812d2 100644 --- a/backends/piston/docker-compose.yml +++ b/backends/piston/docker-compose.yml @@ -1,6 +1,10 @@ services: 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 new file mode 100644 index 0000000..3a895c5 --- /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: "http://backend:2000" + +volumes: + openleetcode_data: