Files
documentation/docs/services/gitea/gitea-packages.md
2026-09-28 17:14:01 +02:00

5.3 KiB

Gitea Packages

The gitea server comes with various package registries build in. For details please refer to: https://docs.gitea.com/usage/packages/overview

RPM Registry

Every organization has its own RPM/YUM repository. To publish rpms from your gitea workflows you can use the upload-rpm action - https://gitea.psi.ch/actions/upload-rpm/ - to do so.

The action can be used as follows:

- name: Upload RPM
  uses: actions/upload-rpm@main
  with:
    token: "${{ secrets.PACKAGES_DEPLOY_TOKEN }}"
    files: "*.rpm"

More details about this action can be found at https://gitea.psi.ch/actions/upload-rpm/

Container Registry

Every organization has its own (docker) container registry.

Here some examples how to work with the Container registry that is built into gitea.psi.ch:

# login to the gitea container registry
docker login gitea.psi.ch

# Build and push an image
docker build -t gitea.psi.ch/{owner}/{image}:{tag} .
docker push gitea.psi.ch/{owner}/{image}:{tag}

# Pull an image
docker pull gitea.psi.ch/{owner}/{image}:{tag}

# Run an image from the registry
docker run -it --rm gitea.psi.ch/{owner}/{image}:{tag}

You can automatically built an push a container into the registry via a gitea action workflow. An example you can find here:

https://gitea.psi.ch/images/alpine-mkdocs/src/branch/main/.gitea/workflows/build_push.yaml

All you need is a file like this in .gitea/workflows/

name: Build and Publish Docker Image

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  docker:
    runs-on: ubuntu-latest-intranet
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Login to Docker Registry
        uses: docker/login-action@v3
        with:
          registry: gitea.psi.ch
          username: ${{ github.repository_owner }}
          password: ${{ secrets.REGISTRY_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: gitea.psi.ch/${{ github.repository }}:latest

See Token for Gitea workflows for how to get and set ${{ secrets.REGISTRY_TOKEN }}.

PyPI Package Registry

Every organization has its own (PyPi) packages registry.

Publish a Python package manually

To publish a package, run:

python -m twine upload dist/* \
  --repository-url https://gitea.psi.ch/api/packages/{owner}/pypi \
  --username {username} \
  --password {token} \
  --verbose

where dist/* points to your python distribution files that are usually generated when you build a python package.

You could also configure repository-url, username and password in your ~/.pypirc

[distutils]
index-servers = gitea

[gitea]
repository = https://gitea.psi.ch/api/packages/{owner}/pypi
username = {username}
password = {token}

and then run:

python -m twine upload dist/* --repository gitea --verbose

Publish a Python package through CICD

Here we are using uv to build our package (which generates dist/*), but also to build a venv and install twine inside of it. You can find the code for this example here:

https://gitea.psi.ch/sls/OM/src/branch/main/.gitea/workflows/release.yml

All you need is a file like this in .gitea/workflows/

name: "Publish release to Gitea Packages"

on:
  push:
    tags:
      # Publish on any tag starting with a `v`, e.g., v0.1.0
      - v*

jobs:
  run:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install uv
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

      - name: Install Python 3.12
        run: uv python install 3.12
        
      - name: Build
        run: uv build

      - name: Install twine
        run: uv add twine

      - name: Publish
        env:
          PYPI_INDEX_URL: "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/pypi"
        run: |
          echo "Publishing to ${PYPI_INDEX_URL}"
          uv run python -m twine upload dist/* \
            --repository-url ${PYPI_INDEX_URL} \
            --username ${{ github.repository_owner }}-gitea \
            --password ${{ secrets.REGISTRY_TOKEN }} \
            --verbose

See Token for Gitea workflows for how to get and set ${{ secrets.REGISTRY_TOKEN }}.

For a given {owner}, the package will be published here https://gitea.psi.ch/{owner}/-/packages.

You can then link it to a specific repository from the settings of the package:

Token for Gitea workflows

For the Gitea CI/CD workflows above to work you need to get a token and set it as a secret called REGISTRY_TOKEN on the organization like this:

This is usually a token from a bot user that belongs to the organization. You can create a bot user and get a token for it as described here https://linux.psi.ch/documentation/services/gitea/gitea-faq/#i-need-a-service-usertoken-for-automation.

The bot user needs write permissions to packages for the gitea organization. Example e-mail request:

Username: {owner}-gitea
Scope: read:repository,write:packages
E-mail: ...

Additionally, the bot user needs to be added to the Gitea organization {owner}.