Skip to content

Commit

Permalink
chore: Docker build (#10)
Browse files Browse the repository at this point in the history
* chore: add Dockerfile, update CMake build definition

* ci: update build action, add docker build

* ci: update build action format
  • Loading branch information
heronimus authored Oct 4, 2024
1 parent 51b1467 commit a856fd3
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 21 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/action.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 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
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 .
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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++")
65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit a856fd3

Please sign in to comment.