feat: add healthcheck feature and update Dockerfile for build process
This commit is contained in:
parent
e78ac289f7
commit
ef2f477fcd
3 changed files with 29 additions and 16 deletions
|
@ -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
|
||||
|
|
6
puppy/app/healthcheck.cpp
Normal file
6
puppy/app/healthcheck.cpp
Normal file
|
@ -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);
|
||||
}
|
|
@ -4,16 +4,10 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <random>
|
||||
|
||||
#include "PromtCtlDocument.hpp"
|
||||
#include "PromtFTManager.hpp"
|
||||
|
||||
template<typename... T>
|
||||
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<typename... T>
|
||||
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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue