I'm trying to build a docker image that optionally adds a yarn (or npm lockfile) while building. I'd like to add it explicitly, but also not fail the build if it isn't included.
The intent is to respect it if the hosted application uses a deterministic build process, but not force it to. I'd also like to let an application use this container to bootstrap itself into deterministic builds.
Here's what I'm starting with:
FROM node:8.12.0-alpine
USER node
WORKDIR ${my_workdir}
COPY --chown=node:node src/yarn.lock ./
COPY --chown=node:node src/package*.json ./
RUN yarn && yarn cache clean
COPY --chown=node:node src/ .
CMD []
Is there a command or option I can use instead of copy that won't fail if the src/yarn.lock
file isn't on the filesystem?
You can try adding the yarn.lock as yarn.lock*
along with another file so that the COPY won't fail. Something along these line should do the trick:
FROM node:8.12.0-alpine
USER node
WORKDIR ${my_workdir}
COPY --chown=node:node src/package*.json src/yarn.lock* ./
RUN yarn && yarn cache clean
COPY --chown=node:node src/ .
CMD []
Hope it helps!