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

chore: Docker build #10

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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
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"]