Skip to content

Commit

Permalink
move build script to a seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
guplersaxanoid committed Nov 6, 2023
1 parent e6d4d77 commit de65103
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
22 changes: 22 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 @@ -65,6 +67,16 @@ jobs:
- name: build
run: yarn build

- name: Build and push
if: github.event_name == 'push'
uses: docker/build-push-action@v2
with:
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
tags: onfinality/subql-query:dockertest
build-args: RELEASE_VERSION=${{ steps.get-query-version.outputs.QUERY_VERSION }}

- name: Build and push
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
Expand Down Expand Up @@ -121,6 +133,16 @@ jobs:
- name: build
run: yarn build

- name: Build and push
if: github.event_name == 'push'
uses: docker/build-push-action@v2
with:
push: true
platforms: arm64,amd64
file: ./packages/query/Dockerfile
tags: subquerynetwork/subql-query:dockertest
build-args: RELEASE_VERSION=${{ steps.get-query-version.outputs.QUERY_VERSION }}

- name: Build and push
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
Expand Down
20 changes: 5 additions & 15 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@ COPY ./packages ./packages
# Copy tsconfig.json
COPY ./tsconfig.json ./tsconfig.json

# Copy build script and make it executable
COPY ./packages/node/scripts/build.sh ./packages/node/scripts/build.sh
RUN chmod +x ./packages/node/scripts/build.sh

# Install dependencies and build
RUN apk add --no-cache jq && \
npm install -g --force yarn@latest && \
cd packages/node && \
jq -r '.dependencies | to_entries[] | select(.value == "workspace:*") | .key' package.json | while read -r dep; do \
echo "Dep: $dep"; \
cat ../../tsconfig.json; \
directory=$(jq --arg dep $dep -r '.compilerOptions.paths[$dep][0]' ../../tsconfig.json | cut -d'/' -f 2); \
echo "Directory: $directory"; \
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
RUN ./packages/node/scripts/build.sh

# Production stage
FROM node:18-alpine
Expand Down
17 changes: 17 additions & 0 deletions packages/node/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

apk add --no-cache jq
npm install -g --force yarn@latest
cd packages/node

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
17 changes: 5 additions & 12 deletions packages/query/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@ COPY ./packages ./packages
# Copy tsconfig.json
COPY ./tsconfig.json ./tsconfig.json

# Copy build script and make it executable
COPY ./packages/query/scripts/build.sh ./packages/query/scripts/build.sh
RUN chmod +x ./packages/query/scripts/build.sh

# Install dependencies and build
RUN apk add --no-cache jq && \
npm install -g --force yarn@latest && \
cd packages/query && \
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
RUN ./packages/query/scripts/build.sh

# Production stage
FROM node:18-alpine
Expand Down
17 changes: 17 additions & 0 deletions packages/query/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

apk add --no-cache jq
npm install -g --force yarn@latest
cd packages/query

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

0 comments on commit de65103

Please sign in to comment.