From bef502c22566c78040e2c17d8ecaf4dcad650272 Mon Sep 17 00:00:00 2001 From: soler_j Date: Sun, 27 Apr 2025 21:02:54 +0200 Subject: Suppression du fichier DockerFile, ajout d'un nouveau Dockerfile avec des étapes de compilation pour Go et C++, mise à jour des chemins d'accès et des dépendances, et ajout d'un fichier .dockerignore pour gérer les fichiers à ignorer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 24 ++++++++++++++++++ .github/workflows/build.yml | 42 +++++++++++++++++++++++++++++++ DockerFile | 60 --------------------------------------------- Dockerfile | 53 +++++++++++++++++++++++++++++++++++++++ app/cmd/main.go | 4 +-- app/internal/create_bot.go | 2 +- bot/include/server.cpp | 1 + devenv.nix | 3 +-- 8 files changed, 124 insertions(+), 65 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml delete mode 100644 DockerFile create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f041403 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,24 @@ +# Ignore any directory named build at any level +build/ +**/build/ + +# Ignore any file or directory with 'build' in its name +*build* +**/*build* + +# Ignore common build artifacts +*.o +*.obj +*.exe +*.out +*.a +*.so +*.dll +*.pyc +*.class + +# Optionally, ignore CMake and Make build folders +CMakeFiles/ +cmake-build-*/ +Makefile +CMakeCache.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..75b136a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: Build and Push Docker image + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + env: + IMAGE_NAME: ${{ github.repository }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push with cache + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.IMAGE_NAME }}:latest + platforms: linux/amd64,linux/arm64 + cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:cache + cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max diff --git a/DockerFile b/DockerFile deleted file mode 100644 index 13ef32a..0000000 --- a/DockerFile +++ /dev/null @@ -1,60 +0,0 @@ -# Étape de compilation pour le programme Go -FROM golang:1.23-alpine AS go-builder -WORKDIR /app -COPY app/ . -RUN CGO_ENABLED=0 go build -o /api main.go - -# Étape de compilation pour le programme C++ avec DPP -FROM ubuntu:24.04 AS cpp-builder - -# Installation des dépendances système -RUN apt-get update && \ - apt-get install -y \ - git \ - gcc \ - g++ \ - cmake \ - clang-tools \ - libssl-dev \ - zlib1g-dev \ - libopus-dev \ - pkg-config - -# Clonage de DPP avec le commit spécifique -RUN git clone https://github.com/brainboxdotcc/DPP.git /dpp && \ - cd /dpp && \ - git checkout c6bcab5b4632fe35e32e63e3bc813e9e2cd2893e && \ - git submodule update --init --recursive - -# Construction de DPP -RUN mkdir -p /dpp/build && \ - cd /dpp/build && \ - cmake .. -DDPP_BUILD_TEST=OFF && \ - make -j$(nproc) && \ - make install - -# Construction du bot utilisateur -WORKDIR /bot -COPY bot/ . -RUN mkdir -p build && \ - cd build && \ - cmake .. -DCMAKE_PREFIX_PATH=/dpp/build && \ - make -j$(nproc) - -# Étape finale d'exécution -FROM alpine:3.21 -WORKDIR /app - -# Copie des binaires -COPY --from=go-builder /api . -COPY --from=cpp-builder /bot/build/bot . - -# Installation des dépendances runtime -RUN apk add --no-cache \ - libstdc++ \ - libssl3 \ - zlib \ - opus - -# Configuration des points d'entrée -ENTRYPOINT ["/app/api"] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..36a2cbd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# Étape de compilation pour le programme Go +FROM golang:1.23-alpine AS go-builder +WORKDIR /app +COPY app/ . +RUN CGO_ENABLED=0 go build -o /api/app ./cmd/main.go + +# Étape de compilation pour le programme C++ avec DPP +FROM alpine:3.21 AS cpp-builder +RUN apk add --no-cache build-base cmake git openssl-dev zlib-dev opus-dev clang + +# Clonage de DPP +RUN git clone https://github.com/brainboxdotcc/DPP.git /dpp && \ + cd /dpp && \ + git checkout c6bcab5b4632fe35e32e63e3bc813e9e2cd2893e && \ + git submodule update --init --recursive + +# Construction de DPP +RUN mkdir -p /dpp/build && \ + cd /dpp/build && \ + cmake .. -DDPP_BUILD_TEST=OFF && \ + make -j$(nproc) && \ + make install && \ + cp -r /dpp/include/dpp /usr/include/ && \ + cp /usr/local/lib/libdpp* /usr/lib/ + +# Construction du bot utilisateur +WORKDIR /src +COPY bot/ . + +# Construction en pointant vers DPP installé localement +RUN mkdir build && cd build && \ + cmake .. && \ + make -j$(nproc) + +# Étape finale d'exécution +FROM alpine:3.21 +WORKDIR /app + +# Copie des binaires +COPY --from=go-builder /api ./api +COPY --from=cpp-builder /usr/local/lib/libdpp* /usr/lib/ +COPY --from=cpp-builder /src/build/discord-bot ./bot/build/discord-bot + +# Installation des dépendances runtime +RUN apk add --no-cache \ + libstdc++ \ + libssl3 \ + zlib \ + opus + +RUN chmod +x ./api/app ./bot/build/discord-bot + +ENTRYPOINT ["./api/app"] diff --git a/app/cmd/main.go b/app/cmd/main.go index 525482c..14980b7 100644 --- a/app/cmd/main.go +++ b/app/cmd/main.go @@ -23,8 +23,8 @@ func main() { mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, World!")) }) - botId := "XXXXX" - botToken := "XXXXX" + botId := "xxxxx" + botToken := "xxxxx" bot := &internal.Bot{ BotID: botId, diff --git a/app/internal/create_bot.go b/app/internal/create_bot.go index c1bea85..7f9aa15 100644 --- a/app/internal/create_bot.go +++ b/app/internal/create_bot.go @@ -25,7 +25,7 @@ func Start(b *Bot) (net.Conn, error) { } // Configuration du bot - cmd := exec.Command("../bot/build/discord-bot", b.BotToken) + cmd := exec.Command("./bot/build/discord-bot", b.BotToken) cmd.SysProcAttr = &syscall.SysProcAttr{ Setpgid: true, // Permet de kill le processus enfant si nécessaire } diff --git a/bot/include/server.cpp b/bot/include/server.cpp index 55e5df9..9425e85 100644 --- a/bot/include/server.cpp +++ b/bot/include/server.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // Nécessaire pour std::remove_if #include #include #include diff --git a/devenv.nix b/devenv.nix index c0e83be..dfa89c7 100644 --- a/devenv.nix +++ b/devenv.nix @@ -44,8 +44,7 @@ ''; scripts.start.exec = '' - cd app - go run cmd/main.go + go run app/cmd/main.go ''; # Supprimer la configuration brew inutile dans Nix -- cgit v1.2.3