Skip to content

Instantly share code, notes, and snippets.

@christopherdeutsch
Last active July 28, 2020 17:44
Show Gist options
  • Select an option

  • Save christopherdeutsch/3a4d1ee506313b65607cb0959514883a to your computer and use it in GitHub Desktop.

Select an option

Save christopherdeutsch/3a4d1ee506313b65607cb0959514883a to your computer and use it in GitHub Desktop.
webpack cache-at-build-time Dockerfile example
#!/bin/bash
# read in WEBPACK_BUILD_ENV that was written at build time in the Dockerfile (above)
. /webpack-environment.env
if [[ "$1" = "myapp" ]]; then
if [[ -z "$ENV" || "$WEBPACK_BUILD_ENV" != "$ENV" ]]; then
npm run "build:${environment}"
fi
exec myapp
fi
exec "$@"
# build webpack at runtime and write the build envionment name to a file
FROM whatever
ARG WEBPACK_BUILD_ENV=dev
RUN npm run build:${WEBPACK_BUILD_ENV && echo ${WEBPACK_BUILD_ENV} > /webpack-environment.env
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["myapp"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment