From fb23bd5d269622dbf3cd34f9d645bda3a5e3b230 Mon Sep 17 00:00:00 2001 From: Romain Date: Fri, 18 Feb 2022 15:44:08 +0100 Subject: [PATCH] Fix empty WebUI static assets directory --- .github/workflows/build.yaml | 2 +- .github/workflows/test-unit.yaml | 2 +- .github/workflows/validate.yaml | 2 +- .gitignore | 1 - .semaphore/semaphore.yml | 2 +- Makefile | 13 ++++++++----- docs/content/contributing/building-testing.md | 2 +- webui/.gitignore | 4 ++++ webui/dev/scripts/transfer.js | 1 + webui/readme.md | 16 ++++++++-------- .../static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md | 1 + 11 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 49e945f2c..7a4d8c996 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,7 +23,7 @@ jobs: - name: Build webui run: | - make generate-webui + make clean-webui generate-webui tar czvf webui.tar.gz ./webui/static/ - name: Artifact webui diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index a1d861a31..3502c2a92 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -40,7 +40,7 @@ jobs: restore-keys: ${{ runner.os }}-test-unit-go- - name: Avoid generating webui - run: mkdir -p webui/static && touch webui/static/index.html + run: touch webui/static/index.html - name: Tests run: make test-unit diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 5fb080436..d6b637642 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -48,7 +48,7 @@ jobs: run: curl -sfL https://raw.githubusercontent.com/client9/misspell/master/install-misspell.sh | sh -s -- -b $(go env GOPATH)/bin ${MISSSPELL_VERSION} - name: Avoid generating webui - run: mkdir -p webui/static && touch webui/static/index.html + run: touch webui/static/index.html - name: Validate run: make validate diff --git a/.gitignore b/.gitignore index 7cb18a276..461f51e8a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ .DS_Store /dist /webui/.tmp/ -/webui/static/ /site/ /docs/site/ /autogen/ diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 52f359b13..a77104b2b 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -40,7 +40,7 @@ blocks: - name: Test Integration commands: - make pull-images - - mkdir -p webui/static && touch webui/static/index.html # Avoid generating webui + - touch webui/static/index.html # Avoid generating webui - PRE_TARGET="" make binary - make test-integration - df -h diff --git a/Makefile b/Makefile index 338583ad8..be6a15272 100644 --- a/Makefile +++ b/Makefile @@ -58,14 +58,18 @@ dist: build-webui-image: docker build -t traefik-webui --build-arg ARG_PLATFORM_URL=$(PLATFORM_URL) -f webui/Dockerfile webui +## Clean WebUI static generated assets +clean-webui: + rm -r webui/static + mkdir -p webui/static + echo 'For more information show `webui/readme.md`' > webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md + ## Generate WebUI generate-webui: - if [ ! -d "webui/static" ]; then \ + if [ ! -f "webui/static/index.html" ]; then \ $(MAKE) build-webui-image; \ - mkdir -p webui/static; \ docker run --rm -v "$$PWD/webui/static":'/src/webui/static' traefik-webui npm run build:nc; \ docker run --rm -v "$$PWD/webui/static":'/src/webui/static' traefik-webui chown -R $(shell id -u):$(shell id -g) ./static; \ - echo 'For more information show `webui/readme.md`' > $$PWD/webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md; \ fi ## Build the linux binary @@ -114,8 +118,7 @@ validate: $(PRE_TARGET) bash $(CURDIR)/script/validate-shell-script.sh ## Clean up static directory and build a Docker Traefik image -build-image: binary - rm -rf webui/static +build-image: clean-webui binary docker build -t $(TRAEFIK_IMAGE) . ## Build a Docker Traefik image diff --git a/docs/content/contributing/building-testing.md b/docs/content/contributing/building-testing.md index 7572e2f6e..9c96ae784 100644 --- a/docs/content/contributing/building-testing.md +++ b/docs/content/contributing/building-testing.md @@ -102,7 +102,7 @@ Once you've set up your go environment and cloned the source repository, you can ```bash # Generate UI static files -rm -rf ./webui/static/; make generate-webui +make clean-webui generate-webui # required to merge non-code components into the final binary, # such as the web dashboard/UI diff --git a/webui/.gitignore b/webui/.gitignore index 94d7eb53f..db32ba46c 100644 --- a/webui/.gitignore +++ b/webui/.gitignore @@ -26,3 +26,7 @@ yarn-error.log* # local env files .env.local .env.*.local + +# static assets (ignore all except the DO NOT EDIT file) +static/* +!static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md diff --git a/webui/dev/scripts/transfer.js b/webui/dev/scripts/transfer.js index d6ec3c4fc..ed812efff 100644 --- a/webui/dev/scripts/transfer.js +++ b/webui/dev/scripts/transfer.js @@ -5,6 +5,7 @@ const folder = process.argv[2] async function execute () { try { await fs.emptyDir('./static') + await fs.outputFile('./static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md', 'For more information show `webui/readme.md`') console.log('Deleted static folder contents!') await fs.copy(`./dist/${folder}`, './static', { overwrite: true }) console.log('Installed new files in static folder!') diff --git a/webui/readme.md b/webui/readme.md index 426698bbe..8d23a7a8b 100644 --- a/webui/readme.md +++ b/webui/readme.md @@ -14,15 +14,15 @@ Traefik Web UI provide 2 types of information: Use the make file : ```shell -make build-image # Generate Docker image -make generate-webui # Generate static contents in `traefik/webui/static/` folder. +make build-image # Generate Docker image. +make clean-webui generate-webui # Generate static contents in `webui/static/` folder. ``` ## How to build (only for frontend developer) - prerequisite: [Node 12.11+](https://nodejs.org) [Npm](https://www.npmjs.com/) -- Go to the `webui` directory +- Go to the `webui/` directory - To install dependencies, execute the following commands: @@ -32,9 +32,9 @@ make generate-webui # Generate static contents in `traefik/webui/static/` fold - `npm run build` -- Static contents are built in the `webui/static` directory +- Static contents are built in the `webui/static/` directory -**Do not manually change the files in the `webui/static` directory** +**Do not manually change the files in the `webui/static/` directory** - The build allows to: - optimize all JavaScript @@ -46,10 +46,10 @@ make generate-webui # Generate static contents in `traefik/webui/static/` fold ## How to edit (only for frontend developer) -**Do not manually change the files in the `webui/static` directory** +**Do not manually change the files in the `webui/static/` directory** -- Go to the `webui` directory -- Edit files in `webui/src` +- Go to the `webui/` directory +- Edit files in `webui/src/` - Run in development mode : - `npm run dev` diff --git a/webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md b/webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md new file mode 100644 index 000000000..a0965fd38 --- /dev/null +++ b/webui/static/DONT-EDIT-FILES-IN-THIS-DIRECTORY.md @@ -0,0 +1 @@ +For more information show `webui/readme.md` \ No newline at end of file