Skip to content

Commit

Permalink
[SKIP CI] Fix docker ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Nov 7, 2023
1 parent b21d739 commit 47e69c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
changes_found: ${{ steps.check_changes.outputs.changes_found }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check for package changes and commit message
id: check_changes
run: |
Expand Down
32 changes: 24 additions & 8 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# Build stage
FROM node:18-alpine as builder

# Set working directory
WORKDIR /app
COPY ./packages/node ./
RUN npm install -g --force yarn@latest && \
yarn pack --filename app.tgz && \
rm -rf /root/.npm /root/.cache

# Copy all packages
COPY ./packages ./packages

# Copy tsconfig.json
COPY ./tsconfig.json ./tsconfig.json

# Copy build script
COPY ./scripts/build.sh ./scripts/build.sh

# Install dependencies and build
RUN ./scripts/build.sh packages/node

# Production stage
FROM node:18-alpine
RUN apk add --no-cache tini curl git
COPY --from=builder /app/app.tgz /app.tgz
RUN tar -xzvf /app.tgz --strip 1 && \

# Copy .tgz file from builder
COPY --from=builder /app/packages/node/app.tgz /app.tgz

# Install production dependencies
RUN apk add --no-cache tini curl git && \
tar -xzvf /app.tgz --strip 1 && \
rm /app.tgz && \
yarn install --production && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache

# Set Entry point and command
ENTRYPOINT ["/sbin/tini", "--", "bin/run"]
CMD ["-f","/app"]
CMD ["-f","/app"]
18 changes: 18 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e

apk add --no-cache jq
npm install -g --force yarn@latest
cd "$1"

# Modifies the package.json to replace "workspace:*" versions with actual versions
jq -r '.dependencies | to_entries[] | select(.value == "workspace:*") | .key' package.json | while read -r dep; do
directory=$(jq --arg dep "$dep" -r '.compilerOptions.paths[$dep][0]' ../../tsconfig.json | cut -d'/' -f 2)
version=$(jq --arg directory "$directory" -r '.version' ../"$directory"/package.json)
if [ "$version" != null ]; then
jq --arg dep "$dep" --arg version "$version" -r '.dependencies[$dep] = $version' package.json > package.tmp.json && mv package.tmp.json package.json
fi
done

yarn pack --filename app.tgz
rm -rf /root/.npm /root/.cache
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@subql/common-near": ["packages/common-near/src"],
"@subql/common-near/*": ["packages/common-near/src/*"],
"@subql/types-near": ["packages/types/src"],
"@subql/types-near/*": ["packages/types/src/*"],
"@subql/types-near/*": ["packages/types/src/*"]
},
"skipLibCheck": true
},
Expand Down

0 comments on commit 47e69c3

Please sign in to comment.