From bc55de171cb8fc9ff72eb634eee4483888428175 Mon Sep 17 00:00:00 2001 From: heronimus Date: Thu, 3 Oct 2024 23:41:44 +0700 Subject: [PATCH 1/3] chore: add Dockerfile, update CMake build definition --- CMakeLists.txt | 3 +++ Dockerfile | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dockerfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 381c045..9bd21bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,3 +61,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON ) + +#Set Linker flags +set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eda7266 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,65 @@ +# Build stage +FROM debian:trixie-slim AS build + +# Install necessary build tools and dependencies +RUN apt-get update && apt-get install -y \ + g++ \ + cmake \ + make \ + git \ + wget \ + libcurl4-openssl-dev \ + zlib1g-dev \ + ca-certificates \ + libssl-dev \ + libopus0 \ + libopus-dev \ + libsodium-dev \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /app + +# Copy the source code +COPY . . + +# Create build directory +RUN mkdir build + +# Build the project +WORKDIR /app/build +RUN wget -O libdpp.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.0.23/libdpp-10.0.23-linux-x64.deb \ + && dpkg -i libdpp.deb \ + && ldconfig +RUN cmake -DUSE_EXTERNAL_JSON=OFF .. -B./ && make + +# Run stage +FROM debian:trixie-slim AS runtime + +# Install runtime dependencies & libraries +RUN apt-get update && apt-get install -y \ + ca-certificates \ + libopus0 \ + libopus-dev \ + libsodium-dev \ + libcurl4-openssl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user +RUN useradd -m -s /bin/bash appuser + +# Set the working directory +WORKDIR /app + +# Add external library libdpp +COPY --from=build /app/build/libdpp.deb . +RUN dpkg -i libdpp.deb && rm libdpp.deb + +# Copy the built executable from the build stage +COPY --from=build --chown=appuser:appuser /app/build/asiantbd_bot . + +# Switch to non-root user +USER appuser + +# Set the entrypoint +ENTRYPOINT ["/app/asiantbd_bot"] From 9cfda7d1dfe6f3fd07d55d56dfad9921c353b803 Mon Sep 17 00:00:00 2001 From: heronimus Date: Thu, 3 Oct 2024 23:42:17 +0700 Subject: [PATCH 2/3] ci: update build action, add docker build --- .github/workflows/action.yml | 21 --------------------- .github/workflows/build.yml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 .github/workflows/action.yml create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml deleted file mode 100644 index 711b383..0000000 --- a/.github/workflows/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: C/C++ CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev -y - - name: Apply Configure - run: ./configure - - name: Cmake With Fetching External Dependencies - run: cmake -DUSE_EXTERNAL_DPP=OFF -DUSE_EXTERNAL_JSON=OFF - - name: Make - run: make diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ad5bc16 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + cmake: + name: CMake + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev -y + - name: Apply Configure + run: ./configure + - name: Cmake With Fetching External Dependencies + run: cmake -DUSE_EXTERNAL_DPP=OFF -DUSE_EXTERNAL_JSON=OFF + - name: Make + run: make + docker: + name: Docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker Build + run: | + docker build --platform=linux/amd64 -t asiantbd/crypto-prices-slash-bot . From f2ce1fa0559458fb5f33879190d4566a377c0a00 Mon Sep 17 00:00:00 2001 From: heronimus Date: Fri, 4 Oct 2024 00:02:58 +0700 Subject: [PATCH 3/3] ci: update build action format --- .github/workflows/build.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad5bc16..c3946fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,13 +14,15 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev -y + run: | + sudo apt-get update + sudo apt-get install cmake make libcurl4-openssl-dev -y - name: Apply Configure run: ./configure - - name: Cmake With Fetching External Dependencies - run: cmake -DUSE_EXTERNAL_DPP=OFF -DUSE_EXTERNAL_JSON=OFF - - name: Make - run: make + - name: CMake With Fetching External Dependencies + run: | + cmake -DUSE_EXTERNAL_DPP=OFF -DUSE_EXTERNAL_JSON=OFF + make docker: name: Docker runs-on: ubuntu-latest