Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source to image #208

Merged
merged 1 commit into from
Jan 10, 2018
Merged

Source to image #208

merged 1 commit into from
Jan 10, 2018

Conversation

dhodovsk
Copy link
Contributor

No description provided.

@@ -22,12 +22,17 @@ else
try_pgupgrade
fi

process_extending_files ${APP_DATA}/src/pre-init ${CONTAINER_SCRIPTS_PATH}/pre-init
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call should also be added to run-postgresql-slave


##### `postgresql-config/`

when running `run-service` command contained
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would restate a bit differently since right now it seems a bit confusing. Something along the lines of:

The postgresql.conf configuration file contained in this folder is used instead of the default configuration when postgresql is started

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds bad to me. Shouldn't we again rather only "include" (additional?) configuration file into the default postgresql.conf?

@pkubatrh
Copy link
Member

@praiskup Please take a look as well

@pkubatrh
Copy link
Member

I wonder... Would this work for the Fedora version out of the box as well?



```
$ s2i build --assemble-user root ~/image-configuration/ postgresql new-postgresql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is --asemble-user root realistically useable in openshift? Shouldn't we rather avoid root user at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User root is in this solution is used only for building the image using s2i. When the built container is run, it is under postgre user who is only in group postgre.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this really commonly enabled feature in OpenShift, so we can make it a "general" requirement? It seems to be pretty dangerous to get root access, even during the build..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other possibility is to add postgres user to root group (as is done e.g in mysql https://github.com/sclorg/mysql-container/blob/master/root-common/usr/libexec/container-setup#L58) but I can't help, it doesn't feel right. I think this issue deserves more discussion. @praiskup @hhorak what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better understand, what exactly is the 'root' needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that is really good question! The problem with missing write permission (that caused failed s2i builds) on /opt/app-root/src is now managed in Dockerfiles with https://github.com/sclorg/postgresql-container/pull/208/files#diff-4040b6e79b7069db62e62fee9e5c3532R72. fix-permissions might fail, but the build finishes successfully. Thank you for making this comment and standing your ground! :)

# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
Copy link
Contributor

@praiskup praiskup Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example configuration file should be few-lines long only (this file is actually generated at postgresql build-time, and as such it would get staled very soon) and do something real.. and be included into the maint postgresql.conf file, or possibly transitively included through the configuration generated by our scripts...

@dhodovsk
Copy link
Contributor Author

@pkubatrh yes, it should also work with fedora, but I ran into a problem with python2 package:

Steps to reproduce:

$ docker run -it registry.fedoraproject.org/f25/s2i-base:latest bash
bash-4.3# dnf install -y python2
Fedora 25 - x86_64                                                        80 MB/s |  50 MB     00:00    
Fedora 25 - x86_64 - Updates                                              73 MB/s |  24 MB     00:00    
Last metadata expiration check: 0:00:06 ago on Fri Nov 24 08:51:08 2017.
Package python-2.7.13-2.fc25.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
bash-4.3# rpm -V python2
package python2 is not installed

Do you know something about this? Could you, please, help me resolve this so I can rebase and apply s2i also to fedora image?

@pkubatrh
Copy link
Member

@dhodovsk What exactly is the issue? Python 2.7 is installed, only the package is not named python2, just python (old style naming).

In any case the postgresql image should not be based on s2i-base at all. It is an oversight that is already fixed in master. It should be based on s2i-core, which is unfortunately not yet built. (sclorg/s2i-base-container#144)

@dhodovsk
Copy link
Contributor Author

@pkubatrh the issue occurred while verifying INSTALED_PKGS - https://github.com/sclorg/postgresql-container/blob/master/latest/Dockerfile.fedora#L51. It works with registry.fedoraproject.org/fedora:26 but not with registry.fedoraproject.org/f25/s2i-base:latest bash. I don't know the python background in fedora but it seemed interesting. Anyway I built fedora s2i-core locally and used it in fedora image with s2i here and it went ok.

@dhodovsk dhodovsk force-pushed the source-to-image branch 4 times, most recently from bd05c52 to f58b86e Compare November 24, 2017 15:15
@@ -0,0 +1,3 @@
#!/bin/bash

/usr/bin/run-postgresql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be symlink to /usr/bin/run-postgresql?

@dhodovsk
Copy link
Contributor Author

@praiskup please review discussed changes, there is another example of handling permissions for ${APP_DATA} here: https://github.com/sclorg/varnish-container/blob/master/4/Dockerfile#L46

#!/bin/bash

# postgresql image encrypts user passwords at service start
# the functionality can be disabled by providing this file (start-hook/set_passwords.sh) in s2i build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

pg_ctl -w start -o "-h ''"
if $PG_INITIALIZED ; then
process_extending_files ${APP_DATA}/src/init-hook ${CONTAINER_SCRIPTS_PATH}/init-hook
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name it init only, or init-hooks?

@@ -67,6 +69,8 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \

VOLUME ["/var/lib/pgsql/data"]

# {APP_DATA} needs to be accessed by postgres user while s2i assembling
RUN chown -R 26:0 ${APP_DATA}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chmod -R og+rwx should be probably used too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant chmod -R ug+rwx.

@@ -1,4 +1,4 @@
FROM rhel7
FROM rhscl/s2i-core-rhel7:1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo :1 suffix

wait_for_postgresql_master
export MASTER_FQDN=$(postgresql_master_addr)
initialize_replica

process_extending_files ${APP_DATA}/src/init ${CONTAINER_SCRIPTS_PATH}/init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should slave call these hooks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked for it to be added because I thought even slaves want to have their configuration files extendible. But looking at pg_basebackup documentation it seems that the slaves will get the master's configurations files along with everything else, so it might not be needed after all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More it seems to me that the password change method is newly called for slave, too.


if [ -v POSTGRESQL_ADMIN_PASSWORD ]; then
psql --command "ALTER USER \"postgres\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_ADMIN_PASSWORD}';"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably editor mis-config (missing newline).


extending_cfg_dir="${APP_DATA}/src/postgresql-config"

for conf in $(ls ${extending_cfg_dir}); do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for conf in "$extending_cfg_dir"/*.conf; do

for conf in $(ls ${extending_cfg_dir}); do
cat >> "$PGDATA/postgresql.conf" <<EOF
include '$extending_cfg_dir/${conf}'
EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but echo would be also OK and a bit more readable.

@praiskup
Copy link
Contributor

Thanks, it is close now :-) could we please add s2i test-cases? Mariadb can be used for inspiration.

@@ -28,9 +28,13 @@ check_env_vars
generate_passwd_file
generate_postgresql_config

process_extending_files ${APP_DATA}/src/pre-init ${CONTAINER_SCRIPTS_PATH}/pre-init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be updated to use init-hook and start-hook directories.

@dhodovsk
Copy link
Contributor Author

dhodovsk commented Dec 6, 2017

The requested changes has been applied; now also to Dockerfile.template and versions 9.5 and 9.4.

@pkubatrh
Copy link
Member

do we need write permissions actually?

For the source files under /opt/app-root/src? One use case that comes to mind is easier debugging of the built image without the need to have it rebuilt with new sources

@omron93
Copy link
Contributor

omron93 commented Dec 12, 2017

do we really need to run fix-permission during assemble run?

We need to add/ensure g+r for root group. To be able to run this image under random UID (~group is 0)... So I think yes.

@dhodovsk
Copy link
Contributor Author

So based on comments above, fix-permission wasn't changed in latest rebase and is called during assemble. Postgres user is added to root group in Dockerfile to be able to perform the operations.

# {APP_DATA} needs to be accessed by postgres user while s2i assembling
# postgres user changes permissiond of files in APP_DATA during assemblng
RUN chown -R 26:0 ${APP_DATA} && \
useradd -G root 26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work on my system. You probably want usermod -a -G root postgres.
I don't think removal of chmod was correct, because default umask should be 0022 -> which means that group get's only r-x permissions.

@pkubatrh
Copy link
Member

[test-openshift]


contained shell scripts (`*.sh`) are sourced once, when database is initialized

##### `start-hook/`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no comment about s/start-hook/postgresql-start-hook/. Mariadb has mysql-cfg, mysql-init and mysql-pre-init. Shouldn't we have the namespaced hook directory, too?

@@ -70,6 +72,12 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \

VOLUME ["/var/lib/pgsql/data"]

# {APP_DATA} needs to be accessed by postgres user while s2i assembling
# postgres user changes permissiond of files in APP_DATA during assemblng
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:
Being also in supplemental group 0, postgres user can by default change the group
ownership of files in $APP_DATA to postgres:root (by fix-permissions script in assemble
script). This group ownership change is needed because the s2i-built image is run under
arbitrary user uid (but gid=0).

# postgres user changes permissiond of files in APP_DATA during assemblng
RUN chown -R postgres:0 ${APP_DATA} && \
chmod -R ug+rwx ${APP_DATA} && \
usermod -a -G root postgres
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have the two questions:

  • is the write permissions needed in case of postgresql?
  • could we just drop chown/chmod and use fix-permissions above (where the data ownership is changed)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fix-permissions should be enough, at least it looks like it's enough for mysql: https://github.com/sclorg/mysql-container/blob/master/root-common/usr/libexec/container-setup#L57

@@ -70,6 +72,12 @@ ENV BASH_ENV=${CONTAINER_SCRIPTS_PATH}/scl_enable \

VOLUME ["/var/lib/pgsql/data"]

# {APP_DATA} needs to be accessed by postgres user while s2i assembling
# postgres user changes permissiond of files in APP_DATA during assemblng
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two typos: "permissiond" and "assemblng"

@hhorak
Copy link
Member

hhorak commented Jan 4, 2018

@dhodovsk @praiskup It's hard to see whether there is still anything to be fixed. From a quick look, it seems things like 's/init/postgresql-init/ands/start-hook/postgresql-start-hook/` are still to be addressed...

@praiskup
Copy link
Contributor

praiskup commented Jan 4, 2018

I would prefer to have that hooks namespaced, yes.

@dhodovsk
Copy link
Contributor Author

dhodovsk commented Jan 9, 2018

@praiskup Is it now ok?

@praiskup
Copy link
Contributor

praiskup commented Jan 9, 2018

Seems to be, small nit with the docs.


##### `postgresql-config/`

contained files will be included at the end of image postgresql.conf file during database initialization
Copy link
Contributor

@praiskup praiskup Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, github fights against me. This should be either dropped, or at least you should mention that only *.conf files are sourced.

@praiskup
Copy link
Contributor

praiskup commented Jan 9, 2018

[test-openshift]

@praiskup
Copy link
Contributor

lgtm

@pkubatrh
Copy link
Member

Merging, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants