Le conteneur docker:27-cli (Alpine) n'a pas Node -> actions/checkout (action JS) échoue avec « exec: "node": not found ». Remplacé par un clone Git du dépôt public (git init + fetch --depth 1 + checkout FETCH_HEAD). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
105 lines
3.6 KiB
YAML
105 lines
3.6 KiB
YAML
# Teste, puis build et publie l'image Docker sur le registre de conteneurs Forgejo :
|
|
# git.dev.kyuno.fr/kyuno/mediadrop
|
|
#
|
|
# - push sur `main` -> tags `latest` + `<sha court>`
|
|
# - push d'un tag `vX.Y.Z` -> tags `X.Y.Z`, `X.Y`, `latest`
|
|
# - déclenchement manuel possible (Actions -> Run workflow)
|
|
#
|
|
# Prérequis côté instance :
|
|
# 1. Actions activé pour le dépôt : Settings -> Actions -> Enable.
|
|
# 2. Un runner enregistré avec le label `ubuntu-latest`
|
|
# (sinon adapter les `runs-on:` ci-dessous).
|
|
# 3. Le runner doit pouvoir lancer `docker` dans les jobs conteneurisés :
|
|
# monter le socket de l'hôte dans la config du runner (`config.yaml`) —
|
|
# container:
|
|
# options: -v /var/run/docker.sock:/var/run/docker.sock
|
|
# puis redémarrer le runner. (Ou utiliser un runner « host » avec Docker.)
|
|
# 4. Le runner doit joindre git.dev.kyuno.fr et github.com (actions/checkout).
|
|
# 5. Registre : le jeton automatique `secrets.GITHUB_TOKEN` peut pousser des
|
|
# paquets pour l'organisation `kyuno`. Si ce n'est pas le cas, créer un
|
|
# secret de dépôt `REGISTRY_TOKEN` (jeton d'accès avec la permission
|
|
# « write:package ») et remplacer `secrets.GITHUB_TOKEN` plus bas.
|
|
|
|
name: Publier l'image Docker
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ['v*']
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
env:
|
|
REGISTRY: git.dev.kyuno.fr
|
|
IMAGE: git.dev.kyuno.fr/${{ github.repository_owner }}/mediadrop
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: node:22-bookworm
|
|
steps:
|
|
- uses: https://github.com/actions/checkout@v4
|
|
- run: npm ci
|
|
- run: npm run lint
|
|
- run: npm run typecheck
|
|
- run: npm test
|
|
|
|
publish:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: docker:27-cli
|
|
steps:
|
|
# `docker:27-cli` (Alpine) n'a pas Node : on ne peut pas utiliser
|
|
# actions/checkout (action JS). Clone Git direct du dépôt public.
|
|
- name: Récupérer les sources
|
|
run: |
|
|
set -eu
|
|
apk add --no-cache git
|
|
git init -q
|
|
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
|
|
git fetch -q --depth 1 origin "${{ github.ref_name }}"
|
|
git checkout -q FETCH_HEAD
|
|
|
|
- name: Calculer les tags
|
|
id: tags
|
|
run: |
|
|
set -eu
|
|
if [ "${{ github.ref_type }}" = "tag" ]; then
|
|
v="${{ github.ref_name }}"
|
|
v="${v#v}"
|
|
list="${IMAGE}:${v} ${IMAGE}:${v%.*} ${IMAGE}:latest"
|
|
else
|
|
short="$(echo "${{ github.sha }}" | cut -c1-12)"
|
|
list="${IMAGE}:latest ${IMAGE}:${short}"
|
|
fi
|
|
echo "list=${list}" >> "$GITHUB_OUTPUT"
|
|
echo "Tags : ${list}"
|
|
|
|
- name: Connexion au registre
|
|
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.actor }}" --password-stdin
|
|
|
|
- name: Build
|
|
run: |
|
|
set -eu
|
|
args=""
|
|
for t in ${{ steps.tags.outputs.list }}; do args="$args -t $t"; done
|
|
# shellcheck disable=SC2086
|
|
docker build $args \
|
|
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
.
|
|
|
|
- name: Push
|
|
run: |
|
|
set -eu
|
|
for t in ${{ steps.tags.outputs.list }}; do docker push "$t"; done
|
|
|
|
- name: Déconnexion
|
|
if: always()
|
|
run: docker logout "$REGISTRY"
|