diff --git a/puppy/Dockerfile b/puppy/Dockerfile index dab8e62..c539092 100644 --- a/puppy/Dockerfile +++ b/puppy/Dockerfile @@ -1,11 +1,13 @@ #check=skip=JSONArgsRecommended FROM debian:12-slim AS builder RUN apt-get update && DEBIAN_FRONTEND=noninteracive apt-get install -y \ - --no-install-recommends cmake g++-mingw-w64-i686-posix make && \ + --no-install-recommends cmake g++-mingw-w64-i686-posix g++ make && \ apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /build COPY . . +RUN g++ -o healthcheck -I./include ./app/healthcheck.cpp + RUN --mount=type=cache,target=cmake-build cmake -B cmake-build \ -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ && cmake --build cmake-build -j$(nproc) && \ cp cmake-build/promt-puppy.exe . @@ -13,21 +15,23 @@ RUN --mount=type=cache,target=cmake-build cmake -B cmake-build \ FROM debian:12-slim AS runner ENV WINEPREFIX=/wineprefix \ DEBIAN_FRONTEND=noninteracive -RUN sed -i 's/main/main contrib/' /etc/apt/sources.list.d/debian.sources && \ - dpkg --add-architecture i386 && apt-get update && \ +RUN dpkg --add-architecture i386 && apt-get update && \ apt-get install -y --no-install-recommends \ - wine wine64 wine32:i386 ca-certificates && \ + wine wine64 wine32:i386 && \ + apt-get clean && rm -rf /var/lib/apt/lists/* && \ wineboot -i && echo "Sleeping for 15 seconds..." && sleep 15 && \ - apt-get clean && rm -rf /var/lib/apt/lists/* + mkdir /tmpfs && ln -sf /tmpfs $WINEPREFIX/drive_c/tmpfs + COPY build/ $WINEPREFIX/drive_c RUN wine regedit $WINEPREFIX/drive_c/registry.reg && \ - mkdir /tmpfs && ln -sf /tmpfs $WINEPREFIX/drive_c/tmpfs && \ echo "Sleeping for 15 seconds" && sleep 15 WORKDIR /app -COPY --from=builder /build/promt-puppy.exe . +COPY --from=builder /build/promt-puppy.exe /build/healthcheck . + +HEALTHCHECK CMD ./healthcheck EXPOSE 80/tcp VOLUME /cache diff --git a/puppy/app/healthcheck.cpp b/puppy/app/healthcheck.cpp new file mode 100644 index 0000000..f5e023f --- /dev/null +++ b/puppy/app/healthcheck.cpp @@ -0,0 +1,6 @@ +#include "httplib.hpp" + +int main() { + auto res = httplib::Client("127.0.0.1", 80).Get("/health"); + return !(res && res->status == 200); +} diff --git a/puppy/app/main.cpp b/puppy/app/main.cpp index b1652f0..1acb218 100644 --- a/puppy/app/main.cpp +++ b/puppy/app/main.cpp @@ -4,16 +4,10 @@ #include #include #include -#include #include "PromtCtlDocument.hpp" #include "PromtFTManager.hpp" -template -static inline void print(T... args) { - ((std::cout << args << ' '), ...) << std::endl; -} - static inline std::string random_filename(int len = 65) { static const char ASCII_PRINTABLE[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; std::random_device random_device; @@ -26,10 +20,15 @@ static inline std::string random_filename(int len = 65) { return random_string; } -static const char TMP_FOLDER[] = "C:\\tmpfs\\"; +static constexpr std::string TMP_FOLDER = "C:\\tmpfs\\"; static const auto TMP_IN = TMP_FOLDER + random_filename(); static const auto TMP_OUT = TMP_FOLDER + random_filename(); +template +static inline void print(T... args) { + ((std::cout << args << ' '), ...) << std::endl; +} + static inline auto utf8_to_cp(const char *data) { int size = MultiByteToWideChar(CP_UTF8, 0, data, -1, 0, 0); auto wstr = new wchar_t[size]; @@ -86,7 +85,7 @@ class WebServer { ofs << utf8_to_cp(text.c_str()); } translator.Translate(TMP_IN, TMP_OUT); - res.set_content(read_file(TMP_OUT), "text/html"); + res.set_content(std::move(read_file(TMP_OUT)), "text/html"); } void TranslateText(const std::string &text, httplib::Response &res) { @@ -146,9 +145,13 @@ class WebServer { if (!std::filesystem::exists(TMP_FOLDER)) std::filesystem::create_directory(TMP_FOLDER); m_svr.Post("/translate", [this](const httplib::Request &req, httplib::Response &res) { - print("Got request!"); TranslateHandler(req, res); }); + + m_svr.Get("/health", [](const httplib::Request &req, httplib::Response &res) { + res.set_content("OK", "text/plain"); + res.status = 200; + }); } ~WebServer() {