refactor(ci): simplify CI configuration by consolidating binary build steps and updating Dockerfile

This commit is contained in:
Félix MARQUET
2025-06-13 13:55:10 +02:00
parent 60db3550c0
commit fe33377fa0
7 changed files with 47 additions and 202 deletions

View File

@@ -6,18 +6,8 @@ on:
- dev - dev
jobs: jobs:
build-binaries: build-binary:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
platform: linux/amd64
name: github-ntfy-amd64
- target: aarch64-unknown-linux-musl
platform: linux/arm64
name: github-ntfy-arm64
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -26,7 +16,7 @@ jobs:
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
toolchain: stable toolchain: stable
target: ${{ matrix.target }} target: x86_64-unknown-linux-musl
override: true override: true
- name: Installer cross - name: Installer cross
@@ -49,32 +39,27 @@ jobs:
RUSTFLAGS: "-C target-feature=+crt-static" RUSTFLAGS: "-C target-feature=+crt-static"
OPENSSL_NO_VENDOR: 0 OPENSSL_NO_VENDOR: 0
run: | run: |
cross build --release --target ${{ matrix.target }} --features vendored-openssl cross build --release --target x86_64-unknown-linux-musl --features vendored-openssl
- name: Préparer le binaire - name: Préparer le binaire
run: | run: |
mkdir -p release mkdir -p release
cp target/${{ matrix.target }}/release/github-ntfy release/${{ matrix.name }} cp target/x86_64-unknown-linux-musl/release/github-ntfy release/github-ntfy
- name: Upload binaire comme artifact - name: Upload binaire comme artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.name }} name: github-ntfy
path: release/${{ matrix.name }} path: release/github-ntfy
docker-build-push: docker-build-push:
needs: [ build-binaries ] needs: [build-binary]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Configurer QEMU - name: Configurer Docker
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Configurer Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Login Docker Hub - name: Login Docker Hub
@@ -83,60 +68,20 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Télécharger tous les binaires - name: Télécharger le binaire
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: github-ntfy
path: binaries path: binaries
- name: Préparer les binaires pour Docker - name: Préparer le binaire pour Docker
run: | run: |
mkdir -p binaries-docker chmod +x binaries/github-ntfy
cp binaries/github-ntfy-amd64/github-ntfy-amd64 binaries-docker/
cp binaries/github-ntfy-arm64/github-ntfy-arm64 binaries-docker/
chmod +x binaries-docker/*
- name: Créer Dockerfile spécifique pour chaque architecture - name: Construire et pousser l'image Docker
run: |
# Créer un Dockerfile séparé pour chaque architecture
cat > Dockerfile.multi << 'EOF'
FROM --platform=${TARGETPLATFORM} alpine:3.22
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETVARIANT
# Copier le binaire approprié selon l'architecture
COPY binaries-docker/github-ntfy-amd64 /usr/local/bin/github-ntfy-amd64
COPY binaries-docker/github-ntfy-arm64 /usr/local/bin/github-ntfy-arm64
# Installer des outils pour débogage et déplacer le bon binaire
RUN apk add --no-cache sqlite-libs openssl nginx && \
if [ "$TARGETARCH" = "amd64" ]; then \
cp /usr/local/bin/github-ntfy-amd64 /usr/local/bin/github-ntfy; \
elif [ "$TARGETARCH" = "arm64" ]; then \
cp /usr/local/bin/github-ntfy-arm64 /usr/local/bin/github-ntfy; \
fi && \
chmod +x /usr/local/bin/github-ntfy && \
rm /usr/local/bin/github-ntfy-*
WORKDIR /app
COPY web /app/web
COPY config.toml /app/config.toml
ENV DB_PATH=/data
VOLUME /data
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/github-ntfy"]
CMD ["--config", "/app/config.toml"]
EOF
- name: Construire et pousser l'image Docker multi-architecture
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: true
platforms: linux/amd64,linux/arm64 tags: breizhhardware/github-ntfy:dev
tags: | file: Dockerfile
breizhhardware/github-ntfy:dev
file: Dockerfile.multi

View File

@@ -40,15 +40,6 @@ jobs:
build-binaries: build-binaries:
needs: version needs: version
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
platform: linux/amd64
name: github-ntfy-amd64
- target: aarch64-unknown-linux-musl
platform: linux/arm64
name: github-ntfy-arm64
steps: steps:
- name: Checkout code - name: Checkout code
@@ -58,13 +49,13 @@ jobs:
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
toolchain: stable toolchain: stable
target: ${{ matrix.target }} target: x86_64-unknown-linux-musl
override: true override: true
- name: Installer cross - name: Installer cross
run: cargo install cross run: cargo install cross
- name: Créer Cross.toml pour spécifier OpenSSL statique - name: Créer Cross.toml pour spécifier OpenSSL vendored
run: | run: |
cat > Cross.toml << 'EOF' cat > Cross.toml << 'EOF'
[build.env] [build.env]
@@ -75,24 +66,24 @@ jobs:
] ]
EOF EOF
- name: Construire avec cross - name: Construire avec cross et OpenSSL vendored
env: env:
OPENSSL_STATIC: 1 OPENSSL_STATIC: 1
RUSTFLAGS: "-C target-feature=+crt-static" RUSTFLAGS: "-C target-feature=+crt-static"
OPENSSL_NO_VENDOR: 0 OPENSSL_NO_VENDOR: 0
run: | run: |
cross build --release --target ${{ matrix.target }} --features vendored-openssl cross build --release --target x86_64-unknown-linux-musl --features vendored-openssl
- name: Préparer le binaire - name: Préparer le binaire
run: | run: |
mkdir -p release mkdir -p release
cp target/${{ matrix.target }}/release/github-ntfy release/${{ matrix.name }} cp target/x86_64-unknown-linux-musl/release/github-ntfy release/github-ntfy
- name: Upload binaire comme artifact - name: Upload binaire comme artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.name }} name: github-ntfy
path: release/${{ matrix.name }} path: release/github-ntfy
docker-build-push: docker-build-push:
needs: [version, build-binaries] needs: [version, build-binaries]
@@ -101,11 +92,6 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Configurer QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Configurer Docker Buildx - name: Configurer Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -118,27 +104,23 @@ jobs:
- name: Télécharger tous les binaires - name: Télécharger tous les binaires
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: github-ntfy
path: binaries path: binaries
- name: Préparer les binaires pour Docker - name: Préparer le binaire pour Docker
run: | run: |
mkdir -p binaries-docker chmod +x binaries/github-ntfy
cp binaries/github-ntfy-amd64/github-ntfy-amd64 binaries-docker/
cp binaries/github-ntfy-arm64/github-ntfy-arm64 binaries-docker/
chmod +x binaries-docker/*
ls -la binaries-docker/
# Construire et pousser l'image multi-architecture # Construire et pousser l'image multi-architecture
- name: Construire et pousser l'image Docker multi-architecture - name: Construire et pousser l'image Docker
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: true
platforms: linux/amd64,linux/arm64
tags: | tags: |
breizhhardware/github-ntfy:latest breizhhardware/github-ntfy:latest
breizhhardware/github-ntfy:${{ needs.version.outputs.version }} breizhhardware/github-ntfy:${{ needs.version.outputs.version }}
file: Dockerfile.multi file: Dockerfile
create-release: create-release:
needs: [version, build-binaries] needs: [version, build-binaries]
@@ -150,6 +132,7 @@ jobs:
- name: Télécharger tous les binaires - name: Télécharger tous les binaires
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: github-ntfy
path: binaries path: binaries
- name: Créer une release GitHub - name: Créer une release GitHub
@@ -158,8 +141,7 @@ jobs:
tag_name: ${{ needs.version.outputs.version }} tag_name: ${{ needs.version.outputs.version }}
name: Release ${{ needs.version.outputs.version }} name: Release ${{ needs.version.outputs.version }}
files: | files: |
binaries/github-ntfy-amd64/github-ntfy-amd64 binaries/github-ntfy
binaries/github-ntfy-arm64/github-ntfy-arm64
draft: false draft: false
prerelease: false prerelease: false
generate_release_notes: true generate_release_notes: true

3
.gitignore vendored
View File

@@ -410,3 +410,6 @@ github-ntfy/*
# Rust # Rust
target target
target/* target/*
binaries
binaries/*

View File

@@ -1,63 +1,25 @@
FROM 1.87.0-alpine3.22 as builder FROM alpine:3.22
LABEL maintainer="BreizhHardware" # Copier le binaire
LABEL version_number="1.4" COPY binaries/github-ntfy /usr/local/bin/github-ntfy
# Installer les dépendances
RUN apk add --no-cache sqlite-libs openssl nginx && \
chmod +x /usr/local/bin/github-ntfy
WORKDIR /app WORKDIR /app
# Installation of dependencies # Copier les fichiers web dans le répertoire attendu par nginx
RUN apk add --no-cache sqlite-dev musl-dev openssl-dev pkgconfig COPY web/* /var/www/html/
# Copy of the source files
COPY Cargo.toml Cargo.lock ./
# Create a temp source file to pre download dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
cargo build --release && \
rm -rf src
# Copy real file
COPY src/ ./src/
# Build the application
RUN cargo build --release
# Final image
FROM alpine:3.22
# Install of runtime dependencies
RUN apk add --no-cache sqlite-libs openssl nginx
# Copy the static files
COPY index.html /var/www/html/index.html
COPY script.js /var/www/html/script.js
# Copy the built application from the builder stage
COPY --from=builder /app/target/release/github-ntfy /usr/local/bin/github-ntfy
# Configure Nginx
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
# Copy the entrypoint script # Copier le script d'entrée
COPY entrypoint.sh / COPY entrypoint.sh /app/entrypoint.sh
RUN chmod 700 /entrypoint.sh RUN chmod +x /app/entrypoint.sh
# Define the working directory
ENV USERNAME="" \
PASSWORD="" \
NTFY_URL="" \
GHNTFY_TIMEOUT="3600" \
GHNTFY_TOKEN="" \
DOCKER_USERNAME="" \
DOCKER_PASSWORD="" \
GOTIFY_URL="" \
GOTIFY_TOKEN="" \
DISCORD_WEBHOOK_URL="" \
SLACK_WEBHOOK_URL=""
# Créer le répertoire de données
RUN mkdir -p /github-ntfy && chmod 755 /github-ntfy RUN mkdir -p /github-ntfy && chmod 755 /github-ntfy
EXPOSE 5000 80 EXPOSE 5000 80
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]

View File

@@ -1,47 +0,0 @@
FROM alpine:3.22 AS base
# Copier les binaires précompilés selon l'architecture
COPY binaries-docker/github-ntfy-amd64 /usr/local/bin/github-ntfy-amd64
COPY binaries-docker/github-ntfy-arm64 /usr/local/bin/github-ntfy-arm64
# Installation des dépendances et configuration du binaire selon l'architecture
RUN apk add --no-cache sqlite-libs openssl nginx && \
if [ "$(uname -m)" = "x86_64" ]; then \
cp /usr/local/bin/github-ntfy-amd64 /usr/local/bin/github-ntfy; \
elif [ "$(uname -m)" = "aarch64" ]; then \
cp /usr/local/bin/github-ntfy-arm64 /usr/local/bin/github-ntfy; \
fi && \
chmod +x /usr/local/bin/github-ntfy && \
rm /usr/local/bin/github-ntfy-*
WORKDIR /app
# Copier les fichiers statiques
COPY index.html /var/www/html/index.html
COPY script.js /var/www/html/script.js
# Copier la configuration nginx
COPY nginx.conf /etc/nginx/nginx.conf
# Copier le script d'entrée
COPY entrypoint.sh /
RUN chmod 700 /entrypoint.sh
# Variables d'environnement
ENV USERNAME="" \
PASSWORD="" \
NTFY_URL="" \
GHNTFY_TIMEOUT="3600" \
GHNTFY_TOKEN="" \
DOCKER_USERNAME="" \
DOCKER_PASSWORD="" \
GOTIFY_URL="" \
GOTIFY_TOKEN="" \
DISCORD_WEBHOOK_URL="" \
SLACK_WEBHOOK_URL=""
RUN mkdir -p /github-ntfy && chmod 755 /github-ntfy
EXPOSE 8080 80
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Github-Ntfy Add a Repo</title> <title>Github-Ntfy Add a Repo</title>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<script src="./script.js" defer></script> <script src="script.js" defer></script>
</head> </head>
<body class="bg-[#1b2124] text-gray-200"> <body class="bg-[#1b2124] text-gray-200">
<header class="text-center py-8 bg-[#23453d] shadow-lg"> <header class="text-center py-8 bg-[#23453d] shadow-lg">