Skip to content

Commit

Permalink
Update ui build to avoid yarn build fail after make.
Browse files Browse the repository at this point in the history
we are building ui-dist in make using docker image of nodejs after
building dist it put those dist in build or build-external folder.
These folders are created by docker run under root user. After make
if we try to build it locally by yarn build it tries to delete build
folder from $USER user thats why we are getting permission error.

```bash
shovan@probot:~/Desktop/workspace/src/github.com/weaveworks/scope/client$ ls -l
total 420
drwxr-xr-x    7 shovan shovan   4096 Jun 12 15:46 app
drwxr-xr-x    2 root   root     4096 Jun 13 00:42 build
drwxr-xr-x    2 root   root     4096 Jun 13 00:37 build-external
-rw-r--r--    1 shovan shovan    608 Jun 12 15:46 Dockerfile
drwxr-xr-x 1016 shovan shovan  36864 Jun 13 00:36 node_modules
-rw-r--r--    1 shovan shovan   4642 Jun 13 00:29 package.json
-rw-r--r--    1 shovan shovan   1764 Jun 12 15:46 README.md
-rw-r--r--    1 shovan shovan   2623 Jun 12 15:46 server.js
drwxr-xr-x    5 shovan shovan   4096 Jun 12 16:14 test
-rw-r--r--    1 shovan shovan   4239 Jun 12 15:46 webpack.local.config.js
-rw-r--r--    1 shovan shovan   3856 Jun 13 00:27 webpack.production.config.js
-rw-r--r--    1 shovan shovan 334991 Jun 12 15:46 yarn.lock
```

Fix -

This PR will add 2 more target in package.json for build inside docker
`yarn run build-docker` and `yarn run build-external-docker` in targerts
of makefile it uses these to to build using node docker image and copy
build files in `build` and `build-external` folder. Folders `build` and
`build-external` will be created by $USER user so we will not get permission
error in local yarn build after make.

Signed-off-by: Shovan Maity <[email protected]>
  • Loading branch information
shovanmaity committed Jun 12, 2019
1 parent c2e83ab commit a37f8c6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extras/copyreport/copyreport
app/static.go
vendor/github.com/ugorji/go/codec/codecgen/bin/*
*.codecgen.go
client/build-external/*
client/build*
prog/staticui/*
prog/externalui/*
client/build-pkg
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ update-cri:
protoc-gen-gofast:
@go get -u -v github.com/gogo/protobuf/protoc-gen-gofast

# Use cri target to download latest cri proto files and regenerate CRI runtime files.
# Use cri target to download latest cri proto files and regenerate CRI runtime files.
cri: update-cri protoc-gen-gofast
@cd $(GOPATH)/src;protoc --proto_path=$(GOPATH)/src --gofast_out=plugins=grpc:. github.com/weaveworks/scope/cri/runtime/api.proto

Expand Down Expand Up @@ -159,26 +159,30 @@ $(SCOPE_UI_TOOLCHAIN_UPTODATE): client/yarn.lock $(SCOPE_UI_BUILD_UPTODATE)
touch $(SCOPE_UI_TOOLCHAIN_UPTODATE)

client/build/index.html: $(shell find client/app -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE)
mkdir -p client/build
rm -rf client/build
if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then \
$(SUDO) docker run $(RM) $(RUN_FLAGS) \
-v $(shell pwd)/.cache:/home/weave/scope/.cache \
-v $(shell pwd)/client:/home/weave/scope/client \
-v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \
-w /home/weave/scope/client \
$(SCOPE_UI_BUILD_IMAGE) yarn run build; \
$(SCOPE_UI_BUILD_IMAGE) yarn run build-docker; \
fi
mkdir -p client/build
cp -r client/build-docker/* client/build

client/build-external/index.html: $(shell find client/app -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE)
mkdir -p client/build-external
rm -rf client/build-external
if test "true" != "$(SCOPE_SKIP_UI_ASSETS)"; then \
$(SUDO) docker run $(RM) $(RUN_FLAGS) \
-v $(shell pwd)/.cache:/home/weave/scope/.cache \
-v $(shell pwd)/client:/home/weave/scope/client \
-v $(shell pwd)/$(SCOPE_UI_TOOLCHAIN):/home/weave/scope/client/node_modules \
-w /home/weave/scope/client \
$(SCOPE_UI_BUILD_IMAGE) yarn run build-external; \
$(SCOPE_UI_BUILD_IMAGE) yarn run build-external-docker; \
fi
mkdir client/build-external
cp -r client/build-docker-external/* client/build-external

client-test: $(shell find client/app/scripts -type f) $(SCOPE_UI_TOOLCHAIN_UPTODATE)
$(SUDO) docker run $(RM) $(RUN_FLAGS) \
Expand Down
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
"scripts": {
"build": "webpack --config webpack.production.config.js",
"build-external": "EXTERNAL=true webpack --config webpack.production.config.js",
"build-docker": "DOCKER=true webpack --config webpack.production.config.js",
"build-external-docker": "DOCKER=true EXTERNAL=true webpack --config webpack.production.config.js",
"copy-pkg-files": "cp package.json build-pkg/ && cp -R app/styles build-pkg/",
"build-pkg": "mkdir -p build-pkg && node node_modules/.bin/babel app/scripts --ignore __tests__ --out-dir build-pkg && yarn run copy-pkg-files",
"bundle": "mkdir -p bundle && yarn run build-pkg && cd ./build-pkg && yarn pack --filename ../bundle/weave-scope.tgz",
Expand Down
8 changes: 8 additions & 0 deletions client/webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ if (process.env.EXTERNAL) {
PUBLIC_PATH = 'https://s3.amazonaws.com/static.weave.works/scope-ui/';
}

if (process.env.DOCKER) {
if (process.env.EXTERNAL) {
OUTPUT_PATH = 'build-docker-external/';
}else{
OUTPUT_PATH = 'build-docker/';
}
}

/**
* This is the Webpack configuration file for production.
*/
Expand Down

0 comments on commit a37f8c6

Please sign in to comment.