From 40fb7f8a45bba5aa9e4c87fe5440bed5a84888c8 Mon Sep 17 00:00:00 2001 From: gi8 Date: Wed, 20 Nov 2024 16:15:45 +0100 Subject: [PATCH] remove wrapper --- Dockerfile | 15 +----------- wrapper.c | 67 ------------------------------------------------------ 2 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 wrapper.c diff --git a/Dockerfile b/Dockerfile index 23a0755..0a2f44c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,3 @@ -# Step 1: Build the wrapper -FROM alpine:3.20 as wrapper-builder - -RUN apk add --no-cache gcc musl-dev make - -COPY wrapper.c /src/wrapper.c - -RUN gcc -o /wrapper /src/wrapper.c -static && chmod +x /wrapper - -# Step 2: Download kubectl binary FROM alpine:3.20 as downloader # renovate: datasource=github-tags depName=kubernetes/kubectl extractVersion=^kubernetes-(?.*)$ @@ -17,11 +7,8 @@ RUN apk add --no-cache curl && \ curl -LO "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" && \ chmod +x kubectl -# Step 3: Create the final minimal image FROM gcr.io/distroless/static-debian12:nonroot COPY --from=downloader /kubectl /usr/local/bin/kubectl -COPY --from=wrapper-builder /wrapper /usr/local/bin/wrapper -ENTRYPOINT ["/usr/local/bin/wrapper"] -CMD [ "kubectl" ] +ENTRYPOINT ["/usr/local/bin/kubectl"] diff --git a/wrapper.c b/wrapper.c deleted file mode 100644 index 8bf0f06..0000000 --- a/wrapper.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -#include -#include - -volatile sig_atomic_t terminate = 0; - -void handle_signal(int sig) { - terminate = 1; -} - -int main(int argc, char *argv[]) { - if (argc < 2) { - fprintf(stderr, "Usage: %s [arguments...]\n", argv[0]); - return EXIT_FAILURE; - } - - // Set up signal handling for SIGINT and SIGTERM - struct sigaction sa = {0}; - sa.sa_handler = handle_signal; - sa.sa_flags = SA_RESTART; // Automatically restart interrupted system calls - if (sigaction(SIGINT, &sa, NULL) == -1 || sigaction(SIGTERM, &sa, NULL) == -1) { - perror("Failed to set signal handlers"); - return EXIT_FAILURE; - } - - // Fork the process to execute the command - pid_t pid = fork(); - if (pid < 0) { - perror("Failed to fork"); - return EXIT_FAILURE; - } - - if (pid == 0) { - // Child process: Execute the command - execvp(argv[1], &argv[1]); - perror("Failed to execute command"); - _exit(EXIT_FAILURE); - } - - // Parent process: Monitor the child process - int status; - while (!terminate) { - if (waitpid(pid, &status, 0) == -1) { - if (terminate) break; // Exit loop if signal was caught - perror("Error while waiting for child process"); - return EXIT_FAILURE; - } - - if (WIFEXITED(status)) { - return WEXITSTATUS(status); // Child exited normally - } - - if (WIFSIGNALED(status)) { - fprintf(stderr, "Child process terminated by signal %d\n", WTERMSIG(status)); - return EXIT_FAILURE; - } - } - - // Handle termination signal - kill(pid, SIGTERM); - waitpid(pid, &status, 0); // Ensure child is reaped - return EXIT_FAILURE; -} -