summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsoler_j <soler_j@etna-alternance.net>2025-04-27 21:02:54 +0200
committersoler_j <soler_j@etna-alternance.net>2025-04-27 21:02:54 +0200
commitbef502c22566c78040e2c17d8ecaf4dcad650272 (patch)
tree7ec37738e2895912088ab015bb15c5492e0f8f15
parentd497fec2d9d32359428f63595989065c1c9cf5a8 (diff)
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.
-rw-r--r--.dockerignore24
-rw-r--r--.github/workflows/build.yml42
-rw-r--r--Dockerfile (renamed from DockerFile)45
-rw-r--r--app/cmd/main.go4
-rw-r--r--app/internal/create_bot.go2
-rw-r--r--bot/include/server.cpp1
-rw-r--r--devenv.nix3
7 files changed, 90 insertions, 31 deletions
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
index 13ef32a..36a2cbd 100644
--- a/DockerFile
+++ b/Dockerfile
@@ -2,25 +2,13 @@
FROM golang:1.23-alpine AS go-builder
WORKDIR /app
COPY app/ .
-RUN CGO_ENABLED=0 go build -o /api main.go
+RUN CGO_ENABLED=0 go build -o /api/app ./cmd/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
+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 && \
@@ -31,14 +19,17 @@ RUN mkdir -p /dpp/build && \
cd /dpp/build && \
cmake .. -DDPP_BUILD_TEST=OFF && \
make -j$(nproc) && \
- make install
+ make install && \
+ cp -r /dpp/include/dpp /usr/include/ && \
+ cp /usr/local/lib/libdpp* /usr/lib/
# Construction du bot utilisateur
-WORKDIR /bot
+WORKDIR /src
COPY bot/ .
-RUN mkdir -p build && \
- cd build && \
- cmake .. -DCMAKE_PREFIX_PATH=/dpp/build && \
+
+# Construction en pointant vers DPP installé localement
+RUN mkdir build && cd build && \
+ cmake .. && \
make -j$(nproc)
# Étape finale d'exécution
@@ -46,8 +37,9 @@ FROM alpine:3.21
WORKDIR /app
# Copie des binaires
-COPY --from=go-builder /api .
-COPY --from=cpp-builder /bot/build/bot .
+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 \
@@ -56,5 +48,6 @@ RUN apk add --no-cache \
zlib \
opus
-# Configuration des points d'entrée
-ENTRYPOINT ["/app/api"]
+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 <mutex>
#include <vector>
#include <queue>
+#include <algorithm> // Nécessaire pour std::remove_if
#include <functional>
#include <sys/socket.h>
#include <sys/un.h>
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