When generating a Dockerfile for a project that uses execjs and Yarn, the "Install yarn" section of the generated Dockerfile is missing a RUN instruction.
<% else -%>
<% if node_version -%> <% else %>RUN<% end %> corepack enable && \
<% end -%>
Caveats
This fix worked in this particular situation but I'm not sure if it is a drop in solution when execjs is not being used and the node_install ends up rendering the full template.
When generating a Dockerfile for a project that uses
execjs
and Yarn, the "Install yarn" section of the generated Dockerfile is missing aRUN
instruction.Steps to reproduce
The steps below were used to recreate the issue and the result is available here: https://github.com/jeff-french/dockerfile-rails-issue-reproduction
Actual output
This will produce an invalid section starting around line 40 of the generated Dockerfile
Expected output
Investigation
The issue appears to be caused when the
install_node
template is called the second time to setup Yarn: https://github.com/fly-apps/dockerfile-rails/blob/ec2b18e331ebbdfa1e5331268ba3b7f64b66ccc0/lib/generators/templates/Dockerfile.erb#L67-L70In this call
node_version
gets set tonil
due to the usage ofexecjs
andyarn_version
get set to4.0.2
.When the
install_node
template gets rendered from this call, the following section gets skipped entirely sincenode_version=nil
: https://github.com/fly-apps/dockerfile-rails/blob/ec2b18e331ebbdfa1e5331268ba3b7f64b66ccc0/lib/generators/templates/_install_node.erb#L23-L34and then this section attempts to append to the
RUN
command from the previously skipped section: https://github.com/fly-apps/dockerfile-rails/blob/ec2b18e331ebbdfa1e5331268ba3b7f64b66ccc0/lib/generators/templates/_install_node.erb#L35-L46Solution
I was able to get the expected output by changing the following section: https://github.com/fly-apps/dockerfile-rails/blob/ec2b18e331ebbdfa1e5331268ba3b7f64b66ccc0/lib/generators/templates/_install_node.erb#L41-L43
to
Caveats
This fix worked in this particular situation but I'm not sure if it is a drop in solution when
execjs
is not being used and thenode_install
ends up rendering the full template.