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

Apply Migration Scripts on docker startup #56

Open
Hassnain-Alvi opened this issue May 6, 2019 · 0 comments
Open

Apply Migration Scripts on docker startup #56

Hassnain-Alvi opened this issue May 6, 2019 · 0 comments

Comments

@Hassnain-Alvi
Copy link

I am Unable to initialise database with schema evolution manager on docker startup. My docker file is as follows

FROM postgres:10-alpine

WORKDIR /opt/luminary-api-db
COPY . .

RUN apk add py-pip ruby ruby-rdoc
RUN gem install schema-evolution-manager && \
    pip install awscli

RUN cp docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d

EXPOSE 5432

docker-entrypoint-initdb.d contain one init script

set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE DATABASE ${POSTGRES_USER}_test;
    GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_USER}_test TO $POSTGRES_USER;
EOSQL

# Applying Sem Scripts
echo
echo 'PostgreSQL initialzing Data...'
echo

psql -U $POSTGRES_USER

sem-apply --url postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost/$POSTGRES_DB
sem-apply --url postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost/$POSTGRES_DB_test

On docker container startup the database is created fine but the schema evolution manager says its unable to connect to database
Here is the complete stack trace

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sh
CREATE DATABASE
GRANT

PostgreSQL initialzing Data...

psql: could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Address not available
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
/usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/library.rb:136:in `rescue in system_or_error': Error running command[psql --no-align --tuples-only --no-psqlrc --command "select count(*) from pg_namespace where nspname='schema_evolution_manager'" postgresql://user:pass@localhost/db]: Non zero exit code[pid 47 exit 2] running command[psql --no-align --tuples-only --no-psqlrc --command "select count(*) from pg_namespace where nspname='schema_evolution_manager'" postgresql://user:pass@localhost/db] (RuntimeError)
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/library.rb:129:in `system_or_error'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:32:in `psql_command'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:90:in `schema_schema_evolution_manager_exists?'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/scripts.rb:86:in `scripts_previously_run'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/scripts.rb:48:in `each_pending'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:22:in `bootstrap!'
	from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/bin/sem-apply:30:in `<top (required)>'
	from /usr/bin/sem-apply:23:in `load'
	from /usr/bin/sem-apply:23:in `<main>'

Can someone tell me how can i fix this issue?

@Hassnain-Alvi Hassnain-Alvi changed the title Initialisation on docker startup Failed Initialisation on docker startup May 6, 2019
@Hassnain-Alvi Hassnain-Alvi changed the title Failed Initialisation on docker startup Apply Migration Scripts on docker startup May 6, 2019
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

No branches or pull requests

1 participant