diff --git a/.gitignore b/.gitignore index 02e0ca300d..1c75d321d9 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ budibase-component budibase-datasource *.iml +packageNames.txt diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile index d405e8a0af..1ad1f2058b 100644 --- a/hosting/single/Dockerfile +++ b/hosting/single/Dockerfile @@ -10,12 +10,15 @@ COPY package.json . COPY yarn.lock . COPY lerna.json . COPY .yarnrc . +COPY packageNames.txt . + +COPY packages/server/package.json packages/server/package.json +COPY packages/worker/package.json packages/worker/package.json COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh -RUN ./scripts/removeWorkspaceDependencies.sh package.json -RUN ./scripts/removeWorkspaceDependencies.sh packages/server/package.json -RUN ./scripts/removeWorkspaceDependencies.sh packages/worker/package.json +RUN chmod +x ./scripts/removeWorkspaceDependencies.sh +RUN ./scripts/removeWorkspaceDependencies.sh # We will never want to sync pro, but the script is still required @@ -28,8 +31,6 @@ COPY packages/server/dist packages/server/dist COPY packages/server/client packages/server/client COPY packages/worker/dist packages/worker/dist -RUN rm -rf scripts/ - FROM budibase/couchdb as runner ARG TARGETARCH @@ -89,7 +90,16 @@ COPY hosting/single/ssh/sshd_config /etc/ COPY hosting/single/ssh/ssh_setup.sh /tmp RUN /build-target-paths.sh -COPY --from=build /app /app + +# setup letsencrypt certificate +RUN apt-get install -y certbot python3-certbot-nginx +COPY hosting/letsencrypt /app/letsencrypt +RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh + +COPY --from=build /app/node_modules /node_modules +COPY --from=build /app/package.json /package.json +COPY --from=build /app/packages/server /app +COPY --from=build /app/packages/worker /worker EXPOSE 80 @@ -98,10 +108,6 @@ EXPOSE 443 EXPOSE 2222 VOLUME /data -# setup letsencrypt certificate -RUN apt-get install -y certbot python3-certbot-nginx -COPY hosting/letsencrypt /app/letsencrypt -RUN chmod +x /app/letsencrypt/certificate-request.sh /app/letsencrypt/certificate-renew.sh # Remove cached files RUN rm -rf \ /root/.cache \ diff --git a/hosting/single/runner.sh b/hosting/single/runner.sh index 9be1f6ce81..d980202f88 100644 --- a/hosting/single/runner.sh +++ b/hosting/single/runner.sh @@ -70,8 +70,8 @@ fi # Read in the .env file and export the variables for LINE in $(cat ${DATA_DIR}/.env); do export $LINE; done -ln -s ${DATA_DIR}/.env /app/server/.env -ln -s ${DATA_DIR}/.env /app/worker/.env +ln -s ${DATA_DIR}/.env /app/.env +ln -s ${DATA_DIR}/.env /worker/.env # make these directories in runner, incase of mount mkdir -p ${DATA_DIR}/minio chown -R couchdb:couchdb ${DATA_DIR}/couch diff --git a/scripts/build-single-image.sh b/scripts/build-single-image.sh index 56394d0dd7..a9abe8c8da 100755 --- a/scripts/build-single-image.sh +++ b/scripts/build-single-image.sh @@ -1,3 +1,4 @@ #!/bin/bash yarn build --scope @budibase/server --scope @budibase/worker +./scripts/generatePackageNamesFile.sh docker build -f hosting/single/Dockerfile -t budibase:latest . diff --git a/scripts/generatePackageNamesFile.sh b/scripts/generatePackageNamesFile.sh new file mode 100755 index 0000000000..e214efeacc --- /dev/null +++ b/scripts/generatePackageNamesFile.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +workspace_info=$(yarn --silent workspaces info) + +package_names_file="packageNames.txt" + +rm -f $package_names_file + + +packages=$(echo "$workspace_info" | jq -r 'keys[]') +echo "$packages" > $package_names_file diff --git a/scripts/removeWorkspaceDependencies.sh b/scripts/removeWorkspaceDependencies.sh index 7c85040cca..146b4a9ef5 100755 --- a/scripts/removeWorkspaceDependencies.sh +++ b/scripts/removeWorkspaceDependencies.sh @@ -1,22 +1,34 @@ #!/bin/bash - -package_json=$(cat "$1") - root_package_json=$(cat "package.json") +process_package() { + local pkg="$1" + local package_json=$(cat "$pkg/package.json") + local has_changes=false -for workspace_package in $(echo "$root_package_json" | jq -r '.workspaces.packages[]' ); do - package_name=$(cat "$workspace_package/package.json" | jq -r '.name') - has_changes=false + - if echo "$package_json" | jq -e --arg package_name "$package_name" '.dependencies | has($package_name)' > /dev/null; then - - package_json=$(echo "$package_json" | jq "del(.dependencies[\"$package_name\"])") - has_changes=true - fi + while IFS= read -r package_name; do + if echo "$package_json" | jq -e --arg package_name "$package_name" '.dependencies | has($package_name)' > /dev/null; then + package_json=$(echo "$package_json" | jq "del(.dependencies[\"$package_name\"])") + has_changes=true + fi + done < "packageNames.txt" if [ "$has_changes" = true ]; then - echo "$package_json" > "$1" + echo "$package_json" > "$1/package.json" + fi +} + + +for pkg in $(echo "$root_package_json" | jq -r '.workspaces.packages[]' ); do + if [[ "$pkg" == *"*"* ]]; then + # Use find to iterate through immediate subdirectories + find "$pkg" -maxdepth 1 -type d -print | while read -r workspace_package; do + process_package "$workspace_package" + done + else + process_package "$pkg" fi done