From 0b137c584ef3b5f7f6986a3a98d84712220cfab0 Mon Sep 17 00:00:00 2001 From: Jay Ji Date: Tue, 7 Nov 2023 14:33:55 +1300 Subject: [PATCH] [SKIP CI] Fix docker ci (#86) --- .github/workflows/node-docker.yml | 2 ++ packages/node/Dockerfile | 32 +++++++++++++++++++++++-------- scripts/build.sh | 18 +++++++++++++++++ tsconfig.json | 2 +- 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 scripts/build.sh diff --git a/.github/workflows/node-docker.yml b/.github/workflows/node-docker.yml index 438280ca..e9a0d85c 100644 --- a/.github/workflows/node-docker.yml +++ b/.github/workflows/node-docker.yml @@ -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: | diff --git a/packages/node/Dockerfile b/packages/node/Dockerfile index 6e68ca1f..50d71e90 100644 --- a/packages/node/Dockerfile +++ b/packages/node/Dockerfile @@ -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"] \ No newline at end of file +CMD ["-f","/app"] diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 00000000..9ae89ba1 --- /dev/null +++ b/scripts/build.sh @@ -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 diff --git a/tsconfig.json b/tsconfig.json index 34d79257..508757bc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,7 +28,7 @@ "references": [ {"path": "packages/common-algorand"}, {"path": "packages/node"}, - {"path": "packages/types"}, + {"path": "packages/types"} ], "include": ["packages/**/*"], "exclude": ["**/node_modules/**"],