Skip to content

Commit

Permalink
[YUNIKORN-2481] Convert yunikorn-site to use pnpm
Browse files Browse the repository at this point in the history
- Update build scripts to use pnpm for dependency management
- Ensure node_modules is not shared between Docker and host
- Update Dockerfile to allow pre-caching pnpm dependencies
  • Loading branch information
craigcondit committed Mar 13, 2024
1 parent f7d1d25 commit 2ad4492
Show file tree
Hide file tree
Showing 7 changed files with 10,534 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
# Ignore files to keep site clean
Dockerfile
README.md
*.swp
**/node_modules/
**/.pnpm-store/
local-build.sh
check_license.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ package-lock.json
yarn.lock
_site/
.docusaurus/
.pnpm-store/
node_modules/
build/
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
ARG NODE_VERSION=
FROM node:${NODE_VERSION}

ADD . /yunikorn-site
WORKDIR /yunikorn-site
RUN npm install -g pnpm
COPY pnpm-lock.yaml /yunikorn-site
RUN pnpm fetch

RUN yarn install
RUN yarn add @docusaurus/theme-search-algolia
RUN yarn build
ENTRYPOINT yarn start --host 0.0.0.0
COPY . /yunikorn-site
RUN pnpm install -r --offline
RUN pnpm build
ENTRYPOINT pnpm start --host 0.0.0.0
4 changes: 2 additions & 2 deletions check_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
echo "checking license headers:"
# run different finds on mac vs linux
if [ "${OS}" = "darwin" ]; then
find -E . ! -path "./.git*" ! -path "./.docusaurus*" ! -path "./node_modules*" -regex ".*(Dockerfile|\.(js|sh|md|conf|yaml|yml|html|css))" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
find -E . ! -path "./.git*" ! -path "./.docusaurus*" ! -path "./node_modules*" ! -path ./pnpm-lock.yaml -regex ".*(Dockerfile|\.(js|sh|md|conf|yaml|yml|html|css))" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
else
find . ! -path "./.git*" ! -path "./.docusaurus*" ! -path "./node_modules*" -regex ".*\(Dockerfile\|\.\(js\|sh\|md\|conf\|yaml\|yml\|html\|css\)\)" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
find . ! -path "./.git*" ! -path "./.docusaurus*" ! -path "./node_modules*" ! -path ./pnpm-lock.yaml -regex ".*\(Dockerfile\|\.\(js\|sh\|md\|conf\|yaml\|yml\|html\|css\)\)" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES
fi
# any file mentioned in the output is missing the license
if [ -s LICRES ]; then
Expand Down
25 changes: 9 additions & 16 deletions local-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function clean() {
echo "removing build artifacts:"
echo " docusaurus install" && rm -rf .docusaurus
echo " node modules" && rm -rf node_modules
echo " yarn lock file" && rm -f yarn.lock
echo " build output" && rm -rf build
}

Expand All @@ -44,8 +43,12 @@ function image_build() {
# build local docker image
cat <<EOF >.dockerfile.tmp
FROM node:${NODE_VERSION}
ADD . /yunikorn-site
WORKDIR /yunikorn-site
RUN npm install -g pnpm
COPY pnpm-lock.yaml /yunikorn-site
RUN pnpm fetch
COPY . /yunikorn-site
RUN pnpm install -r --offline
EOF

if ! docker build -t yunikorn/yunikorn-website:latest -f .dockerfile.tmp .; then
Expand All @@ -59,7 +62,7 @@ EOF
function web() {
# start the web server
echo " Starting development server with locale $LOCALE"
docker exec -it yunikorn-site-local /bin/bash -c "yarn start --locale=$LOCALE --host 0.0.0.0"
docker exec -it yunikorn-site-local /bin/bash -c "pnpm start --locale=$LOCALE --host 0.0.0.0"
RET=$?
[ ${RET} -eq 131 ] && echo " ctrl-\ caught, restarting" && return 2
[ ${RET} -eq 130 ] && echo " ctrl-c caught, exiting build" && return 0
Expand All @@ -73,23 +76,13 @@ function run_base() {
if ! docker run -it --name yunikorn-site-local -d \
-p 3000:3000 \
-v "$PWD":/yunikorn-site \
--mount type=volume,dst=/yunikorn-site/node_modules \
yunikorn/yunikorn-website:latest; then

echo "run local docker image failed"
return 1
fi

# install dependency in docker container
if ! docker exec -it yunikorn-site-local /bin/bash -c "yarn install"; then
echo "yarn install failed"
return 1
fi

# install dependency in docker container
if ! docker exec -it yunikorn-site-local /bin/bash -c "yarn add @docusaurus/theme-search-algolia"; then
echo "yarn add failed"
return 1
fi
return 0
}

Expand All @@ -105,8 +98,8 @@ function run_web() {

function run_build() {
# run build inside the container
if ! docker exec -it yunikorn-site-local /bin/bash -c "yarn build"; then
echo "yarn build failed"
if ! docker exec -it yunikorn-site-local pnpm build; then
echo "pnpm build failed"
return 1
fi
return 0
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.0",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
Expand All @@ -12,7 +13,7 @@
"dependencies": {
"@docusaurus/core": "2.4.1",
"@docusaurus/preset-classic": "2.4.1",
"@docusaurus/theme-search-algolia": "^2.4.1",
"@docusaurus/theme-search-algolia": "^2.4.3",
"@mdx-js/react": "^1.5.8",
"clsx": "^1.1.1",
"node": "^18.8.0",
Expand Down
Loading

0 comments on commit 2ad4492

Please sign in to comment.