'Generic Commit'
Some checks failed
dropshell-build / build (push) Has been cancelled

This commit is contained in:
Your Name 2025-06-06 18:36:58 +12:00
parent 40bbd8684d
commit a961bd37e6
4 changed files with 94 additions and 26 deletions

View File

@ -34,10 +34,66 @@ RUN apk add --no-cache \
elfutils-dev \ elfutils-dev \
elfutils-libelf \ elfutils-libelf \
binutils \ binutils \
binutils-dev binutils-dev \
pipx \
openssl-dev \
sqlite-dev \
libpq-dev \
mariadb-connector-c-dev \
c-ares-dev \
jsoncpp-dev \
ninja \
util-linux-dev \
util-linux-static \
perl
#RUN apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ libexecinfo-dev #RUN apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ libexecinfo-dev
SHELL ["/bin/bash", "-c"]
# Build OpenSSL statically with musl
ARG OPENSSL_VERSION=3.3.0
WORKDIR /tmp
RUN curl -LO https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz && \
tar xzf openssl-${OPENSSL_VERSION}.tar.gz && \
cd openssl-${OPENSSL_VERSION} && \
./Configure no-shared no-dso no-tests no-async linux-x86_64 \
--prefix=/usr/local/openssl-musl \
-static -fPIC && \
make -j$(nproc) && \
make install_sw && \
cd / && rm -rf /tmp/openssl-${OPENSSL_VERSION} /tmp/openssl-${OPENSSL_VERSION}.tar.gz
#ARG DROGON_VERSION=1.9.5
RUN git clone --recurse-submodules https://github.com/drogonframework/drogon.git /tmp/drogon && \
#RUN git clone --branch v${DROGON_VERSION} --depth 1 https://github.com/drogonframework/drogon.git /tmp/drogon && \
mkdir -p /tmp/drogon/build && \
cd /tmp/drogon/build && \
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_CXX_FLAGS="-static -static-libgcc -static-libstdc++" \
-DCMAKE_EXE_LINKER_FLAGS="-static" \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
-DUSE_MONGODB=OFF \
-DUSE_POSTGRESQL=ON \
-DUSE_MYSQL=ON \
-DUSE_SQLITE3=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DUUID_LIBRARY=/usr/lib/libuuid.a \
-DOPENSSL_ROOT_DIR=/usr/local/openssl-musl \
-DOPENSSL_USE_STATIC_LIBS=TRUE \
&&\
make -j$(nproc) && \
make install && \
cd / && rm -rf /tmp/drogon
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
@ -78,3 +134,4 @@ ARG PROJECT
# Copy the actual binary from the regular directory # Copy the actual binary from the regular directory
COPY --from=builder /output/${PROJECT} /${PROJECT} COPY --from=builder /output/${PROJECT} /${PROJECT}

View File

@ -1,18 +0,0 @@
[requires]
drogon/1.9.1
[generators]
cmake_find_package
cmake_paths
cmake_find_package_multi
[options]
drogon:with_orm=True
drogon:with_postgres=True
drogon:with_sqlite3=True
drogon:with_redis=True
drogon:with_brotli=True
drogon:with_zlib=True
[build_requires]
cmake/3.28.3

View File

@ -72,6 +72,8 @@ target_include_directories(${PROJECT_EXE_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/autogen ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen
) )
# Add nlohmann/json # Add nlohmann/json
FetchContent_Declare( FetchContent_Declare(
nlohmann_json nlohmann_json
@ -93,9 +95,20 @@ set(EXTRA_LIBS
-ldl # For dladdr -ldl # For dladdr
) )
##########
# If you include the drogon source code locally in your project, use this method to add drogon
# add_subdirectory(external/drogon)
# target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
##########
find_package(Drogon CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
# Link libraries # Link libraries
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE target_link_libraries(${PROJECT_EXE_NAME} PRIVATE
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
Drogon::Drogon
${EXTRA_LIBS} ${EXTRA_LIBS}
) )

View File

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "httplib.hpp" #include <drogon/HttpClient.h>
#include "version.hpp" #include "version.hpp"
#include "assert.hpp" #include "assert.hpp"
@ -14,14 +14,30 @@ int main() {
std::cout << std::endl; std::cout << std::endl;
std::cout << "Retrieving IP address..." << std::endl; std::cout << "Retrieving IP address..." << std::endl;
httplib::Client cli("http://ipinfo.io"); auto loop = trantor::EventLoop::getEventLoopOfCurrentThread();
auto res = cli.Get("/ip"); auto client = drogon::HttpClient::newHttpClient("http://ipinfo.io", loop);
auto req = drogon::HttpRequest::newHttpRequest();
req->setMethod(drogon::Get);
req->setPath("/ip");
std::string ip_body;
int status = 0;
bool done = false;
client->sendRequest(req, [&](drogon::ReqResult result, const drogon::HttpResponsePtr &resp) {
if (result == drogon::ReqResult::Ok && resp) {
ip_body = resp->body();
status = resp->statusCode();
} else {
status = 0;
}
done = true;
});
while (!done) loop->loopOnce();
ASSERT(res->status == 200, "Failed to get IP"); ASSERT(status == 200, "Failed to get IP");
nlohmann::json j; nlohmann::json j;
j["ip"] = res->body; j["ip"] = ip_body;
j["status"] = res->status; j["status"] = status;
std::cout << j.dump(4) << std::endl; std::cout << j.dump(4) << std::endl;