Sign inSign up

brenard/nfpm

By brenard

•Updated 3 months ago

Gitlab CI and Forgejo Actions image to build Debian package(s) using nfpm

Image
Integration & delivery
Developer tools
0

10K+

brenard/nfpm repository overview

⁠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

Tag summary

Content type

Image

Digest

sha256:c2de5e333…

Size

96.3 MB

Last updated

3 months ago

docker pull brenard/nfpm