Skip to content

Commit d071944

Browse files
litaocdlsxd
authored andcommitted
Initial Commit
Signed-off-by: Gabriele Bartolini <[email protected]>
0 parents  commit d071944

28 files changed

+3397
-0
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/generate-strategy.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Given a list of PostgreSQL versions (defined as directories in the root
4+
# folder of the project), this script generates a JSON object that will be used
5+
# inside the Github workflows as a strategy to create a matrix of jobs to run.
6+
# The JSON object contains, for each PostgreSQL version, the tags of the
7+
# container image to be built.
8+
#
9+
set -eu
10+
11+
# Define an optional aliases for some major versions
12+
declare -A aliases=(
13+
[14]='latest'
14+
)
15+
16+
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}/..")")"
17+
BASE_DIRECTORY="$(pwd)"
18+
19+
20+
# Retrieve the PostgreSQL versions for Debian
21+
cd ${BASE_DIRECTORY}/Debian
22+
for version in */; do
23+
[[ $version == src/ ]] && continue
24+
debian_versions+=("$version")
25+
done
26+
debian_versions=("${debian_versions[@]%/}")
27+
28+
# Sort the version numbers with highest first
29+
mapfile -t debian_versions < <(IFS=$'\n'; sort -rV <<< "${debian_versions[*]}")
30+
31+
# prints "$2$1$3$1...$N"
32+
join() {
33+
local sep="$1"
34+
shift
35+
local out
36+
printf -v out "${sep//%/%%}%s" "$@"
37+
echo "${out#$sep}"
38+
}
39+
40+
entries=()
41+
for version in "${debian_versions[@]}"; do
42+
43+
# Read versions from the definition file
44+
versionFile="${version}/.versions.json"
45+
postgresImageVersion=$(jq -r '.POSTGRES_IMAGE_VERSION | split("-") | .[0]' "${versionFile}")
46+
releaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")
47+
48+
# Initial aliases are "major version", "optional alias", "full version with release"
49+
# i.e. "14", "latest", "14.2-1", "14.2-debian","14.2"
50+
versionAliases=(
51+
"${version}"
52+
${aliases[$version]:+"${aliases[$version]}"}
53+
"${postgresImageVersion}-${releaseVersion}"
54+
"${postgresImageVersion}"
55+
)
56+
# Add all the version prefixes between full version and major version
57+
# i.e "13.2"
58+
while [ "$postgresImageVersion" != "$version" ] && [ "${postgresImageVersion%[.-]*}" != "$postgresImageVersion" ]; do
59+
versionAliases+=("$postgresImageVersion-debian")
60+
postgresImageVersion="${postgresImageVersion%[.-]*}"
61+
done
62+
# Support platform for container images
63+
platforms="linux/amd64"
64+
65+
# Build the json entry
66+
entries+=(
67+
"{\"name\": \"Debian ${postgresImageVersion}\", \"platforms\": \"$platforms\", \"dir\": \"Debian/$version\", \"file\": \"Debian/$version/Dockerfile\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliases[@]}")\"]}"
68+
)
69+
done
70+
71+
# Build the strategy as a JSON object
72+
strategy="{\"fail-fast\": false, \"matrix\": {\"include\": [$(join ', ' "${entries[@]}")]}}"
73+
jq -C . <<<"$strategy" # sanity check / debugging aid
74+
echo "::set-output name=strategy::$(jq -c . <<<"$strategy")"

.github/workflows/build.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Continuous Delivery
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
env:
10+
IMAGE_STAGING: cloudnative-pg/postgresql-testing
11+
IMAGE_RELEASE: cloudnative-pg/postgresql
12+
13+
jobs:
14+
generate-jobs:
15+
name: Generate Jobs
16+
runs-on: ubuntu-20.04
17+
outputs:
18+
strategy: ${{ steps.generate-jobs.outputs.strategy }}
19+
steps:
20+
- name: Checkout Code
21+
uses: actions/checkout@v3
22+
- name: Generate Jobs
23+
id: generate-jobs
24+
shell: bash
25+
run: |
26+
bash .github/generate-strategy.sh
27+
28+
build:
29+
needs: generate-jobs
30+
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
31+
name: ${{ matrix.name }}
32+
runs-on: ubuntu-20.04
33+
permissions:
34+
contents: read
35+
packages: write
36+
steps:
37+
- name: Checkout Code
38+
uses: actions/checkout@v3
39+
40+
- name: Set up QEMU
41+
uses: docker/[email protected]
42+
43+
- name: Docker meta
44+
id: docker-meta
45+
env:
46+
TAGS: ${{ toJson(matrix.tags) }}
47+
run: |
48+
RESULT=""
49+
for tag in $(jq -r '.[]' <<< "${TAGS}")
50+
do
51+
RESULT="${RESULT},ghcr.io/${IMAGE_STAGING}:${tag}"
52+
# If we are running the pipeline in the main branch images are pushed in both -testing and PROD repo
53+
if [ "${GITHUB_REF#refs/heads/}" == main ]
54+
then
55+
RESULT="${RESULT},ghcr.io/${IMAGE_RELEASE}:${tag}"
56+
fi
57+
done
58+
echo "::set-output name=tags::${RESULT%,}"
59+
60+
- name: Set up Docker Buildx
61+
id: buildx
62+
uses: docker/[email protected]
63+
64+
- name: Log in to the GitHub Container registry
65+
uses: docker/[email protected]
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Build and load
72+
uses: docker/[email protected]
73+
with:
74+
context: ${{ matrix.dir }}
75+
file: ${{ matrix.file }}
76+
push: false
77+
load: true
78+
tags: ${{ steps.docker-meta.outputs.tags }}
79+
80+
- name: Dockle scan
81+
uses: erzz/[email protected]
82+
with:
83+
image: "ghcr.io/${{ env.IMAGE_STAGING }}:${{ matrix.tags[0] }}"
84+
exit-code: '1'
85+
failure-threshold: WARN
86+
accept-filenames: usr/share/cmake/Templates/Windows/Windows_TemporaryKey.pfx,etc/trusted-key.key,usr/share/doc/perl-IO-Socket-SSL/certs/server_enc.p12,usr/share/doc/perl-IO-Socket-SSL/certs/server.p12,usr/local/lib/python3.9/dist-packages/azure/core/settings.py,usr/local/lib/python3.8/site-packages/azure/core/settings.py,usr/share/postgresql-common/pgdg/apt.postgresql.org.asc,usr/local/lib/python3.7/dist-packages/azure/core/settings.py,etc/ssl/private/ssl-cert-snakeoil.key
87+
88+
- name: Build and push
89+
uses: docker/[email protected]
90+
with:
91+
context: ${{ matrix.dir }}
92+
file: ${{ matrix.file }}
93+
platforms: ${{ matrix.platforms }}
94+
push: true
95+
tags: ${{ steps.docker-meta.outputs.tags }}

