Last active
December 22, 2023 10:48
-
-
Save wwerner/05a8e627e8f3ba18300db745511d3bcb to your computer and use it in GitHub Desktop.
Enable heroku ps:exec in docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:8-jdk-alpine | |
VOLUME /tmp | |
# see https://devcenter.heroku.com/articles/exec#enabling-docker-support | |
RUN apk add --no-cache curl bash openssh python | |
ADD src/main/docker/heroku-exec.sh /app/.profile.d/heroku-exec.sh | |
RUN chmod a+x /app/.profile.d/heroku-exec.sh | |
ADD src/main/docker/sh-wrapper.sh /bin/sh-wrapper.sh | |
RUN chmod a+x /bin/sh-wrapper.sh | |
RUN rm /bin/sh && ln -s /bin/sh-wrapper.sh /bin/sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# see https://devcenter.heroku.com/articles/exec#enabling-docker-support | |
[ -z "$SSH_CLIENT" ] && source <(curl --fail --retry 3 -sSL "$HEROKU_EXEC_URL") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
/bin/bash "$@" |
sh-wrapper.sh
could be replaced by setting set +o posix
in heroku-exec.sh
.
Thank you for this!
i found i had to add a python symlink to my dockerfile, to get this working with alpine in October 2020:
ln -s /usr/bin/python3 /usr/bin/python
here is a complete alpine dockerfile (for a basic nginx app), that works with heroku-exec:
FROM alpine:latest
# install required packages
RUN apk add --no-cache --update python3 bash curl openssh nginx
# simplfy nginx config to enable ENV variable substitution
RUN echo 'server { listen PORT_NUMBER; }' > /etc/nginx/conf.d/default.conf \
&& mkdir /run/nginx
# add config required for HEROKU_EXEC
# ENV HEROKU_EXEC_DEBUG=1
RUN rm /bin/sh \
&& ln -s /bin/bash /bin/sh \
&& mkdir -p /app/.profile.d/ \
&& printf '#!/usr/bin/env bash\n\nset +o posix\n\n[ -z "$SSH_CLIENT" ] && source <(curl --fail --retry 7 -sSL "$HEROKU_EXEC_URL")\n' > /app/.profile.d/heroku-exec.sh \
&& chmod +x /app/.profile.d/heroku-exec.sh \
&& ln -s /usr/bin/python3 /usr/bin/python
# configure NGINX to listen on dynamic $PORT env variable supplied by Heroku.
CMD sed -i 's/PORT_NUMBER/'"$PORT"'/g' /etc/nginx/conf.d/default.conf; nginx -g 'daemon off;'
I still can't seem to get this working. I've tried their longer, non-Ubuntu script as well, I have heroku-exec.sh
in both possible locations, Python symlinked, set +o posix
. I may have to try sh-wrapper.sh
yet.
Thanks everyone! @MrFishFinger's solution for alpine worked for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sources: