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

Allow "initdb.d" scripts to be (optionally) sourced instead of executed #490

Closed
dakotahawkins opened this issue Aug 24, 2018 · 9 comments
Closed
Labels
Request Request for image modification or feature

Comments

@dakotahawkins
Copy link

Kind-of the opposite of #452 (which fixes #450), but I'd be fine with the current behavior by default provided there can be some means (file name or extension) of sourcing instead of executing.

Rationale:

I have an initialization script that needs file_env(), $POSTGRES_DB, and ${psql[@]}.

When the script is sourced it works, but as none of those are exported, it doesn't work if it's executed. We've had to take care to chmod -x the file to work around this after #452, but that seems kind-of hacky and hard to maintain.

Possible options:

  1. Informal naming convention, e.g. source_*.sh, *.source.sh, .*, or similar
    • Might be hard to document, know about
    • Could be triggered accidentally by unaware users
  2. Separate directory or subdirectory
  3. Export (optionally?) useful functions/variables
    • Hard to maintain
    • Maybe undesirable by default for some users?
  4. Have the default case try to source $f instead of ignoring it
    • Maybe users are exploiting current behavior and putting weird files here for some reason

Thoughts?

@wglambert wglambert added the Request Request for image modification or feature label Aug 24, 2018
@tianon
Copy link
Member

tianon commented Aug 24, 2018

If you remove the executable bit from your .sh file, it will be sourced instead of run:

if [ -x "$f" ]; then

@tianon
Copy link
Member

tianon commented Aug 24, 2018

(As in, this is working as designed, and I'm not sure I understand how/why it's difficult to maintain a chmod -x, so you might need to elaborate a bit. 👍)

@wglambert
Copy link

Related #452

@dakotahawkins
Copy link
Author

@tianon Well, nominally it's not that hard. But since I'm on a windows host it means I had to COPY the file in my Dockerfile instead of mount it in my docker-compose.yml (as you mentioned here). That's really undesirable/annoying for me personally.

@tianon
Copy link
Member

tianon commented Aug 24, 2018

Ah, one simple workaround could be to mount it somewhere else, and adjust your command: to copy/chown it before starting up postgres, something like:

  db:
    image: postgres:10
    command: sh -c 'cp /tmp/xyz.sh /docker-entrypoint-initdb.d/ && chmod -x /docker-entrypoint-initdb.d/xyz.sh && exec docker-entrypoint.sh postgres'
    volumes:
      - ./xyz.sh:/tmp/xyz.sh:ro

@dakotahawkins
Copy link
Author

That's a better workaround indeed.

Still, it seems like many (most?) users would want access to the environment of docker_entrypoint.sh, no? It's good there's a choice, but something a little more declarative than the executable bit (for Windows hosts especially) sounds nicer to me.

If nobody else agrees, though, I can live with the workaround :)

@dakotahawkins
Copy link
Author

@tianon Unless I'm mistaken, for that workaround the entrypoint needs to be changed (from docker-entrypoint.sh) as well, right?

@tianon
Copy link
Member

tianon commented Aug 24, 2018 via email

@dakotahawkins
Copy link
Author

Ah, that's what it does. I was confused I think, I didn't re-run docker_entrypoint!

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

No branches or pull requests

4 participants