Skip to content

Commit 117f913

Browse files
committed
Distgen - add ability to generate files
1 parent 7167da8 commit 117f913

File tree

9 files changed

+127
-113
lines changed

9 files changed

+127
-113
lines changed

Dockerfile.template

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM centos:centos7
1+
FROM {{ config.docker.from }}
22

33
# PostgreSQL image for OpenShift.
44
# Volumes:
@@ -10,8 +10,8 @@ FROM centos:centos7
1010
# * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres'
1111
# PostgreSQL administrative account
1212

13-
ENV POSTGRESQL_VERSION=9.6 \
14-
POSTGRESQL_PREV_VERSION=9.5 \
13+
ENV POSTGRESQL_VERSION={{ spec.version }} \
14+
POSTGRESQL_PREV_VERSION={{ spec.prev_version }} \
1515
HOME=/var/lib/pgsql \
1616
PGUSER=postgres
1717

@@ -23,14 +23,20 @@ create, run, maintain and access a PostgreSQL DBMS server."
2323
LABEL summary=$SUMMARY \
2424
description="$DESCRIPTION" \
2525
io.k8s.description="$DESCRIPTION" \
26-
io.k8s.display-name="PostgreSQL 9.6" \
26+
io.k8s.display-name="PostgreSQL {{ spec.version }}" \
2727
io.openshift.expose-services="5432:postgresql" \
28-
io.openshift.tags="database,postgresql,postgresql96,rh-postgresql96" \
29-
name="centos/postgresql-96-centos7" \
30-
com.redhat.component="rh-postgresql96-docker" \
31-
version="9.6" \
32-
release="1" \
33-
maintainer="SoftwareCollections.org <[email protected]>"
28+
io.openshift.tags="{{ spec.openshift_tags }}" \
29+
name="{{ spec.common_image_name }}" \
30+
com.redhat.component="{{ spec.redhat_component }}" \
31+
{%- if spec.version in spec.rhscl3_introduced %}
32+
version="1"
33+
{%- else %}
34+
version="{{ spec.version }}" \
35+
release="1"
36+
{%- endif %}
37+
{%- if spec.maintainer %} \
38+
maintainer="{{ spec.maintainer }}"
39+
{%- endif %}
3440

3541
EXPOSE 5432
3642

@@ -39,10 +45,14 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
3945
# This image must forever use UID 26 for postgres user so our volumes are
4046
# safe in the future. This should *never* change, the last test is there
4147
# to make sure of that.
42-
RUN yum install -y centos-release-scl-rh && \
43-
yum-config-manager --add-repo https://cbs.centos.org/repos/sclo7-rh-postgresql96-rh-candidate/x86_64/os/ && \
44-
echo gpgcheck=0 >> /etc/yum.repos.d/cbs.centos.org_repos_sclo7-rh-postgresql96-rh-candidate_x86_64_os_.repo && \
45-
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper rh-postgresql96 rh-postgresql96-postgresql-contrib rh-postgresql95-postgresql-server" && \
48+
{%- if spec.repo_enable_reason %}
49+
{{ spec.repo_enable_reason }}
50+
{%- endif %}
51+
RUN {{ spec.environment_setup }}
52+
{%- if not spec.stable %}
53+
{{ spec.staging_repo_setup }}
54+
{%- endif %}
55+
INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper {{ spec.pkgs }}" && \
4656
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
4757
rpm -V $INSTALL_PKGS && \
4858
yum clean all && \
@@ -54,7 +64,7 @@ RUN yum install -y centos-release-scl-rh && \
5464

5565
# Get prefix path and path to scripts rather than hard-code them in scripts
5666
ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql \
57-
ENABLED_COLLECTIONS=rh-postgresql96
67+
ENABLED_COLLECTIONS={{ spec.enabled_collection }}
5868

5969
COPY root /
6070

Makefile

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BASE_IMAGE_NAME = postgresql
33
VERSIONS = 9.4 9.5 9.6
44
OPENSHIFT_NAMESPACES = 9.2
5+
export VERSIONS
56

67
# HACK: Ensure that 'git pull' for old clones doesn't cause confusion.
78
# New clones should use '--recursive'.
@@ -13,11 +14,5 @@ include common/common.mk
1314
upgrade-tests: $(VERSIONS)
1415
test/run_upgrade_test 9.2:remote 9.4:local 9.5:local 9.6:local
1516

16-
DG = /usr/bin/dg
17-
DG_EXEC = ${DG} --max-passes 25 --template Dockerfile.template --multispec specs/multispec.yml
18-
19-
generate_dockerfiles:
20-
for version in ${VERSIONS}; do \
21-
${DG_EXEC} --distro centos-7-x86_64.yaml --multispec-selector version=$${version} --output $${version}/Dockerfile; \
22-
${DG_EXEC} --distro rhel-7-x86_64.yaml --multispec-selector version=$${version} --output $${version}/Dockerfile.rhel7; \
23-
done
17+
distgen:
18+
./gen-dirs.sh

