Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): use npm ci to install node packages #2201

Merged
merged 1 commit into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __defaults_go: &DEFAULTS_GO
go: "1.15.2"
cache:
directories:
- ui/node_modules
- "$HOME/.npm"
# https://restic.net/blog/2018-09-02/travis-build-cache
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod
Expand All @@ -21,7 +21,7 @@ __defaults_js: &DEFAULTS_JS
install: []
cache:
directories:
- ui/node_modules
- "$HOME/.npm"
env:
- NODE_ENV=test

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:12.18.4-alpine as nodejs-builder
RUN mkdir -p /src/ui
COPY ui/package.json ui/package-lock.json /src/ui/
ENV NODE_ENV=production
RUN cd /src/ui && npm install
RUN cd /src/ui && npm ci
RUN apk add make git
COPY ui /src/ui
RUN make -C /src/ui build
Expand Down
2 changes: 1 addition & 1 deletion demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:12.18.4-alpine as nodejs-builder
RUN mkdir -p /src/ui
COPY ui/package.json ui/package-lock.json /src/ui/
ENV NODE_ENV=production
RUN cd /src/ui && npm install
RUN cd /src/ui && npm ci
RUN apk add make git
COPY ui /src/ui
RUN make -C /src/ui build
Expand Down
26 changes: 15 additions & 11 deletions ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

NODE_PATH := $(shell npm bin)
PATH := $(PATH):$(NODE_PATH)
SHELL := env PATH=$(PATH) /bin/sh

$(NODE_PATH)/%: package.json package-lock.json
@export D="$*"; \
if [ "$*" = "commitlint-travis" ]; then export D="@commitlint/travis-cli" ; fi; \
if [ "$*" = "build-storybook" ]; then export D="@storybook/react" ; fi; \
if [ "$*" = "percy-storybook" ]; then export D="@percy-io/percy-storybook" ; fi; \
if [ -d "$(CURDIR)/node_modules/$$D" ] && [ ! -x "$@" ]; then (echo "resetting node_modules" && npm ci); else npm install ; fi
@if [ -x $@ ]; then touch -c $@ ; else echo "missing script: $@" ; exit 1; fi
NODE_PATH := $(shell npm bin)
NODE_MODULES := $(shell dirname `npm bin`)
NODE_INSTALL := $(NODE_MODULES)/.install

PATH := $(PATH):$(NODE_PATH)
SHELL := env PATH=$(PATH) /bin/sh

.DEFAULT_GOAL := build/index.html

$(NODE_INSTALL): package.json package-lock.json
@if [ -e $(NODE_INSTALL) ]; then npm install ; else npm ci; fi
touch $@

$(NODE_PATH)/%: $(NODE_INSTALL)
@if [ ! -x $@ ]; then echo "missing script: $@" ; exit 1; fi

build/index.html: $(NODE_PATH)/react-scripts $(call rwildcard, public src, *)
@rm -fr node_modules/.cache/eslint-loader
Expand Down