Skip to content

Commit

Permalink
build only node package in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
guplersaxanoid committed Oct 31, 2023
1 parent 5c84df6 commit 46beebc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.github
node_modules
coverage
deploy
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/scripts/replace-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Mapping of paths to package names
declare -A packages
packages["./packages/common"]="@subql/common"
packages["./packages/common-substrate"]="@subql/common-substrate"
packages["./packages/node-core"]="@subql/node-core"
packages["./packages/types-core"]="@subql/types-core"
packages["./packages/types"]="@subql/types"
packages["./packages/utils"]="@subql/utils"
packages["./packages/testing"]="@subql/testing"

# Path to the node package.json
node_package_json="./packages/node/package.json"

# Iterate over each package
for package in ${!packages[@]}
do
# Get the version of the current package
version=$(jq -r '.version' $package/package.json)

# Check if the node package.json file exists
if [[ -f $node_package_json ]]; then
# Replace workspace:* with the actual version in package.json of node, without including the trailing comma
sed -i.bak "s#\"${packages[$package]}\": \"workspace:\*\"#\"${packages[$package]}\": \"$version\"#" $node_package_json
# Remove the backup file
rm "${node_package_json}.bak"
else
echo "Error: $node_package_json does not exist."
exit 1
fi
done
16 changes: 11 additions & 5 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ FROM node:18 as builder
WORKDIR /app
COPY ./ ./

# Copy the replace-versions.sh script
COPY ./.github/workflows/scripts/replace-versions.sh ./replace-versions.sh

RUN npm install -g --force yarn@latest
RUN npm install -g --force typescript@latest

RUN yarn install
RUN yarn build
# Run the replace-versions.sh script
RUN chmod +x ./replace-versions.sh
RUN ./replace-versions.sh

WORKDIR /app/packages/node

RUN yarn pack --filename app.tgz
# Run yarn install and yarn build in the packages/node directory
RUN yarn install
RUN yarn build

RUN yarn pack --filename app.tgz

# Production stage
FROM node:18-alpine
Expand All @@ -21,8 +29,6 @@ ENV TZ utc
RUN apk add --no-cache tini git curl tar

COPY --from=builder /app/packages/node/app.tgz /app.tgz
# Copy the yarn cache directory
COPY --from=builder /app/.yarn /app/.yarn

RUN tar -xzvf /app.tgz --strip 1 && rm /app.tgz

Expand Down

0 comments on commit 46beebc

Please sign in to comment.