From 2c090f71df829d1803fd5eb35ae1a70d7b5c8661 Mon Sep 17 00:00:00 2001 From: ICScaryThings Date: Tue, 28 Jun 2022 23:02:34 -0400 Subject: [PATCH] Reworked container build to allow setting instance url at runtime I patched neko's code to use getenv() to grab instance url at startup and store it as a global rather than static const. --- Dockerfile.build | 23 +++++++++++++++++++++++ build_container.sh | 7 +++++++ files/instance_env_config.h.patch | 13 +++++++++++++ files/instance_env_main.c.patch | 29 +++++++++++++++++++++++++++++ run_container.sh | 4 ++++ 5 files changed, 76 insertions(+) create mode 100644 Dockerfile.build create mode 100755 build_container.sh create mode 100644 files/instance_env_config.h.patch create mode 100644 files/instance_env_main.c.patch create mode 100755 run_container.sh diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..0d7502e --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,23 @@ +# Container just for building the code and debug +FROM debian:testing + +ENV BUILD_REQ="build-essential libcurl4-gnutls-dev libcjson-dev libpcre3-dev libfcgi-dev git pkgconf libpcre2-dev" + +RUN apt update && apt upgrade -y +RUN apt install -y $BUILD_REQ fcgiwrap + +WORKDIR /usr/local/src/treebird + +# original source +COPY treebird/ . +COPY mastodont-c ./mastodont-c +COPY treebird/config.def.h ./config.h + +# patch or override files +COPY files/ . +RUN patch -p1 < instance_env_config.h.patch && patch -p1 < instance_env_main.c.patch + +RUN make && make install + +# defined only for debugging reasons +CMD fcgiwrap -c 10 -f -s tcp:0.0.0.0:4008 diff --git a/build_container.sh b/build_container.sh new file mode 100755 index 0000000..a180b6b --- /dev/null +++ b/build_container.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# builds the 'build' image for compiling and testing + +git submodule init +git submodule update + +docker build -t treebird:build -f Dockerfile.build . diff --git a/files/instance_env_config.h.patch b/files/instance_env_config.h.patch new file mode 100644 index 0000000..5c6518d --- /dev/null +++ b/files/instance_env_config.h.patch @@ -0,0 +1,13 @@ +diff --git a/config.def.h b/config.def.h +index a5eed39..0359cd5 100644 +--- a/config.h ++++ b/config.h +@@ -32,7 +32,7 @@ static char* const config_canonical_name = "treebird"; + * + * Example: "https://shitposter.club/" + */ +-static char* const config_instance_url = "https://my-instance.social/"; ++extern char* config_instance_url; + + /* + * OPTIONAL - Mainly for development (or broken servers) diff --git a/files/instance_env_main.c.patch b/files/instance_env_main.c.patch new file mode 100644 index 0000000..ba1d949 --- /dev/null +++ b/files/instance_env_main.c.patch @@ -0,0 +1,29 @@ +diff --git a/src/main.c b/src/main.c +index fc5cc79..6f3d8bc 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -20,7 +20,6 @@ + #include + #include + #include +-#include "../config.h" + #include "index.h" + #include "page_config.h" + #include "path.h" +@@ -41,10 +40,16 @@ + #include "local_config_set.h" + #include "global_cache.h" + ++// global accessed elsewhere via extern def in config.h ++char* config_instance_url = NULL; ++ + int main(void) + { + unsigned run_count = 1; + ++ // Env config ++ config_instance_url = getenv("TREEBIRD_CFG_INSTANCE_URL"); ++ + // Global init + mastodont_global_curl_init(); + diff --git a/run_container.sh b/run_container.sh new file mode 100755 index 0000000..347a144 --- /dev/null +++ b/run_container.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# runs the treebird image as a docker daemon + +docker run --rm --name treebird -p 4008:4008 -e TREEBIRD_CFG_INSTANCE_URL="https://sleepy.cafe/" -d treebird:build