diff options
author | Dan Duvall <dduvall@wikimedia.org> | 2017-08-23 09:58:32 -0700 |
---|---|---|
committer | Dan Duvall <dduvall@wikimedia.org> | 2017-09-05 09:54:04 -0700 |
commit | 89a5377118df6420e9f6b772f10144927730cfcb (patch) | |
tree | 37782440e1479f55ece2ff32db7ad3bbed99a172 | |
parent | 588a5eec5428de559f55207b72e5e35a8ad72719 (diff) | |
download | blubber-89a5377118df6420e9f6b772f10144927730cfcb.tar.gz |
Install node modules into common local directory
Summary:
Install node application dependencies into the common unprivileged
directory defined and managed by `RunsConfig`, and define `NODE_PATH`
such that node applications will search the directory for modules.
This fixes the optimization of image layers by using the original
location for installed modules instead of performing a subsequent move
of the modules back into the project directory. The latter may or may
not result in an additional fs layer depending on the backing storage,
making the previous install/move method unreliable.
Fixes T171632
Depends on D741, D756
Test Plan: Run `go test ./...` or `arc unit`. Build a node application image.
Reviewers: thcipriani, mobrovac, mmodell, #release-engineering-team
Reviewed By: thcipriani, #release-engineering-team
Tags: #release-engineering-team
Maniphest Tasks: T171632
Differential Revision: https://phabricator.wikimedia.org/D757
-rw-r--r-- | config/npm.go | 9 | ||||
-rw-r--r-- | config/npm_test.go | 14 |
2 files changed, 9 insertions, 14 deletions
diff --git a/config/npm.go b/config/npm.go index 26fd0ad..ba3dc26 100644 --- a/config/npm.go +++ b/config/npm.go @@ -5,8 +5,6 @@ import ( "phabricator.wikimedia.org/source/blubber.git/build" ) -const tempNpmInstallDir = "/tmp/node-deps/" - type NpmConfig struct { Install Flag `yaml:"install"` Env string `yaml:"env"` @@ -25,7 +23,7 @@ func (npm NpmConfig) InstructionsForPhase(phase build.Phase) []build.Instruction switch phase { case build.PhasePreInstall: npmInstall := build.RunAll{[]build.Run{ - {"cd", []string{tempNpmInstallDir}}, + {"cd", []string{LocalLibPrefix}}, {"npm install", []string{}}, }} @@ -37,13 +35,12 @@ func (npm NpmConfig) InstructionsForPhase(phase build.Phase) []build.Instruction } return []build.Instruction{ - build.Run{"mkdir -p", []string{tempNpmInstallDir}}, - build.Copy{[]string{"package.json"}, tempNpmInstallDir}, + build.Copy{[]string{"package.json"}, LocalLibPrefix}, npmInstall, } case build.PhasePostInstall: return []build.Instruction{ - build.Run{"mv", []string{path.Join(tempNpmInstallDir, "node_modules"), "./"}}, + build.Env{map[string]string{"NODE_PATH": path.Join(LocalLibPrefix, "node_modules")}}, } } } diff --git a/config/npm_test.go b/config/npm_test.go index d73eb75..da46fcc 100644 --- a/config/npm_test.go +++ b/config/npm_test.go @@ -65,10 +65,9 @@ func TestNpmConfigInstructionsNonProduction(t *testing.T) { t.Run("PhasePreInstall", func(t *testing.T) { assert.Equal(t, []build.Instruction{ - build.Run{"mkdir -p", []string{"/tmp/node-deps/"}}, - build.Copy{[]string{"package.json"}, "/tmp/node-deps/"}, + build.Copy{[]string{"package.json"}, "/opt/lib"}, build.RunAll{[]build.Run{ - {"cd", []string{"/tmp/node-deps/"}}, + {"cd", []string{"/opt/lib"}}, {"npm install", []string{}}, }}, }, @@ -79,7 +78,7 @@ func TestNpmConfigInstructionsNonProduction(t *testing.T) { t.Run("PhasePostInstall", func(t *testing.T) { assert.Equal(t, []build.Instruction{ - build.Run{"mv", []string{"/tmp/node-deps/node_modules", "./"}}, + build.Env{map[string]string{"NODE_PATH": "/opt/lib/node_modules"}}, }, cfg.InstructionsForPhase(build.PhasePostInstall), ) @@ -100,10 +99,9 @@ func TestNpmConfigInstructionsProduction(t *testing.T) { t.Run("PhasePreInstall", func(t *testing.T) { assert.Equal(t, []build.Instruction{ - build.Run{"mkdir -p", []string{"/tmp/node-deps/"}}, - build.Copy{[]string{"package.json"}, "/tmp/node-deps/"}, + build.Copy{[]string{"package.json"}, "/opt/lib"}, build.RunAll{[]build.Run{ - {"cd", []string{"/tmp/node-deps/"}}, + {"cd", []string{"/opt/lib"}}, {"npm install", []string{"--production"}}, {"npm dedupe", []string{}}, }}, @@ -115,7 +113,7 @@ func TestNpmConfigInstructionsProduction(t *testing.T) { t.Run("PhasePostInstall", func(t *testing.T) { assert.Equal(t, []build.Instruction{ - build.Run{"mv", []string{"/tmp/node-deps/node_modules", "./"}}, + build.Env{map[string]string{"NODE_PATH": "/opt/lib/node_modules"}}, }, cfg.InstructionsForPhase(build.PhasePostInstall), ) |