Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Images Postgres Alpine, optimization #207

Merged
merged 1 commit into from
Feb 26, 2018
Merged

Conversation

andruwa13
Copy link
Contributor

No description provided.

db/Dockerfile Outdated
RUN apt-get update \
&& apt-get install -y \
build-essential \
RUN apk add --no-cache --virtual .build-deps \
curl \
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I sound maniac, but can you order package list in alphabetical order please (like it was before) ? It is a good practice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix

@pichouk
Copy link
Contributor

pichouk commented Nov 21, 2017

I just test it on my test server and my production server, it works perfect :)
But I'm not using Wal-e and I think it is important. If you can test it, that's great. If not we'll try to find out someone for this ^^

I also add @xcompass as reviewer. I like to have his wise feedback on change like this.

@andruwa13
Copy link
Contributor Author

@pichouk I also do not have the opportunity to check how Wal-e works (

db/entrypoint.sh Outdated
@@ -20,6 +16,8 @@ function update_conf () {
sed -i "s/wal_level =.*$/wal_level = $WAL_LEVEL/g" $PGDATA/postgresql.conf
sed -i "s/archive_mode =.*$/archive_mode = $ARCHIVE_MODE/g" $PGDATA/postgresql.conf
sed -i "s/archive_timeout =.*$/archive_timeout = $ARCHIVE_TIMEOUT/g" $PGDATA/postgresql.conf
sed -i "s/log_timezone =.*$/log_timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf
sed -i "s/timezone =.*$/timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an indentation mistake here :)

db/entrypoint.sh Outdated
@@ -46,6 +48,9 @@ if [ "$1" = 'postgres' ]; then

WAL_LEVEL=archive
ARCHIVE_MODE=on

echo "log_timezone = $DEFAULT_TIMEZONE" >> $PGDATA/postgresql.conf
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the $PGDATA folder should be a mounted volume, so data inside it are persistent. So it seems that everytime the container restart it will add two new lines inside the postgresql.conf file. Am I right ? If true this is not a correct behavior, but I don't know a correct workaround for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, right. this fixes errors:

invalid value for parameter "log_timezone": "localtime"
invalid value for parameter "TimeZone": "localtime"
configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but this is not ok if our container just append lines to a persistent configuration file at each restart.
I tried to reproduce the errors you show, but it seems that it didn't happen if you mount /etc/localtime inside the container like we do on our docker-compose.yml file

Copy link
Contributor

Choose a reason for hiding this comment

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

Oups I just see that you can remove those two lines since you add this :

sed -i "s/log_timezone =.*$/log_timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf
sed -i "s/timezone =.*$/timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On RancherOS if there is not this line there will be errors that I sent above. Delete echo "log_timezone = $DEFAULT_TIMEZONE" >> $PGDATA/postgresql.conf ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the sed commands you add should fix it. Can you try without the two following echo instructions please ?

echo "log_timezone = $DEFAULT_TIMEZONE" >> $PGDATA/postgresql.conf
echo "timezone = $DEFAULT_TIMEZONE" >> $PGDATA/postgresql.conf

If there is still errors, we'll have to investigate on another way to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RancherOS not work, if you delete :(

echo "log_timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf
echo "timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf

Log:

25.11.2017 19:25:38LOG:  invalid value for parameter "log_timezone": "localtime"
25.11.2017 19:25:38LOG:  invalid value for parameter "TimeZone": "localtime"
25.11.2017 19:25:38FATAL:  configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete ?
this

sed -i "s/log_timezone =.*$/log_timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf
sed -i "s/timezone =.*$/timezone = $DEFAULT_TIMEZONE/g" $PGDATA/postgresql.conf

without it

echo "log_timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf
echo "timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf

does not work

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the correct workaround can be:

  • check (using grep) if timezone = and log_timezone = are already present in the file
  • if yes, use sed to set the value
  • if not, append the configuration lines using echo >>

Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could remove the timezone and log_timezone lines first and then append them:

sed -i "s/log_timezone =.*$//g" $PGDATA/postgresql.conf
sed -i "s/timezone =.*$//g" $PGDATA/postgresql.conf
echo "log_timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf
echo "timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf

@pichouk
Copy link
Contributor

pichouk commented Nov 25, 2017

TODO/reminder before validating this PR:

@andruwa13
Copy link
Contributor Author

andruwa13 commented Nov 25, 2017

test WALE_S3, not work

25.11.2017 19:59:10LOG:  archive command failed with exit code 127
25.11.2017 19:59:10DETAIL:  The failed archive command was: envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push pg_xlog/00000001000000000000000C
25.11.2017 19:59:11sh: envdir: not found
25.11.2017 19:59:11LOG:  archive command failed with exit code 127
25.11.2017 19:59:11DETAIL:  The failed archive command was: envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push pg_xlog/00000001000000000000000C
25.11.2017 19:59:12sh: envdir: not found
25.11.2017 19:59:12LOG:  archive command failed with exit code 127
25.11.2017 19:59:12DETAIL:  The failed archive command was: envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push pg_xlog/00000001000000000000000C
25.11.2017 19:59:12WARNING:  archiving transaction log file "00000001000000000000000C" failed too many times, will try again later

@pichouk
Copy link
Contributor

pichouk commented Nov 27, 2017

Hmm seems that it is an issue with envdir. Maybe it is just a missing command in Alpine.

@andruwa13
Copy link
Contributor Author

WAL-E not support Alpine :(

@pichouk
Copy link
Contributor

pichouk commented Nov 29, 2017

Arf... What made you say that ?

db/Dockerfile Outdated

&& pip --no-cache-dir install 'wal-e<1.0.0' \
&& rm -rf /var/cache/apk/* /tmp/* /var/tmp/* \
&& apk del .build-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

here you removed tzdata. Isn't it being used for timezone info for postgres later when user sets timezone? And I think the same for ca-certificates, pv, py-cffi and py-cryptography. They are not build dependencies but runtime dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix, py-cryptography - without it does not work

db/entrypoint.sh Outdated
@@ -46,6 +48,9 @@ if [ "$1" = 'postgres' ]; then

WAL_LEVEL=archive
ARCHIVE_MODE=on

echo "log_timezone = $DEFAULT_TIMEZONE" >> $PGDATA/postgresql.conf
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could remove the timezone and log_timezone lines first and then append them:

sed -i "s/log_timezone =.*$//g" $PGDATA/postgresql.conf
sed -i "s/timezone =.*$//g" $PGDATA/postgresql.conf
echo "log_timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf
echo "timezone = $ DEFAULT_TIMEZONE" >> $ PGDATA / postgresql.conf

db/Dockerfile Outdated
&& apt-get install -y \
build-essential \
RUN apk add --no-cache --virtual .build-deps \
bash \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this as we are aiming for smaller image.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 But then we need to use #/bin/sh for the entrypoint.sh script. Should test if it also works OK with sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not work
03.12.2017 1:24:49/entrypoint.sh: line 29: syntax error: unexpected "(" (expecting "fi")

Copy link
Contributor

Choose a reason for hiding this comment

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

The entrypoint script need some rewrite to work with sh. But I think we can achieve this.

@andruwa13
Copy link
Contributor Author

WAL-E, not work to alpine(
error:

03.12.2017 2:10:50LOG:  archive command failed with exit code 127
03.12.2017 2:10:50DETAIL:  The failed archive command was: envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push pg_xlog/000000010000000000000002
03.12.2017 2:10:50WARNING:  archiving transaction log file "000000010000000000000002" failed too many times, will try again later

@andruwa13
Copy link
Contributor Author

andruwa13 commented Dec 3, 2017

@pichouk @xcompass can make a backup (WAL-E) a separate container?

@pichouk
Copy link
Contributor

pichouk commented Dec 5, 2017

About the WAL-E support, I really don't know what to do. I don't use it and I don't really know why it didn't work on Alpine.

I would like to investigate on this, but I have no time for now. I'll see in few days/weeks if I can achieve to something with WAL-E and Alpine.

@pichouk pichouk added the Work In Progress Not yet ready for review label Dec 5, 2017
@xcompass
Copy link
Contributor

xcompass commented Dec 7, 2017

I don't think we can use a separate container. I think postgres is actually calling WAL-E script directly. Re: WAL-E error, could you enable WAL-E logging: https://github.com/wal-e/wal-e#logging to see where it fails? Might be a configuration thing.

@pichouk
Copy link
Contributor

pichouk commented Jan 22, 2018

Just push some changes which should fix wal-e support. But image is bigger (345MB).

@andruwa13
Copy link
Contributor Author

@pichouk not work(
rancher 2018-01-22 20-33-45

@pichouk
Copy link
Contributor

pichouk commented Jan 23, 2018

Ok I get it. In fact the postgresql configuration file ($PGDATA/postgresql.conf), which also configure Wal-e is setup by the setup-wale.sh script. This script is put on the /docker-entrypoint-initdb.d/ folder so it is executed once (and only once) at the database initialization. So my workaround works for new database but not existing ones.
I'll find something better.

@pichouk
Copy link
Contributor

pichouk commented Jan 23, 2018

It should works now :)

@andruwa13
Copy link
Contributor Author

@pichouk Goog work! Work old DataBases and new

@pichouk
Copy link
Contributor

pichouk commented Jan 24, 2018

Snap, just tried to deploy it on my existing server and I got this error

LOG:  invalid value for parameter "log_timezone": "localtime"
LOG:  invalid value for parameter "TimeZone": "localtime"
FATAL:  configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors

Thought it was solved ?

@andruwa13
Copy link
Contributor Author

yes 7ed04e8

@pichouk
Copy link
Contributor

pichouk commented Jan 25, 2018

Seems that you removed it on 321b162

@pichouk
Copy link
Contributor

pichouk commented Feb 5, 2018

I squashed all commits and tested the image. Seems to works with existing and new databases :)
Looks good to me ! I'll like an approval from @xcompass too but apart from that I'm ok to merge.

@IonCharge
Copy link

IonCharge commented Feb 13, 2018

Are you including Bash in the alpine package? Or just Sh? It seems Mattermost needs/prefers bash?
Maybe worth seeing if it fixes this issue: #234

Just add the following to the dockerfile for the app:
RUN apk add --no-cache bash and change the entrypoint to be bin\bash

@pichouk

@pichouk
Copy link
Contributor

pichouk commented Feb 13, 2018

@ionbasa I don't understand, this PR is about PostgreSQL image, not App image. I guess you speak about #208 right ?

@IonCharge
Copy link

@pichouk Yes, I posted in the wrong PR, sorry.

@pichouk pichouk removed need tests in production null Work In Progress Not yet ready for review labels Feb 26, 2018
@pichouk
Copy link
Contributor

pichouk commented Feb 26, 2018

I guess we can merge now. Thanks a lot @andruwa13 :)

@pichouk pichouk merged commit 4e24257 into mattermost:master Feb 26, 2018
abarbare pushed a commit to abarbare/mattermost-docker that referenced this pull request Feb 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2: Dev Review Requires review by a core committer Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants