Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dev dependencies removed in docker build #1742

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docker/rpc-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ COPY ./package.json ./package.json
COPY ./turbo.json ./turbo.json
COPY ./yarn.lock ./yarn.lock
COPY ./tsconfig.json ./tsconfig.json
COPY ./docker/rpc-proxy/adjust-packages.sh ./adjust-packages.sh

# Install all the dependencies and build the app
RUN yarn install && yarn build

# Clean the package.json files ready for production
RUN apk add --no-cache jq
RUN chmod +x ./adjust-packages.sh
RUN /bin/sh ./adjust-packages.sh ./

# Stage 2: Serve the app using node
FROM node:20.17.0-alpine3.20 AS runner

Expand Down
48 changes: 48 additions & 0 deletions docker/rpc-proxy/adjust-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# -----------------------------------------------------------------------------
# Info:
# - input: directory to search for package.json files
# - output:
# package.json without devDependencies section
# package.json without version selectors in dependencies
# -----------------------------------------------------------------------------

# Check if the search directory is provided
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-directory>"
exit 1
fi
SEARCH_DIR="$1"

# Check if the search directory exists
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: Directory '$SEARCH_DIR' not found."
exit 1
fi
claytonneal marked this conversation as resolved.
Show resolved Hide resolved


# Find all package.json files in the specified directory (excluding node_modules)
find "$SEARCH_DIR" -type f -name "package.json" ! -path "*/node_modules/*" | while read PACKAGE_JSON; do
echo "Processing: $PACKAGE_JSON"


# Remove the "devDependencies" section and overwrite the file
if jq -e '.devDependencies' "$PACKAGE_JSON" > /dev/null; then
jq 'del(.devDependencies)' "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
echo "devDependencies removed from $PACKAGE_JSON"
else
echo "No devDependencies section found in $PACKAGE_JSON. No changes made."
fi

# Remove version selectors from dependencies
# Check if the dependencies section exists in the package.json file
if jq -e '.dependencies' "$PACKAGE_JSON" > /dev/null; then
# Remove version selectors from dependencies
jq '(.dependencies |= with_entries(.value |= ltrimstr("^") | ltrimstr("~")))' "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
echo "Version selectors (caret/tilde) removed from dependencies in $PACKAGE_JSON"
else
echo "No dependencies section found in $PACKAGE_JSON. No changes made."
fi

done
claytonneal marked this conversation as resolved.
Show resolved Hide resolved
Loading