Skip to content

Commit bb2e192

Browse files
committed
Change rust executor to zig
1 parent 9e6b8cf commit bb2e192

9 files changed

Lines changed: 34 additions & 33 deletions

File tree

services/app/apps/codebattle/lib/codebattle/code_check/checker.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ defmodule Codebattle.CodeCheck.Checker do
4141
end
4242

4343
defp get_executor, do: Application.fetch_env!(:codebattle, :checker_executor)
44-
# defp get_executor, do: Codebattle.CodeCheck.Executor.RemoteRust
44+
# defp get_executor, do: Codebattle.CodeCheck.Executor.RemoteZig
4545
end

services/app/apps/codebattle/lib/codebattle/code_check/executor/remote_rust.ex renamed to services/app/apps/codebattle/lib/codebattle/code_check/executor/remote_zig.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Codebattle.CodeCheck.Executor.RemoteRust do
1+
defmodule Codebattle.CodeCheck.Executor.RemoteZig do
22
@moduledoc false
33

44
alias Codebattle.CodeCheck.Checker.Token
@@ -52,13 +52,12 @@ defmodule Codebattle.CodeCheck.Executor.RemoteRust do
5252

5353
def execute(params, lang_meta) do
5454
headers = [
55-
{"content-type", "application/json"},
56-
{"content-encoding", "deflate"}
55+
{"content-type", "application/json"}
5756
]
5857

59-
Logger.debug("RemoteRustExecutor request params: #{Jason.encode!(params)}")
58+
Logger.debug("RemoteZigExecutor request params: #{Jason.encode!(params)}")
6059

61-
body = params |> Jason.encode!() |> :zlib.compress()
60+
body = Jason.encode!(params)
6261

6362
now = :os.system_time(:millisecond)
6463

@@ -67,26 +66,26 @@ defmodule Codebattle.CodeCheck.Executor.RemoteRust do
6766
|> Finch.request(CodebattleHTTP, receive_timeout: Languages.get_timeout_ms(lang_meta))
6867
|> case do
6968
{:ok, %Finch.Response{status: 200, body: body}} ->
70-
Logger.debug("RemoteRustExecutor Response #{inspect(body)}")
69+
Logger.debug("RemoteZigExecutor Response #{inspect(body)}")
7170

7271
Logger.error(
73-
"RemoteRustExecutor success lang: #{lang_meta.slug}, time_ms: #{:os.system_time(:millisecond) - now}}"
72+
"RemoteZigExecutor success lang: #{lang_meta.slug}, time_ms: #{:os.system_time(:millisecond) - now}}"
7473
)
7574

7675
AtomizedMap.load(body)
7776

7877
{:ok, %Finch.Response{status: status, body: body}} ->
7978
Logger.error(
80-
"RemoteRustExecutor failure status: #{status}, lang: #{lang_meta.slug},time_ms: #{:os.system_time(:millisecond) - now}, body: #{inspect(body)}"
79+
"RemoteZigExecutor failure status: #{status}, lang: #{lang_meta.slug},time_ms: #{:os.system_time(:millisecond) - now}, body: #{inspect(body)}"
8180
)
8281

83-
{:error, "RemoteRustExecutor failure: #{inspect(body)}"}
82+
{:error, "RemoteZigExecutor failure: #{inspect(body)}"}
8483

8584
{:error, finch_exception} ->
8685
reason = Exception.format(:error, finch_exception, [])
8786

8887
Logger.error(
89-
"RemoteRustExecutor error lang: #{lang_meta.slug}, time_ms: #{:os.system_time(:millisecond) - now}, error: #{inspect(reason)}"
88+
"RemoteZigExecutor error lang: #{lang_meta.slug}, time_ms: #{:os.system_time(:millisecond) - now}, error: #{inspect(reason)}"
9089
)
9190

9291
{:error, :timeout}
@@ -97,9 +96,10 @@ defmodule Codebattle.CodeCheck.Executor.RemoteRust do
9796
to_string(:rand.uniform(10_000_000))
9897
end
9998

100-
# defp runner_url(_lang), do: "http://localhost:4002/run"
101-
defp runner_url(lang) do
102-
namespace = Application.get_env(:codebattle, :k8s_namespace, "default")
103-
"http://runner-#{lang}.#{namespace}.svc/run"
104-
end
99+
defp runner_url(_lang), do: "http://localhost:4040/run"
100+
101+
# defp runner_url(lang) do
102+
# namespace = Application.get_env(:codebattle, :k8s_namespace, "default")
103+
# "http://runner-#{lang}.#{namespace}.svc/run"
104+
# end
105105
end

services/app/apps/runner/images/cpp/Containerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-rs:latest
2-
ARG ALPINE_TAG=3.22
1+
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-zig:latest
2+
ARG ALPINE_TAG=3.23
33
ARG TARGETPLATFORM
44

55
########################################
@@ -53,6 +53,6 @@ RUN chown -R app:app /usr/src/app || true
5353

5454
USER app
5555

56-
EXPOSE 8000
56+
EXPOSE 4040
5757
COPY --from=runner /app/codebattle_runner /runner/codebattle_runner
5858
ENTRYPOINT ["/runner/codebattle_runner"]

services/app/apps/runner/images/python/Containerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-rs:latest
2-
ARG PY_TAG=3.14.0-alpine3.22
1+
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-zig:latest
2+
ARG PY_TAG=3.14.2-alpine3.23
33
ARG TARGETPLATFORM
44

55
FROM --platform=$TARGETPLATFORM ${RUNNER_IMAGE} AS runner
@@ -21,6 +21,6 @@ RUN chown -R app:app /usr/src/app
2121

2222
USER app
2323

24-
EXPOSE 8000
24+
EXPOSE 4040
2525
COPY --from=runner /app/codebattle_runner /runner/codebattle_runner
2626
ENTRYPOINT ["/runner/codebattle_runner"]

services/app/apps/runner/images/ruby/Containerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-rs:latest
2-
ARG RUBY_TAG=3.4.7-alpine3.22
1+
ARG RUNNER_IMAGE=ghcr.io/hexlet-codebattle/runner-zig:latest
2+
ARG RUBY_TAG=4.0.1-alpine3.23
33
ARG TARGETPLATFORM
44

55
FROM --platform=$TARGETPLATFORM ${RUNNER_IMAGE} AS runner
@@ -22,6 +22,6 @@ RUN chown -R app:app /usr/src/app
2222

2323
USER app
2424

25-
EXPOSE 8000
25+
EXPOSE 4040
2626
COPY --from=runner /app/codebattle_runner /runner/codebattle_runner
2727
ENTRYPOINT ["/runner/codebattle_runner"]

services/app/apps/runner/lib/runner/languages.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ defmodule Runner.Languages do
4040
checker_version: 2,
4141
output_version: 2,
4242
generate_checker?: false,
43-
version: "3.4.7",
43+
version: "4.0.1",
4444
container_run_timeout: "15s",
4545
check_dir: "check",
4646
solution_file_name: "solution.rb",
4747
checker_file_name: "checker.rb",
48-
image: "ghcr.io/hexlet-codebattle/ruby:3.4.7",
48+
image: "ghcr.io/hexlet-codebattle/ruby:4.0.1",
4949
solution_template: """
5050
def solution(<%= arguments %>)
5151
ans = <%= default_value %>
@@ -514,12 +514,12 @@ defmodule Runner.Languages do
514514
checker_version: 2,
515515
output_version: 2,
516516
generate_checker?: false,
517-
version: "3.14.0",
517+
version: "3.14.2",
518518
check_dir: "check",
519519
container_run_timeout: "15s",
520520
solution_file_name: "solution.py",
521521
checker_file_name: "checker.py",
522-
image: "ghcr.io/hexlet-codebattle/python:3.14.0",
522+
image: "ghcr.io/hexlet-codebattle/python:3.14.2",
523523
solution_template: """
524524
from typing import List, Dict
525525

services/app/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ config :codebattle, :oauth,
7171
config :codebattle, :start_create_bot_timeout, to_timeout(second: 3)
7272
config :codebattle, :tournament_run_upcoming, false
7373
config :codebattle, app_version: System.get_env("APP_VERSION", "dev")
74-
# config :codebattle, checker_executor: Codebattle.CodeCheck.Executor.RemoteRust
74+
# config :codebattle, checker_executor: Codebattle.CodeCheck.Executor.RemoteZig
7575
config :codebattle, asserts_executor: Codebattle.AssertsService.Executor.Remote
7676
config :codebattle, chat_bot_token: System.get_env("CODEBATTLE_CHAT_BOT_TOKEN", "chat_bot")
7777
config :codebattle, checker_executor: Codebattle.CodeCheck.Executor.RemoteContainerRun

services/app/config/releases.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tournament_rematch_timeout_ms =
1414

1515
checker_executor =
1616
case System.get_env("CODEBATTLE_EXECUTOR") do
17-
"rust" -> Codebattle.CodeCheck.Executor.RemoteRust
17+
"zig" -> Codebattle.CodeCheck.Executor.RemoteZig
1818
_ -> Codebattle.CodeCheck.Executor.RemoteContainerRun
1919
end
2020

@@ -158,7 +158,8 @@ config :runner, container_killer: System.get_env("RUNNER_CONTAINER_KILLER", "")
158158
config :runner, cpu_logger: System.get_env("RUNNER_CPU_LOGGER", "") == "true"
159159

160160
config :runner,
161-
max_parallel_containers_run: "CODEBATTLE_MAX_PARALLEL_CONTAINERS_RUN" |> System.get_env("16") |> String.to_integer()
161+
max_parallel_containers_run:
162+
"CODEBATTLE_MAX_PARALLEL_CONTAINERS_RUN" |> System.get_env("16") |> String.to_integer()
162163

163164
config :runner, pull_images: System.get_env("RUNNER_PULL_IMAGES", "") == "true"
164165

services/app/config/test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ checker_executor =
44
case System.get_env("CODEBATTLE_EXECUTOR") do
55
"local" -> Codebattle.CodeCheck.Executor.Local
66
"remote" -> Codebattle.CodeCheck.Executor.RemoteContainerRun
7-
"rust" -> Codebattle.CodeCheck.Executor.RemoteRust
7+
"zig" -> Codebattle.CodeCheck.Executor.RemoteZig
88
_ -> Codebattle.CodeCheck.Executor.Fake
99
end
1010

0 commit comments

Comments
 (0)