diff --git a/.github/workflows/memory.yml b/.github/workflows/memory.yml new file mode 100644 index 0000000..db5ca94 --- /dev/null +++ b/.github/workflows/memory.yml @@ -0,0 +1,99 @@ +name: memory-2026 +on: + push: + branches: [develop] +jobs: + # 4.1 — TEST : exécuter "file" sur tous les JPG/JPEG + test-memory-2026: + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + - name: Create test script (LF only) + shell: powershell + run: | + $lines = @( + '#!/usr/bin/env bash', + 'set -euo pipefail', + 'export DEBIAN_FRONTEND=noninteractive', + 'apt-get update >/dev/null', + 'apt-get install -y file >/dev/null', + 'shopt -s globstar nullglob', + 'files=(**/*.jpg **/*.jpeg)', + 'if [ ${#files[@]} -eq 0 ]; then', + ' echo "Aucun .jpg/.jpeg"', + ' exit 0', + 'fi', + 'for f in "${files[@]}"; do', + ' file "$f"', + 'done' + ) + $path = Join-Path $env:GITHUB_WORKSPACE 'test_jpgs.sh' + $content = ($lines -join "`n") # LF uniquement + [System.IO.File]::WriteAllText($path, $content, (New-Object System.Text.UTF8Encoding($false))) + - name: Run test script inside Debian (with "file") + shell: powershell + run: | + $work = $env:GITHUB_WORKSPACE -replace '\\','/' + docker run --rm --mount "type=bind,src=$work,dst=/work" -w /work debian:stable-slim bash /work/test_jpgs.sh + + # 4.2 — BUILD : construire l'image /memory-2026:latest + build-memory-2026: + runs-on: self-hosted + needs: test-memory-2026 + steps: + - uses: actions/checkout@v4 + - name: Docker build + shell: powershell + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/memory-2026:latest . + + # 4.3 — PUSH : pousser sur Docker Hub + push-memory-2026: + runs-on: self-hosted + needs: build-memory-2026 + steps: + - name: Sanity check secrets + shell: powershell + run: | + if (-not "${{ secrets.DOCKERHUB_USERNAME }}") { throw "Secret DOCKERHUB_USERNAME vide ou manquant" } + if (-not "${{ secrets.DOCKERHUB_TOKEN }}") { throw "Secret DOCKERHUB_TOKEN vide ou manquant" } + Write-Host "Secrets présents" + - name: Docker login (via cmd + fichier ASCII) + shell: powershell + run: | + $u = "${{ secrets.DOCKERHUB_USERNAME }}".Trim().ToLower() + $t = "${{ secrets.DOCKERHUB_TOKEN }}".Trim() + $tf = Join-Path $env:RUNNER_TEMP "dh_token.txt" + [System.IO.File]::WriteAllText($tf, $t, [System.Text.Encoding]::ASCII) + # on utilise cmd.exe pour interpréter la redirection "<" + cmd /c "docker logout 1>nul 2>nul & docker login -u $u --password-stdin < ""$tf""" + Remove-Item $tf -Force + docker info | Select-String -SimpleMatch "Username: $u" | Out-Host + - name: Docker push + shell: powershell + run: | + $u = "${{ secrets.DOCKERHUB_USERNAME }}".Trim().ToLower() + docker push "$u/memory-2026:latest" + + # 4.4 — DEPLOY : SSH vers ta machine, pull & run en 80:80 + deploy-memory-2026: + runs-on: self-hosted + needs: push-memory-2026 + steps: + - name: Setup SSH key (Windows) + shell: powershell + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + run: | + New-Item -ItemType Directory -Force "$HOME\.ssh" | Out-Null + Set-Content -Path "$HOME\.ssh\id_rsa" -Value $env:SSH_PRIVATE_KEY -NoNewline + icacls "$HOME\.ssh\id_rsa" /inheritance:r /grant:r "$env:USERNAME:(R)" | Out-Null + - name: Deploy to target via SSH + shell: powershell + env: + SSH_USER: ${{ secrets.SSH_USER }} + SSH_HOST: ${{ secrets.SSH_HOST }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + run: | + $image = "$env:DOCKERHUB_USERNAME/memory-2026:latest" + $remote = "docker pull $image; docker ps -aq -f name=^memory-2026$ | xargs -r docker rm -f; docker run -d --name memory-2026 -p 80:80 $image" + ssh -o StrictHostKeyChecking=no "$env:SSH_USER@$env:SSH_HOST" "$remote" diff --git a/.github/workflows/verify-runner.yml b/.github/workflows/verify-runner.yml new file mode 100644 index 0000000..a6ce62f --- /dev/null +++ b/.github/workflows/verify-runner.yml @@ -0,0 +1,16 @@ +name: verify-runner + +on: + workflow_dispatch: + push: + branches: [develop] + +jobs: + ping: + runs-on: self-hosted + steps: + - name: Print env + shell: powershell + run: | + Write-Host "Runner OK" + Write-Host "User: $env:USERNAME" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b3d949 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM nginx:stable + +RUN apt-get update && apt-get install -y --no-install-recommends file \ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /var/concentration/html + +COPY conf/nginx.conf /etc/nginx/nginx.conf + +COPY html/ /var/concentration/html/ + +EXPOSE 80 + + +CMD ["nginx", "-g", "daemon off;"]