Hi gcc-patches mailing list,
pietro <[email protected]> has requested that the following forgejo pull 
request
be published on the mailing list.

Created on: 2025-12-18 23:08:10+00:00
Latest update: 2026-01-06 05:36:08+00:00
Changes: 5 changed files, 430 additions, 0 deletions
Head revision: pietro/gcc-TEST ref forge-cfile commit 
c90915df14c0fb01d8a6acc5d4ab09e9c171d313
Base revision: gcc/gcc-TEST ref trunk commit 
cdb15b390035fc4843e11363bcc4e0eff419d6a3 r16-6513-gcdb15b390035fc
Merge base: cdb15b390035fc4843e11363bcc4e0eff419d6a3
Full diff url: https://forge.sourceware.org/gcc/gcc-TEST/pulls/132.diff
Discussion:  https://forge.sourceware.org/gcc/gcc-TEST/pulls/132
Requested Reviewers: rdfm, clyon

Add a Containerfile for the forge action and create an action to build
it.  Currently, the action does not push the built image to a registry.

---
Changes since v3:
  - Added script to buid images..
  - Added readme with instruction on how to build images.
  - Renamed directory to `contrib/ci-containers`
---
Changes since v3:
  - Copy autoregen.py from builder repository.
  - Squash all commits into one.
---
Changes since v2:
  - Use fedora image to build containers
---
Changes since v1:
  - Added action to build containers


Changed files:
- A: .forgejo/workflows/build-containers.yaml
- A: contrib/ci-containers/README
- A: contrib/ci-containers/autoregen/Containerfile
- A: contrib/ci-containers/autoregen/autoregen.py
- A: contrib/ci-containers/build-image.sh


Pietro Monteiro (1):
  Containerfile for base forge actions

 .forgejo/workflows/build-containers.yaml      |  55 +++++++
 contrib/ci-containers/README                  |  47 ++++++
 contrib/ci-containers/autoregen/Containerfile |  78 ++++++++++
 contrib/ci-containers/autoregen/autoregen.py  | 146 ++++++++++++++++++
 contrib/ci-containers/build-image.sh          | 104 +++++++++++++
 5 files changed, 430 insertions(+)
 create mode 100644 .forgejo/workflows/build-containers.yaml
 create mode 100644 contrib/ci-containers/README
 create mode 100644 contrib/ci-containers/autoregen/Containerfile
 create mode 100755 contrib/ci-containers/autoregen/autoregen.py
 create mode 100755 contrib/ci-containers/build-image.sh

