Skip to content

Commit

Permalink
FIx docker publish CI (subquery#2145)
Browse files Browse the repository at this point in the history
* fix docker CI

* fix node-docker ci

* add debug logs to docker

* fix trailing comma in tsconfig

* move build script to a seperate file

* test query-docker

* debug query-docker

* add context to query-docker

* debug query-docker

* remove debug logs

* Dedupe script, make executable and run through shellcheck

* Add comment

---------

Co-authored-by: Scott Twiname <[email protected]>
  • Loading branch information
guplersaxanoid and stwiname authored Nov 6, 2023
1 parent 17ae093 commit 94ddf7a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 19 deletions.
5 changes: 3 additions & 2 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 Expand Up @@ -65,7 +67,6 @@ jobs:
- run: yarn
- name: build
run: yarn build


- name: Build and push
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
Expand All @@ -75,7 +76,7 @@ jobs:
push: true
platforms: arm64,amd64
file: ./packages/node/Dockerfile
tags: onfinality/subql-node
tags: onfinality/subql-node:v${{ steps.get-node-version.outputs.NODE_VERSION }}
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Build and push
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/query-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 Expand Up @@ -69,6 +71,7 @@ jobs:
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
Expand All @@ -79,6 +82,7 @@ jobs:
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
Expand Down Expand Up @@ -125,6 +129,7 @@ jobs:
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
Expand All @@ -135,6 +140,7 @@ jobs:
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
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"]
32 changes: 24 additions & 8 deletions packages/query/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/query ./
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/query

# Production stage
FROM node:18-alpine
RUN apk add --no-cache tini
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/query/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 @@ -43,7 +43,7 @@
{"path": "packages/node-core"},
{"path": "packages/types-core"},
{"path": "packages/types"},
{"path": "packages/utils"},
{"path": "packages/utils"}
],
"include": ["packages/**/*"],
"exclude": ["**/node_modules/**"],
Expand Down

0 comments on commit 94ddf7a

Please sign in to comment.