.github/workflows/update.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Automatic Updates
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * *
6+
workflow_dispatch:
7+
8+
defaults:
9+
run:
10+
shell: 'bash -Eeuo pipefail -x {0}'
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
token: ${{ secrets.REPO_GHA_PAT }}
19+
- name: Run update script
20+
uses: nick-fields/[email protected]
21+
with:
22+
timeout_minutes: 15
23+
max_attempts: 3
24+
command: |
25+
# pip-tools provides pip-compile used by update.sh
26+
pip3 install --upgrade pip-tools
27+
export PATH=$HOME/.local/bin:$PATH
28+
echo "Updating Debian images"
29+
./Debian/update.sh
30+
- name: Diff
31+
run: |
32+
git status
33+
git diff
34+
- name: Temporarily disable "include administrators" branch protection
35+
if: ${{ always() && github.ref == 'refs/heads/main' }}
36+
id: disable_include_admins
37+
uses: benjefferies/[email protected]
38+
with:
39+
access_token: ${{ secrets.REPO_GHA_PAT }}
40+
branch: main
41+
enforce_admins: false
42+
- uses: EndBug/add-and-commit@v9
43+
id: commit
44+
with:
45+
author_name: EnterpriseDB Automated Updates
46+
author_email: [email protected]
47+
message: 'Daily automatic update'
48+
- name: Enable "include administrators" branch protection
49+
uses: benjefferies/[email protected]
50+
if: ${{ always() && github.ref == 'refs/heads/main' }}
51+
with:
52+
access_token: ${{ secrets.REPO_GHA_PAT }}
53+
branch: main
54+
enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @NiccoloFei @fcanovai @gbartolini @jbattiato @litaocdl @mnencia @sxd

CODE_OF_CONDUCT.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Code of Conduct
2+
3+
Cloud Native Postgres follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). <!-- wokeignore:rule=master -->

Debian/10/.versions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"BARMAN_VERSION": "2.19",
3+
"IMAGE_RELEASE_VERSION": "1",
4+
"POSTGRES_IMAGE_LAST_UPDATED": "2022-03-30T05:30:55.690966Z",
5+
"POSTGRES_IMAGE_VERSION": "10.20-bullseye"
6+
}

Debian/10/Dockerfile

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# vim:set ft=dockerfile:
2+
#
3+
# Copyright The CloudNativePG Contributors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
# 
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
FROM postgres:10.20-bullseye
18+
19+
# Do not split the description, otherwise we will see a blank space in the labels
20+
LABEL name="PostgreSQL Container Images" \
21+
vendor="The CloudNativePG Contributors" \
22+
version="${PG_VERSION}" \
23+
release="1" \
24+
summary="PostgreSQL Container images." \
25+
description="This Docker image contains PostgreSQL and Barman Cloud based on Postgres 10.20-bullseye."
26+
27+
COPY requirements.txt /
28+
29+
# Install pgaudit
30+
RUN set -xe; \
31+
apt-get update; \
32+
apt-get install -y --no-install-recommends \
33+
"postgresql-${PG_MAJOR}-pgaudit" ;\
34+
rm -fr /tmp/* ; \
35+
rm -rf /var/lib/apt/lists/*;
36+
37+
# Install barman-cloud
38+
RUN set -xe; \
39+
apt-get update; \
40+
apt-get install -y --no-install-recommends \
41+
python3-pip \
42+
python3-psycopg2 \
43+
python3-setuptools \
44+
; \
45+
pip3 install --upgrade pip; \
46+
# TODO: Remove --no-deps once https://github.com/pypa/pip/issues/9644 is solved
47+
pip3 install --no-deps -r requirements.txt; \
48+
rm -rf /var/lib/apt/lists/*;
49+
50+
# Change the uid of postgres to 26
51+
RUN usermod -u 26 postgres
52+
USER 26

0 commit comments

Comments
 (0)