Range-diff against v3:
1:  fc80968c8f0e ! 1:  c90915df14c0 Containerfile for base forge actions
    @@ Commit message
     
         contrib/ChangeLog:
     
    -            * ci-container/essential/Containerfile: New file.
    -            * ci-container/essential/autoregen.py: Likewise.
    +            * ci-containers/README: New file.
    +            * ci-containers/autoregen/Containerfile: New file.
    +            * ci-containers/autoregen/autoregen.py: New file.
    +            * ci-containers/build-image.sh: New file.
     
         Signed-off-by: Pietro Monteiro <[email protected]>
     
    @@ .forgejo/workflows/build-containers.yaml (new)
     +#    # run on changes to any file for ci containers or to this file
     +#    paths:
     +#      - .forgejo/workflows/build-containers.yaml
    -+#      - 'contrib/ci-container/**/*'
    ++#      - 'contrib/ci-containers/**/*'
     +  # similar for pull requests
     +  pull_request:
     +    types: [opened, synchronize, reopened]
     +    paths:
     +      - .forgejo/workflows/build-containers.yaml
    -+      - 'contrib/ci-container/**/*'
    ++      - 'contrib/ci-containers/**/*'
     +
     +jobs:
     +  containers:
    @@ .forgejo/workflows/build-containers.yaml (new)
     +
     +      - name: build containers
     +        run: |
    -+          echo "Building containers from contrib/ci-container"
    -+          for DIR in ./contrib/ci-container/*
    ++          echo "Building containers from contrib/ci-containers"
    ++          for DIR in ./contrib/ci-containers/*
     +          do
     +            ! [ -d "$DIR" ] &&  continue
     +            CONTAINER="$(basename "$DIR")"
    @@ .forgejo/workflows/build-containers.yaml (new)
     +              TAG="$FORGEJO_REF_NAME"
     +            fi
     +            echo "Building $CONTAINER with tag $TAG"
    -+            buildah build --network=host -f "$DIR/Containerfile" -t 
"$CONTAINER:$TAG" "$DIR"
    ++            ./contrib/ci-containers/build-image.sh -d "$DIR" -t "$TAG" -- 
--network=host
     +            echo "Built $CONTAINER:$TAG should push it somewhere"
     +            buildah images --json "$CONTAINER:$TAG"
     +            echo "Removing container image from localhost"
    @@ .forgejo/workflows/build-containers.yaml (new)
     +            buildah rmi --prune
     +          done
     
    - ## contrib/ci-container/essential/Containerfile (new) ##
    + ## contrib/ci-containers/README (new) ##
    +@@
    ++# CI Containers
    ++
    ++Each subdirectory under `contrib/ci-containers/` holds a hermetic 
description of
    ++a container image that powers jobs on the [Sourceware
    ++Forge](https://forge.sourceware.org).  The directory itself is used as 
the build
    ++context, so any assets referenced by the `Containerfile` must be present
    ++in the subdirectory.
    ++
    ++Keeping the description self-contained guarantees reproducible builds.
    ++
    ++## Building Images
    ++
    ++Images are built with [buildah](https://buildah.io) via the helper script
    ++`build-image.sh`.  A typical invocation looks like:
    ++
    ++```bash
    ++./contrib/ci-containers/build-image.sh \
    ++    -d ./contrib/ci-containers/foo \
    ++    -t v1.0 \
    ++    -- --layers --no-cache
    ++```
    ++
    ++* `-d` - Path to the directory containing the `Containerfile`.
    ++* `-t` - Tag to apply to the resulting image.
    ++* The trailing `--` passes additional flags directly to `buildah` (here we
    ++request layered output and disable the cache).
    ++
    ++The full image tag will be the basename of the directory, in this case 
`foo`,
    ++and the value passed to the `-t/--tag` argument.  Our hypothetical image 
will be
    ++tagged locally as `foo:v1.0`.
    ++
    ++### Verify the build
    ++
    ++```bash
    ++buildah images --json foo:v1.0
    ++```
    ++
    ++The command returns a JSON object with the image's ID, size, and other 
metadata.
    ++
    ++### Test the image locally
    ++
    ++```bash
    ++podman run --rm -it foo:v1.0 /bin/bash
    ++```
    ++
    ++By running the image interactively you can confirm that the environment 
behaves
    ++as expected.
    +
    + ## contrib/ci-containers/autoregen/Containerfile (new) ##
     @@
     +FROM debian:stable-slim
     +
    @@ contrib/ci-container/essential/Containerfile (new)
     +    [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
     +    apt-get purge -y --auto-remove -o 
APT::AutoRemove::RecommendsImportant=false
     
    - ## contrib/ci-container/essential/autoregen.py (new) ##
    + ## contrib/ci-containers/autoregen/autoregen.py (new) ##
     @@
     +#!/usr/bin/env python3
     +
    @@ contrib/ci-container/essential/autoregen.py (new)
     +        regenerate_manually()
     +    else:
     +        regenerate_with_autoreconf()
    +
    + ## contrib/ci-containers/build-image.sh (new) ##
    +@@
    ++#!/usr/bin/env bash
    ++#
    ++# Build a container using buildah
    ++#
    ++set -euo pipefail
    ++
    ++usage() {
    ++    cat <<EOF
    ++Usage: build-image.sh -d <directory> -t <tag> [-e timestamp] [-- 
buildah-args...]
    ++
    ++Options:
    ++  -d, --dir <path>        Directory with the Containerfile (required).
    ++  -t, --tag <tag> Tag to apply to the built image (required).
    ++  -e, --epoch <ts>        Set the "created" timestamp for the built image 
to this number of seconds since the epoch (optional).
    ++                  Default is to use the timestamp of the current commit.
    ++                  Needs buildah 1.41 or newer.
    ++  -h, --help              Show this help message and exit.
    ++
    ++All arguments after a double-dash (--) are forwarded unchanged to 
'buildah'.
    ++
    ++Example:
    ++  ./build-image.sh -d src -t v1.0 -- --layers --no-cache
    ++EOF
    ++    exit 1
    ++}
    ++
    ++DIR=""
    ++TAG=""
    ++EXTRA_ARGS=()
    ++
    ++while (( "$#" )); do
    ++    case "$1" in
    ++        -d|--dir)
    ++            if [[ -n "${2-}" ]]; then
    ++                DIR="$2"
    ++                shift 2
    ++            else
    ++                echo "error: --dir requires a value" >&2
    ++                exit 1
    ++            fi
    ++            ;;
    ++        -t|--tag)
    ++            if [[ -n "${2-}" ]]; then
    ++                TAG="$2"
    ++                shift 2
    ++            else
    ++                echo "error: --tag requires a value" >&2
    ++                exit 1
    ++            fi
    ++            ;;
    ++        -e|--epoch)
    ++            if [[ -n "${2-}" ]]; then
    ++                SOURCE_DATE_EPOCH="$2"
    ++                shift 2
    ++            else
    ++                echo "error: --source-date-epoch requires a value" >&2
    ++                exit 1
    ++            fi
    ++            ;;
    ++        -h|--help)
    ++            usage
    ++            ;;
    ++        --)
    ++            shift
    ++            EXTRA_ARGS+=("$@")
    ++            break
    ++            ;;
    ++        *)
    ++            echo "error: unknown option '$1'" >&2
    ++            usage
    ++            ;;
    ++    esac
    ++done
    ++
    ++if [[ -z "$DIR" ]]; then
    ++    echo "error: directory (-d/--dir) is required" >&2
    ++    usage
    ++fi
    ++
    ++if [[ -z "$TAG" ]]; then
    ++    echo "error: Tag (-t/--tag) is required." >&2
    ++    usage
    ++fi
    ++
    ++if [[ ! -e "${DIR}/Containerfile" ]]; then
    ++    echo "error: '${DIR}/Containerfile' does not exist." >&2
    ++    usage
    ++fi
    ++
    ++CONTAINER="$(basename "$DIR")"
    ++IMAGE_TAG="${CONTAINER}:${TAG}"
    ++
    ++if [[ -z "${SOURCE_DATE_EPOCH-}" ]]; then
    ++    SCRIPT_DIR="$(dirname "$0")"
    ++    SOURCE_DATE_EPOCH="$(cd "${SCRIPT_DIR}" && git log -1 --pretty=%ct)"
    ++fi
    ++export SOURCE_DATE_EPOCH
    ++
    ++
    ++buildah build \
    ++    -f "${DIR}/Containerfile" \
    ++    -t "$IMAGE_TAG" \
    ++    "${EXTRA_ARGS[@]}" \
    ++    "$DIR"
-- 
2.52.0

Reply via email to