gen-dirs.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
set -e
3+
cd templates
4+
FILES=$(find -follow)
5+
6+
pre_gen_cleanup() {
7+
rm -rf ../latest
8+
for version in ${VERSIONS}; do
9+
rm -rf ../${version}
10+
done
11+
}
12+
13+
# postgresql specific
14+
pg_generate_symlinks() {
15+
echo "Creating symlinks:"
16+
for version in ${VERSIONS}; do
17+
cd ../${version}
18+
echo " ${version}/README.md -> ${version}/root/usr/share/container-scripts/postgresql/README.md"
19+
ln -s root/usr/share/container-scripts/postgresql/README.md README.md
20+
echo " ${version}/test test"
21+
ln -s ../test test
22+
done
23+
cd ..
24+
echo "Moving 9.6 version to latest"
25+
if [ -d "./latest" ]; then
26+
echo "Failed to copy directory: ./latest already exists"
27+
exit 1
28+
fi
29+
mv 9.6 ./latest
30+
echo "Creating symlink 9.6->latest"
31+
ln -s latest 9.6
32+
}
33+
34+
generate_file() {
35+
if [ -L $1 ]; then
36+
echo "Skipping symbolic link: $1"
37+
return
38+
elif [[ -d $1 && ! -d ../${version}/$1 ]]; then
39+
mkdir ../${version}/$1
40+
else
41+
echo "Generating: ${version}/$1"
42+
/usr/bin/dg --max-passes 1 --multispec ../specs/multispec.yml \
43+
--template $1 --distro centos-7-x86_64.yaml \
44+
--multispec-selector version=${version} --output ../${version}/$1
45+
fi
46+
if [ -x $1 ]; then
47+
chmod +x ../${version}/$1
48+
fi
49+
}
50+
51+
generate_dockerfiles() {
52+
mkdir ../$1
53+
echo "Generating Dockerfile: $1/Dockerfile"
54+
/usr/bin/dg --max-passes 25 --template ${PWD}/../Dockerfile.template \
55+
--multispec ../specs/multispec.yml --distro centos-7-x86_64.yaml \
56+
--multispec-selector version=$1 --output ../$1/Dockerfile
57+
echo "Generating Dockerfile: $1/Dockerfile.rhel7"
58+
/usr/bin/dg --max-passes 25 --template ${PWD}/../Dockerfile.template \
59+
--multispec ../specs/multispec.yml --distro rhel-7-x86_64.yaml \
60+
--multispec-selector version=$1 --output ../$1/Dockerfile.rhel7
61+
62+
}
63+
64+
pre_gen_cleanup
65+
66+
for version in ${VERSIONS}; do
67+
generate_dockerfiles $version
68+
69+
# iterate all directories and files in templates except of "."
70+
for file in ${FILES[@]:1}; do
71+
generate_file $file
72+
done
73+
done
74+
75+
pg_generate_symlinks

specs/multispec.yml

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ specs:
4242
enabled_collection: "rh-postgresql94"
4343
openshift_tags: "database,postgresql,postgresql94,rh-postgresql94"
4444
redhat_component: "rh-postgresql94-docker"
45+
common_image_name: "{{ spec.org }}/postgresql-94-{{ spec.prod }}"
46+
rhel_image_name: "rhscl/postgresql-94-rhel7"
47+
centos_image_name: "centos/postgresql-94-centos7"
4548
stable: True
4649

4750
"9.5":
@@ -52,6 +55,9 @@ specs:
5255
enabled_collection: "rh-postgresql95"
5356
openshift_tags: "database,postgresql,postgresql95,rh-postgresql95"
5457
redhat_component: "rh-postgresql95-docker"
58+
common_image_name: "{{ spec.org }}/postgresql-95-{{ spec.prod }}"
59+
rhel_image_name: "rhscl/postgresql-95-rhel7"
60+
centos_image_name: "centos/postgresql-95-centos7"
5561
stable: True
5662

5763
"9.6":
@@ -62,4 +68,7 @@ specs:
6268
enabled_collection: "rh-postgresql96"
6369
openshift_tags: "database,postgresql,postgresql96,rh-postgresql96"
6470
redhat_component: "rh-postgresql96-docker"
71+
common_image_name: "{{ spec.org }}/postgresql-96-{{ spec.prod }}"
72+
rhel_image_name: "rhscl/postgresql-96-rhel7"
73+
centos_image_name: "centos/postgresql-96-centos7"
6574
stable: False

templates/Dockerfile.rhel7

-76
This file was deleted.

