kHRISl33t / runtime-env-cra

Runtime environment handler for create-react-apps
MIT License
49 stars 23 forks source link

Using CMD[...] breaks NGINX default entrypoint #18

Open davidmalis opened 2 years ago

davidmalis commented 2 years ago

When using a CMD from the example for usage in Docker environments, the NGINX default entrypoint (/.docker-entrypoint.sh) skips running configuration scripts inside /docker-entrypoint.d

NGINX ships with three of these scripts by default (please see here: https://github.com/nginxinc/docker-nginx/tree/04226fe92cc11bed68dae464eb60fd5399daf3b1/mainline/alpine)

I was able to get arround this issue by moving the execution of runtime-env-cra into my own custom script which I put into the /docker-entrypoint.d, like so:

RUN npm i -g runtime-env-cra@0.2.4
RUN echo -e '\n\
#!/bin/sh\n\
runtime-env-cra\n' >> /docker-entrypoint.d/runtime-env-cra.sh
RUN chmod 775 /docker-entrypoint.d/runtime-env-cra.sh

WORKDIR /usr/share/nginx/html

EXPOSE 80

# remove the CMD and use the one from the base NGINX image

When the container is started, the entrypoint executes scripts from the /docker-entrypoint.d (including my runtime-env-cra script) and then starts the NGINX process.

kHRISl33t commented 2 years ago

Hey!

Glad you figured it out. Can you explain a bit more in-depth why you would need to do that? I'm not sure I understood why you needed this.

davidmalis commented 2 years ago

Sure thing,

basically I'm using templates for NGINX configuration (described here).

And one of the scripts inside NGINX's /docker-entrypoint.d, namely 20-envsubst-on-templates.sh is crucial to me, because it's responsible for moving /etc/nginx/templates/*.template files into the /etc/nginx/conf.d dir, while replacing placeholders inside with envsubst.

When I introduced your lib (which is awesome, btw), my usual pipelines and deployments stopped working. Basically my NGINX based containers would not have my custom configuration in place, but rather the default one which comes with the NGINX, and that happened because your example said to put a specific CMD [...] in Dockerfile, which is doing what it should, but it makes the NGINX /docker-entrypoint.sh skip all its job, including the above script.

kHRISl33t commented 2 years ago

Ah, I see, okay. You have a very custom setup script then :)

Can you create some detailed instructions on how one can achieve this?

I'm happy to update the README for this use-case. I can also play around with it later to see what could be the best solution.