Skip to content

Commit

Permalink
add yahns
Browse files Browse the repository at this point in the history
  • Loading branch information
kenballus committed Nov 30, 2024
1 parent 3f905d5 commit 6a9bb4d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions images/yahns/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM http-garden-soil:latest

RUN apt -y update && apt -y upgrade && apt -y install ruby-dev ragel && gem install raindrops kgio olddoc rack sleepy_penguin kcar

ARG PARSER_REPO
RUN git clone --recurse-submodules "$PARSER_REPO"

ARG PARSER_VERSION
RUN cd /app/unicorn && git pull && git checkout "$PARSER_VERSION" && export LC_ALL=C.UTF-8 && make -j$(nproc) install-gem

ARG APP_REPO
RUN git clone --recurse-submodules "$APP_REPO"

ARG APP_VERSION
COPY patch.diff .
RUN cd /app/yahns && git pull && git apply /app/patch.diff && git checkout "$APP_VERSION" && make install-gem

COPY yahns.conf .

ARG CONFIG_FILE
COPY $CONFIG_FILE ./config.ru
ARG BACKEND
RUN sed -i "s/PROXY_BACKEND_PLACEHOLDER/$BACKEND/g" config.ru

CMD ["yahns", "-c", "yahns.conf"]
13 changes: 13 additions & 0 deletions images/yahns/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 826eb8d..5b40018 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -8,6 +8,8 @@
rescue LoadError
end

+require 'kgio'
+
class Yahns::HttpClient < Kgio::Socket # :nodoc:
NULL_IO = StringIO.new(''.dup) # :nodoc:

2 changes: 2 additions & 0 deletions images/yahns/proxy.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'yahns/proxy_pass'
run Yahns::ProxyPass.new('http://PROXY_BACKEND_PLACEHOLDER')
21 changes: 21 additions & 0 deletions images/yahns/server.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'json'
require 'base64'

class Server
def call(env)
result = {}
result['headers'] = []
env.each do |key, value|
if not ["QUERY_STRING", "REQUEST_METHOD", "REQUEST_PATH", "PATH_INFO", "REQUEST_URI", "SERVER_PROTOCOL", "HTTP_VERSION", "rack.url_scheme", "SERVER_NAME", "SERVER_PORT", "REMOTE_ADDR", "rack.hijack", "rack.input", "rack.errors", "rack.multiprocess", "rack.multithread", "rack.run_once", "rack.hijack?", "rack.version", "SCRIPT_NAME", "SERVER_SOFTWARE", "rack.logger", "rack.tempfiles"].include?(key)
result['headers'].push([Base64.encode64(key.sub(/\AHTTP_/, "")).strip(), Base64.encode64(value).strip()])
end
end
result['method'] = Base64.encode64(env["REQUEST_METHOD"]).strip()
result['uri'] = Base64.encode64(env["REQUEST_URI"]).strip()
result['body'] = Base64.encode64(env["rack.input"].read).strip()
result['version'] = Base64.encode64(env["SERVER_PROTOCOL"]).strip()
[200, {}, [result.to_json]]
end
end

run Server.new
3 changes: 3 additions & 0 deletions images/yahns/yahns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app(:rack, "/app/config.ru", preload: true) do
listen 80
end

0 comments on commit 6a9bb4d

Please sign in to comment.