templates/cccp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
job-id: postgresql-96-centos7
1+
job-id: postgresql-{{ spec.short }}-{{ spec.prod }}

templates/root/usr/share/container-scripts/postgresql/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
PostgreSQL 9.6 SQL Database Server Docker image
1+
PostgreSQL {{ spec.version }} SQL Database Server Docker image
22
===============================================
33

4-
This container image includes PostgreSQL 9.6 SQL database server for OpenShift and general usage.
4+
This container image includes PostgreSQL {{ spec.version }} SQL database server for OpenShift and general usage.
55
Users can choose between RHEL and CentOS based images.
6-
The RHEL image is available in the [Red Hat Container Catalog](https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/postgresql-96-rhel7)
7-
as registry.access.redhat.com/rhscl/postgresql-96-rhel7.
8-
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/centos/postgresql-96-centos7/)
9-
as centos/postgresql-96-centos7.
6+
The RHEL image is available in the [Red Hat Container Catalog](https://access.redhat.com/containers/#/registry.access.redhat.com/{{ spec.rhel_image_name }})
7+
as registry.access.redhat.com/{{ spec.rhel_image_name }}.
8+
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/{{ spec.centos_image_name }}/)
9+
as {{ spec.centos_image_name }}.
1010

1111

1212
Description
@@ -22,12 +22,12 @@ You can find more information on the PostgreSQL project from the project Web sit
2222
Usage
2323
-----
2424

25-
For this, we will assume that you are using the `rhscl/postgresql-96-rhel7` image.
25+
For this, we will assume that you are using the `{{ spec.rhel_image_name }}` image.
2626
If you want to set only the mandatory environment variables and not store the database
2727
in a host directory, execute the following command:
2828

2929
```
30-
$ docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 rhscl/postgresql-96-rhel7
30+
$ docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 {{ spec.rhel_image_name }}
3131
```
3232

3333
This will create a container named `postgresql_database` running PostgreSQL with
@@ -37,9 +37,9 @@ executions, also add a `-v /host/db/path:/var/lib/pgsql/data` argument (see
3737
below). This will be the PostgreSQL database cluster directory.
3838

3939
If the database cluster directory is not initialized, the entrypoint script will
40-
first run [`initdb`](http://www.postgresql.org/docs/9.6/static/app-initdb.html)
40+
first run [`initdb`](http://www.postgresql.org/docs/{{ spec.version }}/static/app-initdb.html)
4141
and setup necessary database users and passwords. After the database is initialized,
42-
or if it was already present, [`postgres`](http://www.postgresql.org/docs/9.6/static/app-postgres.html)
42+
or if it was already present, [`postgres`](http://www.postgresql.org/docs/{{ spec.version }}/static/app-postgres.html)
4343
is executed and will run as PID 1. You can stop the detached container by running
4444
`docker stop postgresql_database`.
4545

@@ -205,7 +205,7 @@ ensure that you've carefully backed up all your data and that you are OK with
205205
potential manual rollback! **
206206

207207
This image supports automatic upgrade of data directory created by
208-
the PostgreSQL server version 9.5 (and _only_ this version) - provided by sclorg
208+
the PostgreSQL server version {{ spec.prev_version }} (and _only_ this version) - provided by sclorg
209209
image. The upgrade process is designed so that you should be able to just
210210
switch from *image A* to *image B*, and set the `$POSTGRESQL_UPGRADE` variable
211211
appropriately to explicitly request the database data transformation.

templates/root/usr/share/container-scripts/postgresql/common.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ function check_env_vars() {
7070
[[ "$POSTGRESQL_USER" =~ $psql_identifier_regex ]] || usage
7171
[[ "$POSTGRESQL_PASSWORD" =~ $psql_password_regex ]] || usage
7272
[[ "$POSTGRESQL_DATABASE" =~ $psql_identifier_regex ]] || usage
73+
{%- raw %}
7374
[ ${#POSTGRESQL_USER} -le 63 ] || usage "PostgreSQL username too long (maximum 63 characters)"
7475
[ ${#POSTGRESQL_DATABASE} -le 63 ] || usage "Database name too long (maximum 63 characters)"
76+
{%- endraw %}
7577
postinitdb_actions+=",simple_db"
7678
fi
7779

@@ -148,7 +150,7 @@ initdb_wrapper ()
148150
{
149151
# Initialize the database cluster with utf8 support enabled by default.
150152
# This might affect performance, see:
151-
# http://www.postgresql.org/docs/9.6/static/locale.html
153+
# http://www.postgresql.org/docs/{{ spec.version }}/static/locale.html
152154
LANG=${LANG:-en_US.utf8} "$@"
153155
}
154156

templates/test

-1
This file was deleted.

0 commit comments

Comments
 (0)