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.
This commit is contained in:
ICScaryThings 2022-06-28 23:02:34 -04:00
parent 30eb79a018
commit 2c090f71df
5 changed files with 76 additions and 0 deletions

23
Dockerfile.build Normal file
View File

@ -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

7
build_container.sh Executable file
View File

@ -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 .

View File

@ -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)

View File

@ -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 <string.h>
#include <mastodont.h>
#include <stdlib.h>
-#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();

4
run_container.sh Executable file
View File

@ -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