From a5ea47afc91bebfa1229263e41b7aac031c49576 Mon Sep 17 00:00:00 2001 From: garder500 Date: Tue, 28 Oct 2025 18:39:11 +0100 Subject: Ajouter un workflow de construction pour les binaires Go et les images Docker multi-architecture --- .github/workflows/build.yml | 164 ++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 6 +- 2 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5732360 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,164 @@ +name: Build + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + # Build Go binaries for multiple platforms + build-binaries: + name: Build Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + include: + # Linux AMD64 + - goos: linux + goarch: amd64 + output: sovrabase-linux-amd64 + # Linux ARM64 + - goos: linux + goarch: arm64 + output: sovrabase-linux-arm64 + # macOS AMD64 (Intel) + - goos: darwin + goarch: amd64 + output: sovrabase-darwin-amd64 + # macOS ARM64 (Apple Silicon) + - goos: darwin + goarch: arm64 + output: sovrabase-darwin-arm64 + # Windows AMD64 + - goos: windows + goarch: amd64 + output: sovrabase-windows-amd64.exe + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25.2' + cache: true + + - name: Download dependencies + run: go mod download + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + run: | + go build -ldflags="-w -s" -o ${{ matrix.output }} ./cmd/server/main.go + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.output }} + path: ${{ matrix.output }} + retention-days: 7 + + # Build Docker images for multiple architectures + build-docker: + name: Build Docker Image + strategy: + matrix: + include: + # AMD64 on Ubuntu + - runner: ubuntu-latest + platform: linux/amd64 + arch: amd64 + # ARM64 on Ubuntu ARM runner + - runner: ubuntu-24.04-arm + platform: linux/arm64 + arch: arm64 + + runs-on: ${{ matrix.runner }} + + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: ${{ matrix.platform }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + TARGETARCH=${{ matrix.arch }} + cache-from: type=gha + cache-to: type=gha,mode=max + provenance: false + + # Create manifest list to combine both architectures + create-manifest: + name: Create Multi-arch Manifest + needs: build-docker + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + + permissions: + contents: read + packages: write + + steps: + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create and push manifest + run: | + # Extract branch or tag name + BRANCH=${GITHUB_REF##*/} + SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7) + + # Create manifest for branch tag + docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH} \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT} + + # Create manifest for latest tag if on default branch + if [ "${{ github.ref }}" = "refs/heads/main" ] || [ "${{ github.ref }}" = "refs/heads/master" ]; then + docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT} + fi diff --git a/Dockerfile b/Dockerfile index 9fffe62..920a40e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # Stage 1: Build FROM golang:1.25.2-alpine AS builder +# Build arguments for multi-architecture support +ARG TARGETARCH + # Install build dependencies RUN apk add --no-cache git ca-certificates tzdata @@ -18,7 +21,8 @@ COPY . . # Build the application # CGO_ENABLED=0 for static binary # -ldflags="-w -s" to strip debug info and reduce binary size -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ +# TARGETARCH will be automatically set by Docker buildx (amd64 or arm64) +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build \ -ldflags="-w -s" \ -o sovrabase \ ./cmd/server/main.go -- cgit v1.2.3 From 6e1964802e79ff0de87b3bae903e04ef400e1202 Mon Sep 17 00:00:00 2001 From: garder500 Date: Tue, 28 Oct 2025 18:39:16 +0100 Subject: Supprimer les lignes vides inutiles dans le workflow de construction --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5732360..d9548ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,7 +39,7 @@ jobs: - goos: windows goarch: amd64 output: sovrabase-windows-amd64.exe - + steps: - name: Checkout code uses: actions/checkout@v4 @@ -82,13 +82,13 @@ jobs: - runner: ubuntu-24.04-arm platform: linux/arm64 arch: arm64 - + runs-on: ${{ matrix.runner }} - + permissions: contents: read packages: write - + steps: - name: Checkout code uses: actions/checkout@v4 @@ -134,11 +134,11 @@ jobs: needs: build-docker runs-on: ubuntu-latest if: github.event_name != 'pull_request' - + permissions: contents: read packages: write - + steps: - name: Log in to Container Registry uses: docker/login-action@v3 @@ -152,11 +152,11 @@ jobs: # Extract branch or tag name BRANCH=${GITHUB_REF##*/} SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7) - + # Create manifest for branch tag docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT} - + # Create manifest for latest tag if on default branch if [ "${{ github.ref }}" = "refs/heads/main" ] || [ "${{ github.ref }}" = "refs/heads/master" ]; then docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ -- cgit v1.2.3 From 41d0c01a887d81817a24456bc28b332aa5dcb72c Mon Sep 17 00:00:00 2001 From: garder500 Date: Tue, 28 Oct 2025 18:43:25 +0100 Subject: Modifier les balises de métadonnées Docker pour inclure l'architecture et ajuster la création de manifestes multi-architecture. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9548ab..78323d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,10 +109,9 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- - type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch,suffix=-${{ matrix.arch }} + type=ref,event=pr,suffix=-${{ matrix.arch }} + type=sha,prefix={{branch}}-,suffix=-${{ matrix.arch }} - name: Build and push Docker image uses: docker/build-push-action@v5 @@ -153,12 +152,14 @@ jobs: BRANCH=${GITHUB_REF##*/} SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7) - # Create manifest for branch tag + # Create manifest for branch tag (combines amd64 and arm64) docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH} \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-arm64 # Create manifest for latest tag if on default branch if [ "${{ github.ref }}" = "refs/heads/main" ] || [ "${{ github.ref }}" = "refs/heads/master" ]; then docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-arm64 fi -- cgit v1.2.3 From 66dce09d54b7cc9ab7f1acd51f1e02b8064d9d8d Mon Sep 17 00:00:00 2001 From: garder500 Date: Tue, 28 Oct 2025 18:48:48 +0100 Subject: Ajouter un workflow pour construire et télécharger des paquets Linux (deb, rpm, apk, archlinux) à partir des binaires Go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 130 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78323d7..6030daf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,6 +68,136 @@ jobs: path: ${{ matrix.output }} retention-days: 7 + # Build Linux packages (deb and apk) + build-packages: + name: Build Linux Packages + needs: build-binaries + runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64, arm64] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download binary artifact + uses: actions/download-artifact@v4 + with: + name: sovrabase-linux-${{ matrix.arch }} + + - name: Make binary executable + run: chmod +x sovrabase-linux-${{ matrix.arch }} + + - name: Install nfpm + run: | + echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list + sudo apt-get update + sudo apt-get install -y nfpm + + - name: Create nfpm config + run: | + cat > nfpm.yaml <" + description: | + Sovrabase - A modern gRPC server + Built from commit ${GITHUB_SHA::7} + vendor: "Sovrabase" + homepage: "https://github.com/${{ github.repository }}" + license: "MIT" + + contents: + - src: ./sovrabase-linux-${{ matrix.arch }} + dst: /usr/bin/sovrabase + file_info: + mode: 0755 + - src: ./config.toml + dst: /etc/sovrabase/config.toml + type: config + file_info: + mode: 0644 + + overrides: + deb: + scripts: + postinstall: | + #!/bin/sh + echo "Sovrabase installed successfully" + echo "Configuration file: /etc/sovrabase/config.toml" + echo "Run with: sovrabase" + rpm: + scripts: + postinstall: | + #!/bin/sh + echo "Sovrabase installed successfully" + echo "Configuration file: /etc/sovrabase/config.toml" + echo "Run with: sovrabase" + apk: + scripts: + postinstall: | + #!/bin/sh + echo "Sovrabase installed successfully" + echo "Configuration file: /etc/sovrabase/config.toml" + echo "Run with: sovrabase" + archlinux: + scripts: + postinstall: | + #!/bin/sh + echo "Sovrabase installed successfully" + echo "Configuration file: /etc/sovrabase/config.toml" + echo "Run with: sovrabase" + EOF + + - name: Build deb package (Debian/Ubuntu) + run: | + nfpm package --packager deb --target sovrabase_${{ matrix.arch }}.deb + + - name: Build rpm package (Red Hat/Fedora/CentOS) + run: | + nfpm package --packager rpm --target sovrabase_${{ matrix.arch }}.rpm + + - name: Build apk package (Alpine) + run: | + nfpm package --packager apk --target sovrabase_${{ matrix.arch }}.apk + + - name: Build archlinux package (Arch Linux) + run: | + nfpm package --packager archlinux --target sovrabase_${{ matrix.arch }}.pkg.tar.zst + + - name: Upload deb package + uses: actions/upload-artifact@v4 + with: + name: sovrabase_${{ matrix.arch }}.deb + path: sovrabase_${{ matrix.arch }}.deb + retention-days: 30 + + - name: Upload rpm package + uses: actions/upload-artifact@v4 + with: + name: sovrabase_${{ matrix.arch }}.rpm + path: sovrabase_${{ matrix.arch }}.rpm + retention-days: 30 + + - name: Upload apk package + uses: actions/upload-artifact@v4 + with: + name: sovrabase_${{ matrix.arch }}.apk + path: sovrabase_${{ matrix.arch }}.apk + retention-days: 30 + + - name: Upload archlinux package + uses: actions/upload-artifact@v4 + with: + name: sovrabase_${{ matrix.arch }}.pkg.tar.zst + path: sovrabase_${{ matrix.arch }}.pkg.tar.zst + retention-days: 30 + # Build Docker images for multiple architectures build-docker: name: Build Docker Image -- cgit v1.2.3 From 85cf0f6046377c2a32aa842212adab2118d27958 Mon Sep 17 00:00:00 2001 From: garder500 Date: Tue, 28 Oct 2025 18:51:33 +0100 Subject: Supprimer le workflow de construction des paquets Linux obsolète MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 130 -------------------------------------------- 1 file changed, 130 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6030daf..78323d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,136 +68,6 @@ jobs: path: ${{ matrix.output }} retention-days: 7 - # Build Linux packages (deb and apk) - build-packages: - name: Build Linux Packages - needs: build-binaries - runs-on: ubuntu-latest - strategy: - matrix: - arch: [amd64, arm64] - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Download binary artifact - uses: actions/download-artifact@v4 - with: - name: sovrabase-linux-${{ matrix.arch }} - - - name: Make binary executable - run: chmod +x sovrabase-linux-${{ matrix.arch }} - - - name: Install nfpm - run: | - echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list - sudo apt-get update - sudo apt-get install -y nfpm - - - name: Create nfpm config - run: | - cat > nfpm.yaml <" - description: | - Sovrabase - A modern gRPC server - Built from commit ${GITHUB_SHA::7} - vendor: "Sovrabase" - homepage: "https://github.com/${{ github.repository }}" - license: "MIT" - - contents: - - src: ./sovrabase-linux-${{ matrix.arch }} - dst: /usr/bin/sovrabase - file_info: - mode: 0755 - - src: ./config.toml - dst: /etc/sovrabase/config.toml - type: config - file_info: - mode: 0644 - - overrides: - deb: - scripts: - postinstall: | - #!/bin/sh - echo "Sovrabase installed successfully" - echo "Configuration file: /etc/sovrabase/config.toml" - echo "Run with: sovrabase" - rpm: - scripts: - postinstall: | - #!/bin/sh - echo "Sovrabase installed successfully" - echo "Configuration file: /etc/sovrabase/config.toml" - echo "Run with: sovrabase" - apk: - scripts: - postinstall: | - #!/bin/sh - echo "Sovrabase installed successfully" - echo "Configuration file: /etc/sovrabase/config.toml" - echo "Run with: sovrabase" - archlinux: - scripts: - postinstall: | - #!/bin/sh - echo "Sovrabase installed successfully" - echo "Configuration file: /etc/sovrabase/config.toml" - echo "Run with: sovrabase" - EOF - - - name: Build deb package (Debian/Ubuntu) - run: | - nfpm package --packager deb --target sovrabase_${{ matrix.arch }}.deb - - - name: Build rpm package (Red Hat/Fedora/CentOS) - run: | - nfpm package --packager rpm --target sovrabase_${{ matrix.arch }}.rpm - - - name: Build apk package (Alpine) - run: | - nfpm package --packager apk --target sovrabase_${{ matrix.arch }}.apk - - - name: Build archlinux package (Arch Linux) - run: | - nfpm package --packager archlinux --target sovrabase_${{ matrix.arch }}.pkg.tar.zst - - - name: Upload deb package - uses: actions/upload-artifact@v4 - with: - name: sovrabase_${{ matrix.arch }}.deb - path: sovrabase_${{ matrix.arch }}.deb - retention-days: 30 - - - name: Upload rpm package - uses: actions/upload-artifact@v4 - with: - name: sovrabase_${{ matrix.arch }}.rpm - path: sovrabase_${{ matrix.arch }}.rpm - retention-days: 30 - - - name: Upload apk package - uses: actions/upload-artifact@v4 - with: - name: sovrabase_${{ matrix.arch }}.apk - path: sovrabase_${{ matrix.arch }}.apk - retention-days: 30 - - - name: Upload archlinux package - uses: actions/upload-artifact@v4 - with: - name: sovrabase_${{ matrix.arch }}.pkg.tar.zst - path: sovrabase_${{ matrix.arch }}.pkg.tar.zst - retention-days: 30 - # Build Docker images for multiple architectures build-docker: name: Build Docker Image -- cgit v1.2.3