diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..4a106afc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +.git +**/.git +.agents +.codex +.aws +.env* +.DS_Store +.idea +build +cmake-build-* +dist +elog +elogd +elconv +*.o +src/git-revision.h +src/git-revision.h.tmp +elog.spec diff --git a/.gitea/scripts/build-rpm.sh b/.gitea/scripts/build-rpm.sh new file mode 100644 index 00000000..8cf7ed3b --- /dev/null +++ b/.gitea/scripts/build-rpm.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Run inside docker/Dockerfile.build, or on an EL host with build dependencies. +set -euo pipefail +cd "$(dirname "$0")/../.." + +release=${1:?Usage: build-rpm.sh RPM_RELEASE OUTPUT_DIRECTORY} +output=${2:?Usage: build-rpm.sh RPM_RELEASE OUTPUT_DIRECTORY} +[[ "$release" =~ ^[0-9][0-9A-Za-z.]*$ ]] || { echo 'Invalid RPM release' >&2; exit 1; } +version=$(sed -n 's/^#define VERSION "\([0-9][0-9.]*\)"/\1/p' src/elog-version.h) +[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Invalid source version' >&2; exit 1; } +[[ -f mxml/mxml.cxx ]] || { echo 'Run git submodule update --init --recursive first' >&2; exit 1; } +revision=${ELOG_BUILD_REVISION:-$(git rev-parse HEAD)} +[[ "$revision" =~ ^[0-9a-f]{40}$|^unknown$ ]] || { echo 'Invalid revision' >&2; exit 1; } + +mkdir -p "$output" +output=$(cd "$output" && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +name="elog-$version-$release" +source_dir="$work/$name" +topdir="$work/rpmbuild" +mkdir -p "$source_dir" "$topdir"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} + +# Include the checked-out submodule, without nesting Git metadata in releases. +tar --exclude=.git --exclude=git-revision.h --exclude=git-revision.h.tmp -cf - \ + src mxml doc man contrib scripts resources ssl themes logbooks cmake \ + CMakeLists.txt Makefile COPYING README.md elogd.cfg.example \ + elogd.init_template elogd.service elogd.plist makegit \ + | tar -xf - -C "$source_dir" +cp README.md "$source_dir/README" # The existing RPM spec installs this name. +printf '#define GIT_REVISION "%s"\n' "$revision" > "$source_dir/src/git-revision.h" +sed -e "s/__ELOGVER__/$version/g" -e "s/__ELOGREL__/$release/g" \ + -e "s/__GIT__/$revision/g" elog.spec.template > "$topdir/SPECS/elog.spec" +cp "$topdir/SPECS/elog.spec" "$source_dir/elog.spec" +tar -czf "$topdir/SOURCES/$name.tar.gz" -C "$work" "$name" + +rpmbuild -ba "$topdir/SPECS/elog.spec" \ + --define "_topdir $topdir" --define 'debug_package %{nil}' \ + --with krb5 --with ldap --with pam --with ssl + +mkdir -p "$output"/{RPMS,SRPMS,SOURCES} +find "$topdir/RPMS" -name '*.rpm' -exec cp '{}' "$output/RPMS/" \; +cp "$topdir"/SRPMS/*.rpm "$output/SRPMS/" +cp "$topdir/SOURCES/$name.tar.gz" "$output/SOURCES/" +printf 'version=%s\nrelease=%s\nrevision=%s\n' "$version" "$release" "$revision" > "$output/build-info.txt" +cd "$output" +find RPMS SRPMS SOURCES -type f -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS diff --git a/.gitea/scripts/metadata.sh b/.gitea/scripts/metadata.sh new file mode 100644 index 00000000..584931be --- /dev/null +++ b/.gitea/scripts/metadata.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail +export TZ=UTC +cd "$(dirname "$0")/../.." + +version=$(sed -n 's/^#define VERSION "\([0-9][0-9.]*\)"/\1/p' src/elog-version.h) +[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Invalid source version' >&2; exit 1; } +revision=$(git rev-parse HEAD) +short_revision=${revision:0:12} +epoch=$(git show -s --format=%ct HEAD) +timestamp=$(git show -s --format=%cd --date=format-local:%Y%m%d%H%M%S HEAD) +ref=${BUILD_REF:-refs/heads/local} + +if [[ "$ref" == refs/tags/* ]]; then + [[ "$ref" == "refs/tags/v$version" ]] || { + echo "Release tag must be v$version to match src/elog-version.h" >&2 + exit 1 + } + release=1 + image_tag=$version +else + release="0.$timestamp.git$short_revision" + image_tag="sha-$short_revision" +fi + +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + exec >> "$GITHUB_OUTPUT" +fi +{ + printf 'version=%s\n' "$version" + printf 'revision=%s\n' "$revision" + printf 'source_date_epoch=%s\n' "$epoch" + printf 'rpm_release=%s\n' "$release" + printf 'image_tag=%s\n' "$image_tag" +} diff --git a/.gitea/scripts/smoke-container.sh b/.gitea/scripts/smoke-container.sh new file mode 100644 index 00000000..74efc986 --- /dev/null +++ b/.gitea/scripts/smoke-container.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +image=${1:?Usage: smoke-container.sh IMAGE} +container=$(docker run --detach "$image") +# shellcheck disable=SC2329 # Invoked by the EXIT trap. +cleanup() { + if [[ "$?" != 0 ]]; then docker logs "$container" >&2 || true; fi + docker rm --force "$container" >/dev/null +} +trap 'cleanup' EXIT +for _attempt in {1..30}; do + # Run in the container's network namespace: runners may themselves be containers. + if docker exec "$container" bash -c ' + exec 3<>/dev/tcp/127.0.0.1/8080 + printf "GET /demo/ HTTP/1.0\r\nHost: localhost\r\n\r\n" >&3 + IFS= read -r -t 5 status <&3 + [[ "$status" == *" 200 "* ]] + ' 2>/dev/null; then + echo 'ELOG container HTTP smoke check passed' + exit 0 + fi + [[ "$(docker inspect -f '{{.State.Running}}' "$container")" == true ]] || break + sleep 1 +done +echo 'ELOG container HTTP smoke check failed' >&2 +exit 1 diff --git a/.gitea/scripts/smoke-server.sh b/.gitea/scripts/smoke-server.sh new file mode 100644 index 00000000..719ed2e2 --- /dev/null +++ b/.gitea/scripts/smoke-server.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail +binary=${1:?Usage: smoke-server.sh ELOGD RESOURCE_DIRECTORY} +resources=${2:?Usage: smoke-server.sh ELOGD RESOURCE_DIRECTORY} +work=$(mktemp -d) +pid= +# shellcheck disable=SC2329 # Invoked by the EXIT trap. +cleanup() { + if [[ -n "$pid" ]]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi + rm -rf "$work" +} +trap 'cleanup' EXIT +mkdir "$work/logbooks" +cat > "$work/elogd.cfg" <<'EOF' +[global] +Usr = root +Grp = root +Logging Level = 0 +Resolve host names = 0 +[ci] +Attributes = Subject +EOF +"$binary" -c "$work/elogd.cfg" -d "$work/logbooks" -s "$resources" \ + -n 127.0.0.1 -p 8080 -f "$work/elogd.pid" > "$work/elogd.log" 2>&1 & +pid=$! +for _attempt in {1..30}; do + if curl --noproxy '*' --fail --silent --show-error --max-time 2 http://127.0.0.1:8080/ci/ > "$work/index.html" 2>/dev/null; then + if grep -qi 'ELOG' "$work/index.html"; then + echo 'ELOG HTTP smoke check passed' + exit 0 + fi + fi + kill -0 "$pid" 2>/dev/null || break + sleep 1 +done +cat "$work/elogd.log" >&2 +echo 'ELOG HTTP smoke check failed' >&2 +exit 1 diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 00000000..bcd17724 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,115 @@ +name: Build, test and package ELOG + +on: + push: + branches: ['**'] + tags: ['v*'] + pull_request: + workflow_dispatch: + +env: + # Keep the image address used by deployments from the former images/elog repo. + CONTAINER_IMAGE: gitea.psi.ch/images/elog + +jobs: + packages: + name: Build and test EL${{ matrix.el }} + runs-on: ubuntu-latest-intranet + strategy: + fail-fast: false + matrix: + el: [8, 9, 10] + steps: + - name: Checkout source and mxml + uses: https://gitea.psi.ch/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + submodules: recursive + persist-credentials: false + - name: Derive version and validate release tag + id: metadata + env: + BUILD_REF: ${{ github.ref }} + run: bash .gitea/scripts/metadata.sh + - name: Build, HTTP-test and export packages + env: + EL_VERSION: ${{ matrix.el }} + REVISION: ${{ steps.metadata.outputs.revision }} + RPM_RELEASE: ${{ steps.metadata.outputs.rpm_release }} + SOURCE_DATE_EPOCH: ${{ steps.metadata.outputs.source_date_epoch }} + run: | + docker build --platform linux/amd64 --file docker/Dockerfile.build \ + --build-arg "EL_VERSION=$EL_VERSION" \ + --build-arg "REVISION=$REVISION" \ + --build-arg "RPM_RELEASE=$RPM_RELEASE" \ + --build-arg "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" \ + --output "type=local,dest=dist/el$EL_VERSION" . + - name: Store RPMs, source archive and checksums + # PSI's Node 20 build of the Gitea-compatible v3 artifact protocol. + uses: https://gitea.psi.ch/actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 + with: + name: elog-el${{ matrix.el }} + path: dist/el${{ matrix.el }}/ + if-no-files-found: error + retention-days: 30 + + container: + name: Build and test EL9 container + needs: packages + runs-on: ubuntu-latest-intranet + steps: + - name: Checkout + uses: https://gitea.psi.ch/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + - name: Download the tested EL9 RPM + uses: https://gitea.psi.ch/actions/download-artifact@ad191675b41f6a5b46da9a048cb6893812da158b # v3.1.0-node20 + with: + name: elog-el9 + path: dist/el9 + - name: Verify artifacts + run: cd dist/el9 && sha256sum --check SHA256SUMS + - name: Derive image version + id: metadata + env: + BUILD_REF: ${{ github.ref }} + run: bash .gitea/scripts/metadata.sh + - name: Build runtime image from the tested RPM + env: + VERSION: ${{ steps.metadata.outputs.version }} + REVISION: ${{ steps.metadata.outputs.revision }} + run: | + docker build --platform linux/amd64 \ + --build-arg "VERSION=$VERSION" --build-arg "REVISION=$REVISION" \ + --tag "elog-ci:$GITHUB_RUN_ID" . + bash .gitea/scripts/smoke-container.sh "elog-ci:$GITHUB_RUN_ID" + - name: Publish snapshots or versioned release image + # PRs, feature branches and manual runs never receive the registry token. + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + IMAGE_TAG: ${{ steps.metadata.outputs.image_tag }} + BUILD_REF: ${{ github.ref }} + run: | + set -euo pipefail + : "${REGISTRY_USERNAME:?Set REGISTRY_USERNAME to the package token owner}" + : "${REGISTRY_TOKEN:?Set REGISTRY_TOKEN with write:package access to images/elog}" + export DOCKER_CONFIG + DOCKER_CONFIG=$(mktemp -d) + trap 'rm -rf "$DOCKER_CONFIG"' EXIT + printf '%s' "$REGISTRY_TOKEN" | docker login gitea.psi.ch \ + --username "$REGISTRY_USERNAME" --password-stdin + docker tag "elog-ci:$GITHUB_RUN_ID" "$CONTAINER_IMAGE:$IMAGE_TAG" + docker push "$CONTAINER_IMAGE:$IMAGE_TAG" + docker image rm "$CONTAINER_IMAGE:$IMAGE_TAG" + if [[ "$BUILD_REF" == refs/tags/* ]]; then + # Deliberately leave latest promotion to the release operator. + echo "Release image published as $CONTAINER_IMAGE:$IMAGE_TAG" + else + docker tag "elog-ci:$GITHUB_RUN_ID" "$CONTAINER_IMAGE:edge" + docker push "$CONTAINER_IMAGE:edge" + docker image rm "$CONTAINER_IMAGE:edge" + fi + - name: Remove local CI image + if: always() + run: docker image rm "elog-ci:$GITHUB_RUN_ID" || true diff --git a/.gitignore b/.gitignore index 33c6a615..c612a630 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ cmake-build-debug cmake-build-release build xcode +dist/ diff --git a/Dockerfile b/Dockerfile index 8d49e21f..a10e4c8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,20 @@ -FROM gcc:latest -RUN apt-get -qq update && apt-get -y -qq install cmake && apt-get -y -qq install emacs -RUN git clone --quiet https://ritt@bitbucket.org/ritt/elog.git -WORKDIR /elog -RUN git submodule update --init -RUN mkdir build && cd build && cmake .. && make -RUN ls -l build +ARG RUNTIME_IMAGE=gitea.psi.ch/images/rhel9:latest +FROM ${RUNTIME_IMAGE} + +ARG VERSION=unknown +ARG REVISION=unknown +LABEL org.opencontainers.image.title="ELOG" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.revision="${REVISION}" + +# Install the RPM produced from this checkout, rather than the repository's latest. +COPY dist/el9/RPMS/*.rpm /tmp/elog-rpms/ +# Prefer libraries already present in the PSI base; resolve any missing ones online. +RUN (dnf install -y --disablerepo='*' /tmp/elog-rpms/*.rpm \ + || dnf install -y /tmp/elog-rpms/*.rpm) \ + && dnf clean all \ + && rm -rf /tmp/elog-rpms /var/cache/dnf + +COPY docker/krb5.conf /etc/krb5.conf +EXPOSE 8080 +CMD ["elogd", "-c", "/usr/local/elog/elogd.cfg"] diff --git a/Dockerfile.dockerignore b/Dockerfile.dockerignore new file mode 100644 index 00000000..eddb29bc --- /dev/null +++ b/Dockerfile.dockerignore @@ -0,0 +1,8 @@ +# The runtime image needs only the tested RPM and Kerberos configuration. +** +!dist/ +!dist/el9/ +!dist/el9/RPMS/ +!dist/el9/RPMS/*.rpm +!docker/ +!docker/krb5.conf diff --git a/README.md b/README.md index a1178358..29cb7be9 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ Welcome to the ELOG package This is ELOG, an electronic logbook. +Builds and container images are managed here with Gitea Actions. See +[CI, container usage and release recommendations](doc/ci-and-releases.md). + For the full documentation please visit: https://elog.psi.ch/elog Please send all bug reports and comments to [stefan.ritt@psi.ch](stefan.ritt@psi.ch) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 98b63e07..00000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,99 +0,0 @@ -# ELOG Application - -# This template allows you to validate your C++ application. -# The workflow allows running tests and code linting on the default branch. - -image: gcc:latest - - -pipelines: - default: - - step: - name: Build run and test - image: gcc:latest - deployment: test - script: - # Execute your C++ application after compilation to check success - - apt-get -qq update && apt-get -y --force-yes -qq install cmake wget lsof - - git submodule update --init - # Add elog user - - groupadd -r elog - - useradd -d / -s /bin/false -g elog -M -r elog - # Build elog - - mkdir build; cd build - - cmake .. - - make - # Install in default /usr/local/elog - - echo "install in test environment" - - make install - # Start elogd - - echo "Start ELOG" - - /usr/local/sbin/elogd -v 3 -c /usr/local/elog/elogd.cfg 2>&1 & - - sleep 5 - - if [ -f /var/run/elogd.pid ]; then cat /var/run/elogd.pid ; fi - # Check open files - - lsof -p $(cat /var/run/elogd.pid) - # Test Web page - - echo "test web" - - sleep 3 - - wget http://localhost:8080 && true || false - - parallel: - steps: - - step: - name: Build on EL7 - image: mydumper/mydumper-builder-el7 - # trigger: manual # Uncomment to make this a manual deployment. - script: - - echo "Deploying to test environment" - - yum -y update && yum -y install rpm-build gcc gcc-c++ git openssl-devel krb5-devel pam-devel openldap-devel csh which - - git submodule update --init - # git clone https://bitbucket.org/ritt/elog --recursive - - ./buildrpm 3.1.5 $(date +%Y%m%d) -krb5 -ldap -pam -ssl - - mkdir RPMS - - find ~/rpmbuild/RPMS/ -name "*.rpm" -exec mv {} RPMS \; - - ls -l RPMS - artifacts: # defining the artifacts to be passed to each future step. - download: false # do not download artifacts in this step - paths: - - RPMS/*.rpm - - step: - name: Build on EL8 - image: lj020326/centos8-systemd - # trigger: manual # Uncomment to make this a manual deployment. - script: - - echo "Deploying to test environment" - - yum -y update && yum -y install rpm-build gcc gcc-c++ git openssl-devel krb5-devel pam-devel openldap-devel csh make cmake - - git submodule update --init - # git clone https://bitbucket.org/ritt/elog --recursive - - ./buildrpm 3.1.5 $(date +%Y%m%d) -krb5 -ldap -pam -ssl - - mkdir RPMS - - find ~/rpmbuild/RPMS/ -name "*.rpm" -exec mv {} RPMS \; - - ls -l RPMS - artifacts: # defining the artifacts to be passed to each future step. - download: false # do not download artifacts in this step - paths: - - RPMS/*.rpm - - step: - name: Build on EL9 - image: dokken/centos-stream-9 - # trigger: manual # Uncomment to make this a manual deployment. - script: - - echo "Deploying to test environment" - - yum -y update && yum -y install rpm-build gcc gcc-c++ git openssl-devel krb5-devel pam-devel openldap-devel csh - - git submodule update --init - # git clone https://bitbucket.org/ritt/elog --recursive - - ./buildrpm 3.1.5 $(date +%Y%m%d) -krb5 -ldap -pam -ssl - - mkdir RPMS - - find ~/rpmbuild/RPMS/ -name "*.rpm" -exec mv {} RPMS \; - - ls -l RPMS - artifacts: # defining the artifacts to be passed to each future step. - download: false # do not download artifacts in this step - paths: - - RPMS/*.rpm - - step: # non-parallel step - name: Deployement - deployment: staging - script: - - echo "Deliver results" - - ls -l RPMS - diff --git a/doc/ci-and-releases.md b/doc/ci-and-releases.md new file mode 100644 index 00000000..1b1d855d --- /dev/null +++ b/doc/ci-and-releases.md @@ -0,0 +1,146 @@ +# Gitea builds, containers and releases + +The source, RPM build and container definition now live in this repository. +`.gitea/workflows/build.yml` replaces `bitbucket-pipelines.yml` and the build +workflow from `images/elog`. The published container address stays +`gitea.psi.ch/images/elog` so deployments can keep their existing registry path. + +## Builds + +Every branch push, pull request and manual run builds x86_64 packages for EL8, +EL9 and EL10 using Rocky Linux build containers. Each build: + +1. Checks out the pinned `mxml` submodule. +2. Builds with CMake and checks the running daemon over HTTP. +3. Builds binary and source RPMs with SSL, Kerberos, LDAP and PAM enabled. +4. Installs the RPM and repeats the HTTP check. +5. Uploads an `elog-el8`, `elog-el9` or `elog-el10` artifact containing `RPMS`, `SRPMS`, + `SOURCES`, `build-info.txt` and `SHA256SUMS`. + +After all three builds pass, the container job downloads the tested EL9 artifact, +checks its SHA256 sums, builds the runtime image and checks its HTTP response. +The runtime installs that exact RPM; it does not install ELOG from a separately +maintained package repository. The existing PSI RHEL9 base and Kerberos settings +from `images/elog` are retained. + +The supported package targets are EL8, EL9 and EL10. The old EL7 builder is +removed from routine CI. + +| Trigger | RPM release | Published image tags | +| --- | --- | --- | +| Feature branch, pull request or manual run | `0..git` | None | +| Push to `master` | `0..git` | `sha-<12-character sha>`, `edge` | +| Push of `vX.Y.Z` matching the source version | `1` | `X.Y.Z` | + +The version comes from `src/elog-version.h`; it is no longer hard-coded in CI. +Snapshot RPM releases sort before release `1` of the same version. Tag names +that do not match the source version fail before building. Prerelease tags are +not implemented yet. `latest` is deliberately promoted separately, after a +release has been reviewed. + +## Gitea setup and cutover + +1. Enable Actions on this repository. Provide an `ubuntu-latest-intranet` runner + with Docker/BuildKit, an amd64 build environment, Bash, Git and Node 20/24. + It needs access to PSI Gitea, `gitea.psi.ch/images/rhel9`, `repos.psi.ch`, Docker + Hub and the Rocky package repositories. The runtime base must be readable by validation + jobs without the publishing token, including pull requests. +2. Set Actions secrets `REGISTRY_USERNAME` and `REGISTRY_TOKEN` here. The username + must be the account owning the token, and the token needs `write:package` + access plus permission to publish under the `images` organization. The source + repository owner (`ritt`) is not the package namespace (`images`). +3. Push the migration branch and inspect the RPM artifacts and the container + check before merging. The branch does not publish images. +4. Disable the old `images/elog` build workflow when cutting over; otherwise it + can still overwrite `latest` with its independently sourced RPM. Archive that + repository after the new workflow has passed on `master`. +5. Retire the Bitbucket pipeline after the Gitea build is confirmed. There is no + deployment step: publishing an image does not restart running services. + +Actions are fetched from verified PSI mirrors and pinned to commits. The artifact +actions use PSI's Node 20 variants of the v3 protocol; update upload and download +together when changing protocols. Registry credentials are provided only to the +publishing step on `master` and version tag pushes, using a temporary Docker +configuration. Gitea's automatic job token cannot publish container packages: +see the [Gitea compatibility documentation](https://docs.gitea.com/usage/actions/comparison/). + +## Suggested release process + +1. Protect `master` and `v*` tags in Gitea. Require all three package builds and the + container check before merging. Restrict release tag creation to maintainers. +2. Update `src/elog-version.h` and `doc/ChangeLog` in a reviewed change. Use patch + versions for compatible fixes, minor versions for compatible features and + major versions for breaking changes. +3. Create an annotated tag on the reviewed commit, for example `v3.1.6` for the + current header. Push the tag only when ready to build a release. The tag build + produces `elog-3.1.6-1.el8.x86_64.rpm`, its EL9/EL10 equivalents, source RPMs and + source archives, plus `gitea.psi.ch/images/elog:3.1.6`. +4. Create a draft Gitea Release for the tag. Attach the contents of all three CI + artifacts, keeping files for each EL version in separate directories/archives so + their checksum manifests remain usable. Include changes, upgrade notes and + the full image digest. Review it, then publish the release. CI artifacts expire + after 30 days, so release assets are the durable download location. +5. Promote the reviewed image to `latest`, then deploy by version or digest. + Keep `edge` for integration testing. Never move an existing version tag; + publish a new version when a released artifact must change. + +After releasing, bump the source version for the next development cycle so that +its snapshot RPMs sort after the previous stable version. + +For a registry login with publishing access, promotion can use: + +```sh +docker buildx imagetools create \ + --tag gitea.psi.ch/images/elog:latest \ + gitea.psi.ch/images/elog:3.1.6 +``` + +Automating draft release creation and asset attachment is a useful next step. +RPM signing and publishing to Gitea's RPM registry would also let native installs +consume tested releases directly; these require choosing a signing identity and +package repository policy. Rebuilding for base-image updates should have its own +revision/tag convention before it is automated, so a release tag continues to +identify a reviewed artifact. + +## Local validation + +Initialize the submodule, then build and export the same packages used in CI: + +```sh +git submodule update --init --recursive +docker build --platform linux/amd64 -f docker/Dockerfile.build \ + --build-arg EL_VERSION=9 \ + --build-arg "REVISION=$(git rev-parse HEAD)" \ + --build-arg "SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)" \ + --build-arg RPM_RELEASE=0.local \ + --output type=local,dest=dist/el9 . +docker build --platform linux/amd64 -t elog:local . +bash .gitea/scripts/smoke-container.sh elog:local +``` + +Use `EL_VERSION=8` and `dest=dist/el8`, or `EL_VERSION=10` and `dest=dist/el10`, +for the other package checks. EL10 requires an +[x86-64-v3 capable build host](https://docs.rockylinux.org/guides/minimum_hardware_requirements/). +If the PSI base +is unavailable, `--build-arg RUNTIME_IMAGE=rockylinux:9` allows local runtime +validation; production continues to use the PSI base. + +## Running the container + +Mount a valid configuration and persistent data. The default configuration and +demo logbook are installed with the RPM. For your own configuration, set logbook +directories beneath `/var/lib/elog`, or pass `-d /var/lib/elog` explicitly: + +```sh +docker run --rm -p 8080:8080 \ + -v "$PWD/elogd.cfg:/usr/local/elog/elogd.cfg:ro" \ + -v "$PWD/logbook-data:/var/lib/elog" \ + gitea.psi.ch/images/elog:3.1.6 \ + elogd -c /usr/local/elog/elogd.cfg -d /var/lib/elog +``` + +The data directory must be writable by the `elog` account in the container. +Existing installations using an AIT NFS share can keep that mount and their +configured logbook paths. Do not store logbook data only in the container layer. +For configuration examples see `elogd.cfg.example` and the +[ELOG configuration manual](https://elog.psi.ch/elog/config.html). diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build new file mode 100644 index 00000000..46b9bed6 --- /dev/null +++ b/docker/Dockerfile.build @@ -0,0 +1,31 @@ +# syntax=docker/dockerfile:1 +ARG EL_VERSION=9 +FROM rockylinux:${EL_VERSION} AS build +ARG EL_VERSION +RUN dnf install -y dnf-plugins-core \ + && if [ "$EL_VERSION" = 8 ]; then \ + dnf config-manager --set-enabled powertools; \ + else \ + dnf config-manager --set-enabled crb; \ + fi \ + && dnf install -y --allowerasing rpm-build gcc gcc-c++ make cmake git which \ + openssl-devel krb5-devel pam-devel openldap-devel curl \ + && dnf clean all + +WORKDIR /src +COPY . . +ARG REVISION=unknown +ARG SOURCE_DATE_EPOCH=0 +ARG RPM_RELEASE=0.local +ENV ELOG_BUILD_REVISION=${REVISION} SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} + +# Keep the old CMake build/start/HTTP check, as well as the full-feature RPM build. +RUN cmake -S . -B /tmp/elog-cmake -DCMAKE_BUILD_TYPE=Release \ + && cmake --build /tmp/elog-cmake --parallel 2 \ + && bash .gitea/scripts/smoke-server.sh /tmp/elog-cmake/elogd /src \ + && bash .gitea/scripts/build-rpm.sh "$RPM_RELEASE" /out \ + && dnf install -y --disablerepo='*' /out/RPMS/*.rpm \ + && bash .gitea/scripts/smoke-server.sh /usr/local/sbin/elogd /usr/local/elog + +FROM scratch AS packages +COPY --from=build /out/ / diff --git a/docker/krb5.conf b/docker/krb5.conf new file mode 100644 index 00000000..2f4e27ab --- /dev/null +++ b/docker/krb5.conf @@ -0,0 +1,21 @@ +[libdefaults] + default_realm = D.PSI.CH + dns_lookup_realm = false + ticket_lifetime = 10h + renew_lifetime = 30d + forwardable = true + rdns = false + udp_preference_limit = 10 + default_ccache_name = FILE:/tmp/krb5cc_%{uid} + +[realms] + D.PSI.CH = { + kdc = dc00.d.psi.ch + kdc = dc01.d.psi.ch + kdc = dc02.d.psi.ch + admin_server = dc00.d.psi.ch + } + +[domain_realm] + psi.ch = D.PSI.CH + .psi.ch = D.PSI.CH diff --git a/makegit b/makegit index 79056e58..c7353668 100755 --- a/makegit +++ b/makegit @@ -1 +1,7 @@ -echo \#define GIT_REVISION \"`git log -n 1 --pretty=format:'%ad - %h' --date=short`\" +#!/bin/sh +# Docker builds receive the revision without copying Git metadata/credentials. +revision=${ELOG_BUILD_REVISION:-} +if [ -z "$revision" ]; then + revision=$(git log -n 1 --pretty=format:'%ad - %h' --date=short 2>/dev/null) || revision=unknown +fi +printf '#define GIT_REVISION "%s"\n' "$revision"