From 5f99c5d7c09d1bd60c575770d1638cdd3efaef8e Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 22 Mar 2024 16:44:57 +0100 Subject: [PATCH] Add basic buildfarm setup in Dockerfile --- .editorconfig | 6 +++++ .github/workflows/lint.yaml | 29 +++++++++++++++++++++ .github/workflows/run.yaml | 52 +++++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 41 +++++++++++++++++++++++++++++ .gitignore | 1 + .hadolint.yaml | 5 ++++ Dockerfile | 43 ++++++++++++++++++++++++++++++ autoconf.conf | 19 ++++++++++++++ docker-entrypoint.sh | 21 +++++++++++++++ shared.conf | 13 ++++++++++ test.sh | 18 +++++++++++++ 11 files changed, 248 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/run.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 .gitignore create mode 100644 .hadolint.yaml create mode 100644 Dockerfile create mode 100644 autoconf.conf create mode 100755 docker-entrypoint.sh create mode 100644 shared.conf create mode 100755 test.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0af8017 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.conf] +indent_style = tab +indent_size = tab +tab_width = 4 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..b569dc5 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,29 @@ +name: Lint + +on: + pull_request: + push: + branches: + - main + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - uses: raven-actions/actionlint@v1.0.3 + + + hadolint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: Dockerfile + + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - uses: ludeeus/action-shellcheck@2.0.0 \ No newline at end of file diff --git a/.github/workflows/run.yaml b/.github/workflows/run.yaml new file mode 100644 index 0000000..a6b6210 --- /dev/null +++ b/.github/workflows/run.yaml @@ -0,0 +1,52 @@ +name: Run + +on: + schedule: + # The docs suggest not to schedule this on the full hour: + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule + - cron: '42 0,6,12,18 * * *' + +jobs: + run: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + branch: + - REL_12 + - REL_13 + - REL_14 + - REL_15 + - REL_16 + - HEAD + name: ${{ matrix.branch }} + steps: + - uses: actions/checkout@v4.1.1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + - name: Build Dockerfile + uses: docker/build-push-action@v5.3.0 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + load: true + push: false + tags: buildfarm-client:alpine + - uses: actions/cache@v4.0.2 + with: + path: buildroot + key: run-alpine-autoconf-${{ matrix.branch }} + - name: Run buildfarm client + run: | + mkdir -p buildroot + docker run --rm \ + -v ./buildroot:/home/alpine \ + -u "$(id -u):$(id -g)" \ + buildfarm-client:alpine \ + --test \ + --config autoconf.conf \ + --delay-check \ + ${{ matrix.branch }} + # TODO: Remove --delay-check once this is fixed: + # https://www.postgresql.org/message-id/flat/fddd1cd6-dc16-40a2-9eb5-d7fef2101488%40technowledgy.de diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..aa5e1b4 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,41 @@ +name: Test + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + name: Test autoconf + steps: + - uses: actions/checkout@v4.1.1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + - name: Build Dockerfile + uses: docker/build-push-action@v5.3.0 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + load: true + push: false + tags: buildfarm-client:alpine + - uses: actions/cache@v4.0.2 + with: + path: buildroot + key: test-alpine-autoconf + - name: Test autoconf.conf + run: | + mkdir -p buildroot + docker run --rm \ + -v ./buildroot:/home/alpine \ + -u "$(id -u):$(id -g)" \ + buildfarm-client:alpine \ + --test \ + --config autoconf.conf \ + --delay-check + # TODO: Remove --delay-check once this is fixed: + # https://www.postgresql.org/message-id/flat/fddd1cd6-dc16-40a2-9eb5-d7fef2101488%40technowledgy.de \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b26b35 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +buildroot diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..72afa5e --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,5 @@ +failure-threshold: style +ignored: + # repository pinning is better than package pinning for apk + # https://stschindler.medium.com/the-problem-with-docker-and-alpines-package-pinning-18346593e891 + - DL3018 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2adf6f5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM library/alpine:3.19.1@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b + +SHELL ["/bin/sh", "-eux", "-c"] + +RUN apk add \ + --no-cache \ + bison \ + build-base \ + ccache \ + flex \ + git \ + krb5-dev \ + # TODO: Make meson find this instead of readline \ + #libedit-dev \ + libxml2-dev \ + libxslt-dev \ + linux-headers \ + nss_wrapper \ + openldap-dev \ + openssl-dev \ + perl \ + perl-dev \ + perl-lwp-protocol-https \ + perl-mozilla-ca \ + python3-dev \ + readline-dev \ + tcl-dev \ + zlib-dev + +ARG BUILDFARM_CLIENT_VERSION=REL_17 + +RUN git clone --depth 1 --branch ${BUILDFARM_CLIENT_VERSION} https://github.com/PGBuildFarm/client-code /usr/src + +COPY docker-entrypoint.sh / +COPY *.conf /usr/src + +WORKDIR /buildroot +VOLUME /buildroot + +ENTRYPOINT ["/docker-entrypoint.sh"] +# TODO: Remove --delay-check once this is fixed: +# https://www.postgresql.org/message-id/flat/fddd1cd6-dc16-40a2-9eb5-d7fef2101488%40technowledgy.de +CMD ["--test", "--config", "autoconf.conf", "--delay-check"] diff --git a/autoconf.conf b/autoconf.conf new file mode 100644 index 0000000..d4eadbe --- /dev/null +++ b/autoconf.conf @@ -0,0 +1,19 @@ +require 'shared.conf'; + +@PGBuild::conf{animal} = $ENV{AUTOCONF_ANIMAL} // @PGBuild::conf{animal}; +@PGBuild::conf{secret} = $ENV{AUTOCONF_SECRET} // @PGBuild::conf{secret}; + +@PGBuild::conf{make_jobs} = 2; + +# TODO: Building with --enable-nls currently fails with: +# ld: ../../src/port/libpgport.a(strerror.o): in function `pg_strerror_r': +# src/port/strerror.c:72:(.text+0x260): undefined reference to `libintl_gettext' +# ld: src/port/strerror.c:72:(.text+0x2d8): undefined reference to `libintl_gettext' +push(@{@PGBuild::conf{config_opts}}, "--disable-nls"); + +# TODO: Currently failing two tests: +# initdb/001_initdb +# icu / icu/010_database +push(@{@PGBuild::conf{config_opts}}, "--without-icu"); + +1; diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..0f48023 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh +set -eu + +# This script fakes passwd/group files via nss_wrapper to satisfy +# initdb's requirement of having a user with a name. We do this, +# because the uid/gid passed from outside are not known in advance. +# Thus we can't create the corresponding users/groups beforehand. + +LD_PRELOAD="/usr/lib/libnss_wrapper.so" +NSS_WRAPPER_PASSWD="$(mktemp)" +NSS_WRAPPER_GROUP="$(mktemp)" + +uid="$(id -u)" +gid="$(id -g)" + +printf 'postgres:x:%s:%s::/buildroot:/bin/false\n' "$uid" "$gid" > "$NSS_WRAPPER_PASSWD" +printf 'postgres:x:%s:\n' "$gid" > "$NSS_WRAPPER_GROUP" + +export LD_PRELOAD NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP + +exec /usr/src/run_build.pl "$@" diff --git a/shared.conf b/shared.conf new file mode 100644 index 0000000..9f5b82b --- /dev/null +++ b/shared.conf @@ -0,0 +1,13 @@ +require 'build-farm.conf.sample'; + +@PGBuild::conf{build_root} = '/home/alpine'; + +@PGBuild::conf{alerts} = { + HEAD => { alert_after => 9, alert_every => 24 } +}; + +@PGBuild::conf{mail_eventsalerts} = { + all => [$ENV{BUILDFARM_EMAIL_ALL}] +}; + +1; diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..3d6018c --- /dev/null +++ b/test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh +set -eu + +# Run this script to test the Dockerfile locally. + +docker build . + +mkdir -p buildroot +docker run --rm \ + -v ./buildroot:/home/alpine \ + -u "$(id -u):$(id -g)" \ + "$(docker build -q .)" \ + --test \ + --config autoconf.conf \ + --delay-check \ + "$@" + # TODO: Remove --delay-check once this is fixed: + # https://www.postgresql.org/message-id/flat/fddd1cd6-dc16-40a2-9eb5-d7fef2101488%40technowledgy.de