Skip to content

Commit

Permalink
fix(ci): use npm ci to install node packages
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Sep 20, 2020
1 parent cbc657c commit f6cf8c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
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

0 comments on commit f6cf8c5

Please sign in to comment.