Skip to content

ROX-12556: Always initialize from scratch #941

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

Merged
merged 6 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chart/templates/db-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
env:
- name: POSTGRES_PASSWORD_FILE
value: "/run/secrets/stackrox.io/secrets/password"
command: ["docker-entrypoint.sh"]
args: ["init", "postgres", "-c", "config_file=/etc/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.

what does stackrox repo do?

resources:
limits:
cpu: 2
Expand Down
30 changes: 29 additions & 1 deletion image/db/rhel/scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,26 @@ _main() {
set -- postgres "$@"
fi

### STACKROX MODIFIED - Declare variable useful to determine if we want to initialize the DB.
local init
if [ "$1" = 'init' ]; then
init='true'
shift
fi

if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
### STACKROX MODIFIED - If we are initializing, then ensure we start from scratch.
if [ -n "$init" ]; then
echo
echo 'Initializing... Clearing any previous data from directories'
echo

rm -rf "$PGDATA"
if [ -n "${POSTGRES_INITDB_WALDIR:-}" ]; then
rm -rf "$POSTGRES_INITDB_WALDIR"
fi
fi

docker_setup_env
# setup data directories and permissions (when run as root)
docker_create_db_directories
Expand All @@ -317,7 +336,16 @@ _main() {
exec gosu postgres "$BASH_SOURCE" "$@"
fi

### STACKROX MODIFIED - If there is no data, initialize and exit.
### STACKROX MODIFIED - Sanity check the database does not exist
### upon initialization.
if [ -n "$init" ] && [ -n "$DATABASE_ALREADY_EXISTS" ]; then
echo
echo 'PostgreSQL Database appears to already exist upon initialization; Exiting with error...'
echo

exit 1
fi

# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
Expand Down