Hacker News new | ask | show | jobs
by 23david 4259 days ago
One additional tip for readability is to replace the && with set -e at the top of any RUN commands that combine more than one command.

before:

  RUN curl -SLO "http://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \
    && tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
    && rm "node-v$NODE_VERSION-linux-x64.tar.gz"
after:

  RUN set -e; \
    curl -SLO "http://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz"; \
    tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1; \
    rm "node-v$NODE_VERSION-linux-x64.tar.gz
2 comments

Hmm, needs additional semi-colons.
where?

I was trying to use the example given... Here's another, smaller example:

  # install wget without artifacts
  RUN set -e; \
    apt-get update; \
    apt-get install -y wget; \
    apt-get clean; \
    rm -rf /var/lib/apt/lists/*
I think parent meant you trade two &&s for one ;.

Personally I also don't think the meaning is as clear, and you now need to maintain the top line if you cut'n'paste. I suppose it's a matter of taste.

Why?
Because it's more readable? It tells you at the top that any failure will fail the whole thing, and you can avoid the prefix `&&` which reduces the effective indentation level and noise.
You can use the same spacing for the ampersands as used for the semicolons (i.e. at the end of the line).

That said, obviously there's going to be different preferences...I was more wondering if there was some semantic difference.

> You can use the same spacing for the ampersands as used for the semicolons (i.e. at the end of the line).

Then if the lines are long (as they are here) they get cut off and it's much harder to notice that they're there at all.