From e8496e91b8d759515fa2302dfdf9c2941961d35b Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 18 Sep 2023 22:28:47 -0700 Subject: [PATCH] Improve templating so it can be verified in CI --- .gitattributes | 3 + .github/workflows/ci.yml | 4 ++ .github/workflows/verify-templating.yml | 24 +++++++ .gitignore | 1 + 11-to-12/Dockerfile | 20 ++++-- 11-to-13/Dockerfile | 20 ++++-- 11-to-14/Dockerfile | 20 ++++-- 11-to-15/Dockerfile | 20 ++++-- 11-to-16/Dockerfile | 20 ++++-- 12-to-13/Dockerfile | 20 ++++-- 12-to-14/Dockerfile | 20 ++++-- 12-to-15/Dockerfile | 20 ++++-- 12-to-16/Dockerfile | 20 ++++-- 13-to-14/Dockerfile | 20 ++++-- 13-to-15/Dockerfile | 20 ++++-- 13-to-16/Dockerfile | 20 ++++-- 14-to-15/Dockerfile | 20 ++++-- 14-to-16/Dockerfile | 20 ++++-- 15-to-16/Dockerfile | 20 ++++-- Dockerfile.template | 27 ++++---- apply-templates.sh | 43 ++++++++++++ update.sh | 53 +------------- versions.json | 92 +++++++++++++++++++++++++ versions.sh | 55 +++++++++++++++ 24 files changed, 465 insertions(+), 137 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/verify-templating.yml create mode 100644 .gitignore create mode 100755 apply-templates.sh create mode 100644 versions.json create mode 100755 versions.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..daded71 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/*/**/Dockerfile linguist-generated +/*/**/docker-upgrade linguist-generated +/Dockerfile.template linguist-language=Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d83522..1444c9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,15 @@ name: CI on: pull_request: push: + schedule: + - cron: 0 0 * * 0 defaults: run: shell: 'bash -Eeuo pipefail -x {0}' +# TODO generate-stackbrew-library + proper matrix + jobs: test: name: Smoke Test diff --git a/.github/workflows/verify-templating.yml b/.github/workflows/verify-templating.yml new file mode 100644 index 0000000..d796089 --- /dev/null +++ b/.github/workflows/verify-templating.yml @@ -0,0 +1,24 @@ +name: Verify Templating + +on: + pull_request: + push: + +defaults: + run: + shell: 'bash -Eeuo pipefail -x {0}' + +jobs: + apply-templates: + name: Check For Uncomitted Changes + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Clean + run: rm -rf */ + - name: Apply Templates + run: ./apply-templates.sh + - name: Check Git Status + run: | + status="$(git status --short)" + [ -z "$status" ] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d548f66 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.jq-template.awk diff --git a/11-to-12/Dockerfile b/11-to-12/Dockerfile index 5b660fc..55f58f0 100644 --- a/11-to-12/Dockerfile +++ b/11-to-12/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:12-bookworm RUN sed -i 's/$/ 11/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-11=11.21-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-11='11.21-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/11/bin ENV PGBINNEW /usr/lib/postgresql/12/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/12/bin ENV PGDATAOLD /var/lib/postgresql/11/data ENV PGDATANEW /var/lib/postgresql/12/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/11-to-13/Dockerfile b/11-to-13/Dockerfile index 1f2c206..37ca6d7 100644 --- a/11-to-13/Dockerfile +++ b/11-to-13/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:13-bookworm RUN sed -i 's/$/ 11/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-11=11.21-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-11='11.21-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/11/bin ENV PGBINNEW /usr/lib/postgresql/13/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/13/bin ENV PGDATAOLD /var/lib/postgresql/11/data ENV PGDATANEW /var/lib/postgresql/13/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/11-to-14/Dockerfile b/11-to-14/Dockerfile index e1935da..b56be6d 100644 --- a/11-to-14/Dockerfile +++ b/11-to-14/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:14-bookworm RUN sed -i 's/$/ 11/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-11=11.21-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-11='11.21-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/11/bin ENV PGBINNEW /usr/lib/postgresql/14/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/14/bin ENV PGDATAOLD /var/lib/postgresql/11/data ENV PGDATANEW /var/lib/postgresql/14/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/11-to-15/Dockerfile b/11-to-15/Dockerfile index 40c2f74..3eb582b 100644 --- a/11-to-15/Dockerfile +++ b/11-to-15/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:15-bookworm RUN sed -i 's/$/ 11/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-11=11.21-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-11='11.21-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/11/bin ENV PGBINNEW /usr/lib/postgresql/15/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/15/bin ENV PGDATAOLD /var/lib/postgresql/11/data ENV PGDATANEW /var/lib/postgresql/15/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/11-to-16/Dockerfile b/11-to-16/Dockerfile index 82969eb..c26e14d 100644 --- a/11-to-16/Dockerfile +++ b/11-to-16/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:16-bookworm RUN sed -i 's/$/ 11/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-11=11.21-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-11='11.21-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/11/bin ENV PGBINNEW /usr/lib/postgresql/16/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/16/bin ENV PGDATAOLD /var/lib/postgresql/11/data ENV PGDATANEW /var/lib/postgresql/16/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/12-to-13/Dockerfile b/12-to-13/Dockerfile index bad3b0d..3247670 100644 --- a/12-to-13/Dockerfile +++ b/12-to-13/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:13-bookworm RUN sed -i 's/$/ 12/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-12=12.16-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-12='12.16-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/12/bin ENV PGBINNEW /usr/lib/postgresql/13/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/13/bin ENV PGDATAOLD /var/lib/postgresql/12/data ENV PGDATANEW /var/lib/postgresql/13/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/12-to-14/Dockerfile b/12-to-14/Dockerfile index bfd2042..1413d64 100644 --- a/12-to-14/Dockerfile +++ b/12-to-14/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:14-bookworm RUN sed -i 's/$/ 12/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-12=12.16-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-12='12.16-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/12/bin ENV PGBINNEW /usr/lib/postgresql/14/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/14/bin ENV PGDATAOLD /var/lib/postgresql/12/data ENV PGDATANEW /var/lib/postgresql/14/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/12-to-15/Dockerfile b/12-to-15/Dockerfile index 01f2062..604ab22 100644 --- a/12-to-15/Dockerfile +++ b/12-to-15/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:15-bookworm RUN sed -i 's/$/ 12/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-12=12.16-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-12='12.16-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/12/bin ENV PGBINNEW /usr/lib/postgresql/15/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/15/bin ENV PGDATAOLD /var/lib/postgresql/12/data ENV PGDATANEW /var/lib/postgresql/15/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/12-to-16/Dockerfile b/12-to-16/Dockerfile index b9bf396..d3ee9c5 100644 --- a/12-to-16/Dockerfile +++ b/12-to-16/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:16-bookworm RUN sed -i 's/$/ 12/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-12=12.16-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-12='12.16-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/12/bin ENV PGBINNEW /usr/lib/postgresql/16/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/16/bin ENV PGDATAOLD /var/lib/postgresql/12/data ENV PGDATANEW /var/lib/postgresql/16/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/13-to-14/Dockerfile b/13-to-14/Dockerfile index d9cafe0..e5f0605 100644 --- a/13-to-14/Dockerfile +++ b/13-to-14/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:14-bookworm RUN sed -i 's/$/ 13/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-13=13.12-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-13='13.12-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/13/bin ENV PGBINNEW /usr/lib/postgresql/14/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/14/bin ENV PGDATAOLD /var/lib/postgresql/13/data ENV PGDATANEW /var/lib/postgresql/14/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/13-to-15/Dockerfile b/13-to-15/Dockerfile index 5e12216..b2e6105 100644 --- a/13-to-15/Dockerfile +++ b/13-to-15/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:15-bookworm RUN sed -i 's/$/ 13/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-13=13.12-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-13='13.12-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/13/bin ENV PGBINNEW /usr/lib/postgresql/15/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/15/bin ENV PGDATAOLD /var/lib/postgresql/13/data ENV PGDATANEW /var/lib/postgresql/15/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/13-to-16/Dockerfile b/13-to-16/Dockerfile index f4a227a..032f6f8 100644 --- a/13-to-16/Dockerfile +++ b/13-to-16/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:16-bookworm RUN sed -i 's/$/ 13/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-13=13.12-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-13='13.12-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/13/bin ENV PGBINNEW /usr/lib/postgresql/16/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/16/bin ENV PGDATAOLD /var/lib/postgresql/13/data ENV PGDATANEW /var/lib/postgresql/16/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/14-to-15/Dockerfile b/14-to-15/Dockerfile index f17f8ee..0d32d45 100644 --- a/14-to-15/Dockerfile +++ b/14-to-15/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:15-bookworm RUN sed -i 's/$/ 14/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-14=14.9-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-14='14.9-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/14/bin ENV PGBINNEW /usr/lib/postgresql/15/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/15/bin ENV PGDATAOLD /var/lib/postgresql/14/data ENV PGDATANEW /var/lib/postgresql/15/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/14-to-16/Dockerfile b/14-to-16/Dockerfile index 2e6a00a..c757302 100644 --- a/14-to-16/Dockerfile +++ b/14-to-16/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:16-bookworm RUN sed -i 's/$/ 14/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-14=14.9-1.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-14='14.9-1.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/14/bin ENV PGBINNEW /usr/lib/postgresql/16/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/16/bin ENV PGDATAOLD /var/lib/postgresql/14/data ENV PGDATANEW /var/lib/postgresql/16/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/15-to-16/Dockerfile b/15-to-16/Dockerfile index a701a16..a1739b5 100644 --- a/15-to-16/Dockerfile +++ b/15-to-16/Dockerfile @@ -1,10 +1,19 @@ +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + FROM postgres:16-bookworm RUN sed -i 's/$/ 15/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-15=15.4-2.pgdg120+1 \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-15='15.4-2.pgdg120+1' \ + ; \ + rm -rf /var/lib/apt/lists/* ENV PGBINOLD /usr/lib/postgresql/15/bin ENV PGBINNEW /usr/lib/postgresql/16/bin @@ -12,8 +21,9 @@ ENV PGBINNEW /usr/lib/postgresql/16/bin ENV PGDATAOLD /var/lib/postgresql/15/data ENV PGDATANEW /var/lib/postgresql/16/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/Dockerfile.template b/Dockerfile.template index a96ac67..287e789 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,20 +1,23 @@ -FROM postgres:%%POSTGRES_NEW%%-%%SUITE%% +FROM {{ .from }} -RUN sed -i 's/$/ %%POSTGRES_OLD%%/' /etc/apt/sources.list.d/pgdg.list +RUN sed -i 's/$/ {{ .old }}/' /etc/apt/sources.list.d/pgdg.list -RUN apt-get update && apt-get install -y --no-install-recommends \ - postgresql-%%POSTGRES_OLD%%=%%POSTGRES_OLD_VERSION%% \ - postgresql-contrib-%%POSTGRES_OLD%%=%%POSTGRES_OLD_VERSION%% \ - && rm -rf /var/lib/apt/lists/* +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-{{ .old }}={{ .version | @sh }} \ + ; \ + rm -rf /var/lib/apt/lists/* -ENV PGBINOLD /usr/lib/postgresql/%%POSTGRES_OLD%%/bin -ENV PGBINNEW /usr/lib/postgresql/%%POSTGRES_NEW%%/bin +ENV PGBINOLD /usr/lib/postgresql/{{ .old }}/bin +ENV PGBINNEW /usr/lib/postgresql/{{ .new }}/bin -ENV PGDATAOLD /var/lib/postgresql/%%POSTGRES_OLD%%/data -ENV PGDATANEW /var/lib/postgresql/%%POSTGRES_NEW%%/data +ENV PGDATAOLD /var/lib/postgresql/{{ .old }}/data +ENV PGDATANEW /var/lib/postgresql/{{ .new }}/data -RUN mkdir -p "$PGDATAOLD" "$PGDATANEW" \ - && chown -R postgres:postgres /var/lib/postgresql +RUN set -eux; \ + mkdir -p "$PGDATAOLD" "$PGDATANEW"; \ + chown -R postgres:postgres /var/lib/postgresql WORKDIR /var/lib/postgresql diff --git a/apply-templates.sh b/apply-templates.sh new file mode 100755 index 0000000..650e8b7 --- /dev/null +++ b/apply-templates.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +[ -f versions.json ] # run "versions.sh" first + +jqt='.jq-template.awk' +if [ -n "${BASHBREW_SCRIPTS:-}" ]; then + jqt="$BASHBREW_SCRIPTS/jq-template.awk" +elif [ "$BASH_SOURCE" -nt "$jqt" ]; then + # https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk + wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk' +fi + +if [ "$#" -eq 0 ]; then + versions="$(jq -r 'keys_unsorted | map(@sh) | join(" ")' versions.json)" + eval "set -- $versions" +fi + +generated_warning() { + cat <<-EOH + # + # NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" + # + # PLEASE DO NOT EDIT IT DIRECTLY. + # + + EOH +} + +for version; do + export version + + echo "processing $version ..." + + mkdir -p "$version" + + { + generated_warning + gawk -f "$jqt" Dockerfile.template + } > "$version/Dockerfile" + + cp -a docker-upgrade "$version/" +done diff --git a/update.sh b/update.sh index c32caf5..bac2d75 100755 --- a/update.sh +++ b/update.sh @@ -1,54 +1,7 @@ #!/usr/bin/env bash set -Eeuo pipefail -# TODO scrape this somehow? -supportedVersions=( - 16 - 15 - 14 - 13 - 12 - 11 - #10 - #9.6 - #9.5 - #9.4 - #9.3 - #9.2 -) -suite='bookworm' +cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" -for i in "${!supportedVersions[@]}"; do - new="${supportedVersions[$i]}" - echo "# $new" - docker pull "postgres:$new-$suite" > /dev/null - (( j = i + 1 )) - for old in "${supportedVersions[@]:$j}"; do - dir="$old-to-$new" - echo "- $old -> $new ($dir)" - oldVersion="$( - docker run --rm -e OLD="$old" "postgres:$new-$suite" bash -Eeuo pipefail -c ' - sed -i "s/\$/ $OLD/" /etc/apt/sources.list.d/pgdg.list - apt-get update -qq 2>/dev/null - apt-cache policy "postgresql-$OLD" \ - | awk "\$1 == \"Candidate:\" { print \$2; exit }" - ' - )" - echo " - $oldVersion" - if [ "$oldVersion" = '(none)' ]; then - continue - fi - mkdir -p "$dir" - sed \ - -e "s!%%POSTGRES_OLD%%!$old!g" \ - -e "s!%%POSTGRES_OLD_VERSION%%!$oldVersion!g" \ - -e "s!%%POSTGRES_NEW%%!$new!g" \ - -e "s!%%SUITE%%!$suite!g" \ - Dockerfile.template \ - > "$dir/Dockerfile" - cp docker-upgrade "$dir/" - if [[ "$old" != 9.* ]]; then - sed -i -e '/postgresql-contrib-/d' "$dir/Dockerfile" - fi - done -done +./versions.sh "$@" +./apply-templates.sh "$@" diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..b71cf69 --- /dev/null +++ b/versions.json @@ -0,0 +1,92 @@ +{ + "15-to-16": { + "from": "postgres:16-bookworm", + "new": "16", + "old": "15", + "version": "15.4-2.pgdg120+1" + }, + "14-to-16": { + "from": "postgres:16-bookworm", + "new": "16", + "old": "14", + "version": "14.9-1.pgdg120+1" + }, + "13-to-16": { + "from": "postgres:16-bookworm", + "new": "16", + "old": "13", + "version": "13.12-1.pgdg120+1" + }, + "12-to-16": { + "from": "postgres:16-bookworm", + "new": "16", + "old": "12", + "version": "12.16-1.pgdg120+1" + }, + "11-to-16": { + "from": "postgres:16-bookworm", + "new": "16", + "old": "11", + "version": "11.21-1.pgdg120+1" + }, + "14-to-15": { + "from": "postgres:15-bookworm", + "new": "15", + "old": "14", + "version": "14.9-1.pgdg120+1" + }, + "13-to-15": { + "from": "postgres:15-bookworm", + "new": "15", + "old": "13", + "version": "13.12-1.pgdg120+1" + }, + "12-to-15": { + "from": "postgres:15-bookworm", + "new": "15", + "old": "12", + "version": "12.16-1.pgdg120+1" + }, + "11-to-15": { + "from": "postgres:15-bookworm", + "new": "15", + "old": "11", + "version": "11.21-1.pgdg120+1" + }, + "13-to-14": { + "from": "postgres:14-bookworm", + "new": "14", + "old": "13", + "version": "13.12-1.pgdg120+1" + }, + "12-to-14": { + "from": "postgres:14-bookworm", + "new": "14", + "old": "12", + "version": "12.16-1.pgdg120+1" + }, + "11-to-14": { + "from": "postgres:14-bookworm", + "new": "14", + "old": "11", + "version": "11.21-1.pgdg120+1" + }, + "12-to-13": { + "from": "postgres:13-bookworm", + "new": "13", + "old": "12", + "version": "12.16-1.pgdg120+1" + }, + "11-to-13": { + "from": "postgres:13-bookworm", + "new": "13", + "old": "11", + "version": "11.21-1.pgdg120+1" + }, + "11-to-12": { + "from": "postgres:12-bookworm", + "new": "12", + "old": "11", + "version": "11.21-1.pgdg120+1" + } +} diff --git a/versions.sh b/versions.sh new file mode 100755 index 0000000..25664e7 --- /dev/null +++ b/versions.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# TODO scrape this somehow? +supportedVersions=( + 16 + 15 + 14 + 13 + 12 + 11 + #10 + #9.6 + #9.5 + #9.4 + #9.3 + #9.2 +) +suite='bookworm' + +json='{}' + +for i in "${!supportedVersions[@]}"; do + new="${supportedVersions[$i]}" + echo "# $new" + docker pull "postgres:$new-$suite" > /dev/null + (( j = i + 1 )) + for old in "${supportedVersions[@]:$j}"; do + dir="$old-to-$new" + echo "- $old -> $new ($dir)" + from="postgres:$new-$suite" + oldVersion="$( + docker run --rm -e OLD="$old" "$from" bash -Eeuo pipefail -c ' + sed -i "s/\$/ $OLD/" /etc/apt/sources.list.d/pgdg.list + apt-get update -qq 2>/dev/null + apt-cache policy "postgresql-$OLD" \ + | awk "\$1 == \"Candidate:\" { print \$2; exit }" + ' + )" + echo " - $oldVersion" + if [ "$oldVersion" = '(none)' ]; then + continue + fi + json="$(jq <<<"$json" -c --arg dir "$dir" --arg version "$oldVersion" --arg from "$from" --arg old "$old" --arg new "$new" ' + .[$dir] = { + from: $from, + new: $new, + old: $old, + version: $version, + } + ')" + done +done + +jq <<<"$json" '.' > versions.json