No description
  • Dockerfile 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-20 19:33:11 +02:00
.gitignore Add README.md file 2026-02-19 16:38:17 +01:00
Dockerfile Install nfpm using npm to ensure to have the latest version 2026-07-20 19:33:11 +02:00
README.md Add rsync tool and improve example CI build process 2026-06-24 13:32:38 +02:00

Docker image to use nfpm

This docker image could be used with Gitlab CI and Forgejo Actions to build Debian package(s) using nfpm.

Usage

With Gitlab CI

The following pipeline configuration demonstrates a simple usage to build multiple Debian package of a python library:

---
stages:
  - build

build:
  image: docker.io/brenard/nfpm:latest
  stage: build
  rules:
    - if: $CI_COMMIT_TAG
  before_script:
    # Clean previous build
    - rm -fr dist tmp
    - mkdir -p dist tmp
    # Copy clean version of the source code
    - git ls-files | rsync -av --files-from=- ./ tmp/
    # Install GPG key
    - echo "$GPG_KEY" | base64 -d > tmp/key.gpg
    # Ensure git access to source directory
    - git show --name-status --oneline || git config --global --add safe.directory "$(pwd)"
    # Gitlab CI use shallow clone, but we need full history to generate changelog
    - |
      if [ "$( git rev-parse --is-shallow-repository )" == "true" ]; then
        git fetch --unshallow
      fi
  script:
    - |
      # Compute package version
      VERSION=$(git describe --tags 2>/dev/null | sed 's/^[^0-9]*//')
      [ -z "$VERSION" ] && VERSION="0.0-$(git log --oneline|wc -l)-$(git describe --tags --always)"

      # Fix version format to match with Python specs
      # See: https://peps.python.org/pep-0440/
      VERSION=$( echo "$VERSION" | sed -e 's/^[^0-9]*//' -e 's/^\([0-9][^-]*\)-\(.*\)/\1+\2/' )

      # Set version & build egg-info
      [ -f tmp/pyproject.toml ] && \
        tomlq -t -i --arg version "$VERSION" \
          '.project.version=$version' tmp/pyproject.toml
      [ -f tmp/setup.py ] && \
        sed -i "s/^\( *version *= *\)\".*\",$/\1\"$VERSION\",/" \
          tmp/setup.py

      # Build wheel & install it in tmp directory
      cd tmp
      mkdir tmp
      python3 -m pip wheel --no-deps -w dist .
      python3 -m pip install \
        --ignore-installed \
        --no-deps \
        --no-compile \
        --root "tmp" \
        --prefix "/usr" \
        dist/*.whl

      # Fix python path
      mv tmp/usr/lib/python3* tmp/usr/lib/python3
      mv tmp/usr/lib/python3/site-packages tmp/usr/lib/python3/dist-packages

      # Set Debian package maintainer & signature key file
      yq -y -i '.deb.signature.key_file = "key.gpg"' nfpm.yaml
      yq -y -i --arg name "$DEBFULLNAME" --arg email "$DEBEMAIL" \
        '.maintainer = $name + " <" + $email + ">"' nfpm.yaml

      # Build Debian package for Bullseye
      yq -y -i --arg version "$VERSION" '.version = $version + "-1~ee110"' nfpm.yaml
      yq -y -i '.deb.distribution = "bullseye-ee"' .chglog.yml
      chglog init
      nfpm -f nfpm.yaml package --packager deb --target ../dist/

      # Build Debian package for Bookworm
      yq -y -i --arg version "$VERSION" '.version = $version + "-1~ee120"' nfpm.yaml
      yq -y -i '.deb.distribution = "bookworm-ee"' .chglog.yml
      chglog init
      nfpm -f nfpm.yaml package --packager deb --target ../dist/

      # Build Debian package for Trixie
      yq -y -i --arg version "$VERSION" '.version = $version + "-1~ee130"' nfpm.yaml
      yq -y -i '.deb.distribution = "trixie-ee"' .chglog.yml
      chglog init
      nfpm -f nfpm.yaml package --packager deb --target ../dist/

      # Generate release notes
      chglog format --template release -o ../dist/release-notes.md
      sed -i 's/^\([0-9a-f]\{8\}\) /- \1 /' ../dist/release-notes.md
  artifacts:
    paths:
      - dist/*

With Forgejo Actions

FIXME