Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add file/line to tox-bootstrapd stdout/stderr logging. #2855

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions other/bootstrap_daemon/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###########################################################
# Builder image: we compile the code here (static build)
FROM alpine:3.19.0 AS build
FROM alpine:3.21.0 AS build

RUN ["apk", "--no-cache", "add",\
"clang",\
Expand All @@ -26,33 +26,32 @@ COPY other/bootstrap_node_packets.[ch] other/
COPY other/DHT_bootstrap.c other/
COPY other/pkgconfig other/pkgconfig
COPY other/rpm other/rpm
COPY testing/misc_tools.[ch] testing/
COPY testing testing
COPY toxcore toxcore
COPY toxencryptsave toxencryptsave
COPY third_party third_party
COPY CMakeLists.txt so.version ./
COPY other/bootstrap_daemon/CMakeLists.txt other/bootstrap_daemon/CMakeLists.txt
COPY testing/CMakeLists.txt testing/CMakeLists.txt

RUN CC=clang cmake -B_build -H. \
-GNinja \
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fsanitize=alignment,return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow,null -fsanitize-trap=all -fstack-protector-all" \
-DCMAKE_UNITY_BUILD=ON \
-DCMAKE_BUILD_TYPE=Release \
-DFULLY_STATIC=ON \
-DMIN_LOGGER_LEVEL=DEBUG \
-DBUILD_TOXAV=OFF \
-DBOOTSTRAP_DAEMON=ON && \
cmake --build _build --target install
-GNinja \
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fsanitize=alignment,return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow,null -fsanitize-trap=all -fstack-protector-all" \
-DCMAKE_UNITY_BUILD=ON \
-DCMAKE_BUILD_TYPE=Release \
-DFULLY_STATIC=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DBUILD_TOXAV=OFF \
-DBOOTSTRAP_DAEMON=ON \
&& cmake --build _build --target install

# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
# mess with your binaries.
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
ARG CHECK=sha256sum
RUN SHA256="$("$CHECK" /usr/local/bin/tox-bootstrapd)" && \
("$CHECK" -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" && \
false))
RUN SHA256="$("$CHECK" /usr/local/bin/tox-bootstrapd)" \
&& ("$CHECK" -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" \
&& false))

# Remove all the example bootstrap nodes from the config file.
COPY other/bootstrap_daemon/tox-bootstrapd.conf other/bootstrap_daemon/
Expand All @@ -69,12 +68,14 @@ FROM debian:bookworm-slim

COPY --from=build /usr/local/bin/tox-bootstrapd /usr/local/bin/
COPY --from=build /src/c-toxcore/other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
RUN useradd --home-dir /var/lib/tox-bootstrapd --create-home \
--system --shell /sbin/nologin \
--comment "Account to run the Tox DHT bootstrap daemon" \
--user-group tox-bootstrapd && \
chmod 644 /etc/tox-bootstrapd.conf && \
chmod 700 /var/lib/tox-bootstrapd
RUN useradd \
--home-dir /var/lib/tox-bootstrapd \
--create-home \
--system --shell /sbin/nologin \
--comment "Account to run the Tox DHT bootstrap daemon" \
--user-group tox-bootstrapd \
&& chmod 644 /etc/tox-bootstrapd.conf \
&& chmod 700 /var/lib/tox-bootstrapd

WORKDIR /var/lib/tox-bootstrapd

Expand Down
22 changes: 22 additions & 0 deletions other/bootstrap_daemon/docker/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Very selectively add files to the image, because we may have random stuff
# lying around. In particular, we don't need to rebuild the docker image when
# toxav changes or the Dockerfile changes down from the build.
**/*
!cmake/*
!other/bootstrap_daemon/bash-completion/*
!other/bootstrap_daemon/docker/get-nodes.py
!other/bootstrap_daemon/docker/tox-bootstrapd.sha256
!other/bootstrap_daemon/src/*
!other/bootstrap_daemon/tox-bootstrapd.conf
!other/bootstrap_node_packets.[ch]
!other/DHT_bootstrap.c
!other/pkgconfig/*
!other/rpm/*
!testing/misc_tools.[ch]
!toxcore/**/*
!toxencryptsave/**/*
!third_party/cmp/cmp.[ch]
!CMakeLists.txt
!so.version
!other/bootstrap_daemon/CMakeLists.txt
!testing/CMakeLists.txt
12 changes: 12 additions & 0 deletions other/bootstrap_daemon/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -eux -o pipefail

GIT_ROOT="$(git rev-parse --show-toplevel)"
cd "$GIT_ROOT"

docker build \
-t toxchat/bootstrap-node \
-f other/bootstrap_daemon/docker/Dockerfile \
--build-arg CHECK=true \
.
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9ec2993a28988bd147bf8f4f21a824c2fc5dbf7255e391b3ce517d337ebce5c1 /usr/local/bin/tox-bootstrapd
82b1733dea0f650607da7759ec79c827eede6f4646ac1c1afc832ca924e0e3c3 /usr/local/bin/tox-bootstrapd
23 changes: 15 additions & 8 deletions other/bootstrap_daemon/src/command_line_arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
#include "command_line_arguments.h"

#include "global.h"
#include "global.h" // IWYU pragma: keep
#include "log.h"

#include "../../../toxcore/ccompat.h"
Expand All @@ -26,7 +26,7 @@ static void print_help(void)
// 2 space indent
// Make sure all lines fit into 80 columns
// Make sure options are listed in alphabetical order
log_write(LOG_LEVEL_INFO,
LOG_WRITE(LOG_LEVEL_INFO,
"Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n"
"\n"
"Options:\n"
Expand All @@ -43,6 +43,7 @@ static void print_help(void)
" Default option when no --log-backend is\n"
" specified.\n"
" stdout Writes log messages to stdout/stderr.\n"
" --trace Enable verbose network trace logging in toxcore.\n"
" --version Print version information.\n");
}

Expand All @@ -51,7 +52,7 @@ Cli_Status handle_command_line_arguments(
bool *run_in_foreground)
{
if (argc < 2) {
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
LOG_WRITE(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
print_help();
return CLI_STATUS_ERROR;
}
Expand All @@ -64,6 +65,7 @@ Cli_Status handle_command_line_arguments(
{"help", no_argument, nullptr, 'h'},
{"log-backend", required_argument, nullptr, 'l'}, // optional, defaults to syslog
{"version", no_argument, nullptr, 'v'},
{"trace", no_argument, nullptr, 't'},
{nullptr, 0, nullptr, 0 }
};

Expand Down Expand Up @@ -99,24 +101,29 @@ Cli_Status handle_command_line_arguments(
*log_backend = LOG_BACKEND_STDOUT;
log_backend_set = true;
} else {
log_write(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
LOG_WRITE(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
print_help();
return CLI_STATUS_ERROR;
}

break;

case 'v':
log_write(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
LOG_WRITE(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
return CLI_STATUS_DONE;

case 't':
LOG_WRITE(LOG_LEVEL_INFO, "Enabling trace logging in toxcore.\n");
log_enable_trace(true);
break;

case '?':
log_write(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
LOG_WRITE(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
print_help();
return CLI_STATUS_ERROR;

case ':':
log_write(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
LOG_WRITE(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
print_help();
return CLI_STATUS_ERROR;
}
Expand All @@ -127,7 +134,7 @@ Cli_Status handle_command_line_arguments(
}

if (!cfg_file_path_set) {
log_write(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
LOG_WRITE(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
print_help();
return CLI_STATUS_ERROR;
}
Expand Down
Loading
Loading