From bfd1f305e8066e2b3a92e2beaea400a12eb74779 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Fri, 28 Feb 2025 11:15:37 +0100 Subject: [PATCH] Add dockerfile --- .gitignore | 3 ++- CMakeLists.txt | 8 +++++++- Dockerfile | 12 ++++++++++++ builder.Dockerfile | 3 +++ quote.h | 6 ++---- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 builder.Dockerfile diff --git a/.gitignore b/.gitignore index cf99bf6..cc6b551 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Project exclude paths /cmake-build-debug/ -/.idea/ \ No newline at end of file +/.idea/ +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bb56d9..0228fe9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,12 @@ cmake_minimum_required(VERSION 3.19) project(qotd C) +message("STATIC_BUILD=${STATIC_BUILD}") + set(CMAKE_C_STANDARD 99) -add_executable(qotd main.c quote.c quote.h server.c server.h config.h) \ No newline at end of file +add_executable(qotd main.c quote.c quote.h server.c server.h config.h) + +if ( STATIC_BUILD ) + target_link_libraries(qotd -static) +endif() \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cc35805 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM git.legonzaur.fr/legonzaur/qotd/builder:latest AS builder + +WORKDIR /opt/builder + +COPY . . +RUN cmake -B build -DSTATIC_BUILD=true +WORKDIR build +RUN make + +FROM alpine +COPY --from=builder /opt/builder/build/qotd / +ENTRYPOINT ["/qotd"] \ No newline at end of file diff --git a/builder.Dockerfile b/builder.Dockerfile new file mode 100644 index 0000000..f48e37e --- /dev/null +++ b/builder.Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:latest + +RUN apk add --no-cache cmake make gcc musl-dev diff --git a/quote.h b/quote.h index b7deeda..b34e1ad 100644 --- a/quote.h +++ b/quote.h @@ -8,13 +8,11 @@ #include #include #include -#include -#include void getRandomQuote(char quote[2048]); void getQuote(long line, char quote[2048]); -int getFileLineCount(char* filename); +int getFileLineCount(char *filename); -#endif //QOTD_QUOTE_H +#endif // QOTD_QUOTE_H