Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build docker image from source #2124

Merged
merged 36 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
90b21b8
build docker image from source
guplersaxanoid Oct 25, 2023
d5791e9
copy necessary build directories to docker
guplersaxanoid Oct 26, 2023
05e0236
add test tag to docker image
guplersaxanoid Oct 26, 2023
c5af34b
add push trigger to test docker image publish
guplersaxanoid Oct 26, 2023
b10adca
node-docker bug fix
guplersaxanoid Oct 26, 2023
be58c87
fix version replace job
guplersaxanoid Oct 26, 2023
ebe64b7
fix replace-version script call step
guplersaxanoid Oct 26, 2023
08895cb
fix replace-versions script
guplersaxanoid Oct 26, 2023
2180edb
fix dockerfile
guplersaxanoid Oct 26, 2023
29e760b
fix replace-versions.sh
guplersaxanoid Oct 26, 2023
02ba011
debug replace-versions
guplersaxanoid Oct 26, 2023
b6b86fe
fix replace-versions
guplersaxanoid Oct 27, 2023
0ef8cdf
debug replace-versions.sh
guplersaxanoid Oct 27, 2023
9ead7f5
fix replace-versions.sh
guplersaxanoid Oct 27, 2023
e0a96a0
debug node-docker CI
guplersaxanoid Oct 27, 2023
46558bb
fix node-docker CI
guplersaxanoid Oct 27, 2023
ad7c770
fix subquerynetwork docker publish jon
guplersaxanoid Oct 27, 2023
fa6b013
pack npm package before copying to docker
guplersaxanoid Oct 30, 2023
dc1859d
fix typo in docker
guplersaxanoid Oct 30, 2023
1f17d2b
remove debug setup in ci
guplersaxanoid Oct 30, 2023
4b9335f
update docker to build from root of workspace
guplersaxanoid Oct 31, 2023
443d96c
cleanup node-docker workflow
guplersaxanoid Oct 31, 2023
039b61c
run production install inside docker
guplersaxanoid Oct 31, 2023
f251e0b
docker optimize production dependency install
guplersaxanoid Oct 31, 2023
5297d96
copy yarn cache to production
guplersaxanoid Oct 31, 2023
5c84df6
copy yarn cache to production
guplersaxanoid Oct 31, 2023
46beebc
build only node package in docker
guplersaxanoid Oct 31, 2023
0d28f2a
fix dockerfile to use replace-versions.sh
guplersaxanoid Oct 31, 2023
339ce28
install deps and build outside docker
guplersaxanoid Oct 31, 2023
00ac3a5
code cleanup
guplersaxanoid Oct 31, 2023
4e5a0ff
code cleanup
guplersaxanoid Oct 31, 2023
ab1215b
optimize docker image size
guplersaxanoid Oct 31, 2023
4551d92
check for node release before publishing docker
guplersaxanoid Nov 1, 2023
56f971d
update query-to-docker CI
guplersaxanoid Nov 1, 2023
516b570
install curl in node-docker
guplersaxanoid Nov 1, 2023
7e6baae
install git in node-docker
guplersaxanoid Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
name: "Node-to-docker"
on:
release:
types:
- published
workflow_dispatch:
inputs:
isLatest:
description: 'Add latest tag'
default: 'true'
require: true
required: true

jobs:
node-build-push-docker-onfinality:
check:
runs-on: ubuntu-latest
outputs:
changes_found: ${{ steps.check_changes.outputs.changes_found }}
steps:
- uses: actions/checkout@v2
- name: Check for package changes and commit message
id: check_changes
run: |
if [[ "${{ github.event_name }}" == "release" ]]
then
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
if [[ $COMMIT_MESSAGE == "[release]"* ]] && git diff --name-only HEAD~1 HEAD -- './packages/node/package.json'
then
echo "::set-output name=changes_found::true"
else
echo "::set-output name=changes_found::false"
fi
else
echo "::set-output name=changes_found::true"
fi


node-build-push-docker-onfinality:
needs: check
if: needs.check.outputs.changes_found == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -35,20 +62,27 @@ jobs:
run: |
sh .github/workflows/scripts/nodeVersion.sh

- run: yarn
- name: build
run: yarn build


- name: Build and push
if: github.event.inputs.isLatest == 'false'
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/node/Dockerfile
tags: onfinality/subql-node:v${{ steps.get-node-version.outputs.NODE_VERSION }}
tags: onfinality/subql-node
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Build and push
if: github.event.inputs.isLatest == 'true'
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/node/Dockerfile
Expand All @@ -59,7 +93,8 @@ jobs:
run: echo ${{ steps.docker_build.outputs.digest }}

node-build-push-docker-subquery:

needs: check
if: needs.check.outputs.changes_found == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -85,25 +120,29 @@ jobs:
run: |
sh .github/workflows/scripts/nodeVersion.sh

- run: yarn
- name: build
run: yarn build

- name: Build and push
if: github.event.inputs.isLatest == 'false'
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/node/Dockerfile
tags: subquerynetwork/subql-node-substrate:v${{ steps.get-node-version.outputs.NODE_VERSION }},
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}
tags: subquerynetwork/subql-node-substrate,

- name: Build and push
if: github.event.inputs.isLatest == 'true'
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/node/Dockerfile
tags: subquerynetwork/subql-node-substrate:v${{ steps.get-node-version.outputs.NODE_VERSION }},subquerynetwork/subql-node-substrate:latest
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Expand Down
49 changes: 42 additions & 7 deletions .github/workflows/query-docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
name: "Query-to-docker"
on:
release:
types:
- published
workflow_dispatch:
inputs:
isLatest:
description: 'Add latest tag'
default: 'true'
require: true
required: true

jobs:
query-build-push-docker:
check:
runs-on: ubuntu-latest
outputs:
changes_found: ${{ steps.check_changes.outputs.changes_found }}
steps:
- uses: actions/checkout@v2
- name: Check for package changes and commit message
id: check_changes
run: |
if [[ "${{ github.event_name }}" == "release" ]]
then
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
if [[ $COMMIT_MESSAGE == "[release]"* ]] && git diff --name-only HEAD~1 HEAD -- './packages/query/package.json'
then
echo "::set-output name=changes_found::true"
else
echo "::set-output name=changes_found::false"
fi
else
echo "::set-output name=changes_found::true"
fi

query-build-push-docker:
needs: check
if: needs.check.outputs.changes_found == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -35,8 +61,12 @@ jobs:
run: |
sh .github/workflows/scripts/queryVersion.sh

- run: yarn
- name: build
run: yarn build

- name: Build and push
if: github.event.inputs.isLatest == 'false'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
with:
push: true
Expand All @@ -46,7 +76,7 @@ jobs:
build-args: RELEASE_VERSION=${{ steps.get-query-version.outputs.QUERY_VERSION }}

- name: Build and push
if: github.event.inputs.isLatest == 'true'
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
with:
push: true
Expand All @@ -60,7 +90,8 @@ jobs:
run: echo ${{ steps.docker_build.outputs.digest }}

query-build-push-docker-subquery:

needs: check
if: needs.check.outputs.changes_found == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -86,8 +117,12 @@ jobs:
run: |
sh .github/workflows/scripts/queryVersion.sh

- run: yarn
- name: build
run: yarn build

- name: Build and push
if: github.event.inputs.isLatest == 'false'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
with:
push: true
Expand All @@ -97,7 +132,7 @@ jobs:
build-args: RELEASE_VERSION=${{ steps.get-query-version.outputs.QUERY_VERSION }}

- name: Build and push
if: github.event.inputs.isLatest == 'true'
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
with:
push: true
Expand Down
29 changes: 17 additions & 12 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# production images
FROM node:18 as builder
ARG RELEASE_VERSION
ENTRYPOINT ["subql-node"]
RUN npm i -g --unsafe-perm @subql/node@${RELEASE_VERSION}
# Build stage
FROM node:18-alpine as builder
WORKDIR /app
COPY ./packages/node ./
RUN npm install -g --force yarn@latest && \
yarn pack --filename app.tgz && \
rm -rf /root/.npm /root/.cache

# Production stage
FROM node:18-alpine
ENV TZ utc

RUN apk add --no-cache tini git curl
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/lib/node_modules/@subql/node/bin/run"]
CMD ["-f","/app"]
RUN apk add --no-cache tini curl git
COPY --from=builder /app/app.tgz /app.tgz
RUN tar -xzvf /app.tgz --strip 1 && \
rm /app.tgz && \
yarn install --production && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache
ENTRYPOINT ["/sbin/tini", "--", "bin/run"]
CMD ["-f","/app"]
26 changes: 16 additions & 10 deletions packages/query/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# production images
FROM node:18 as builder
ARG RELEASE_VERSION
RUN npm i -g --unsafe-perm @subql/query@${RELEASE_VERSION}
# Build stage
FROM node:18-alpine as builder
WORKDIR /app
COPY ./packages/query ./
RUN npm install -g --force yarn@latest && \
yarn pack --filename app.tgz && \
rm -rf /root/.npm /root/.cache

# Production stage
FROM node:18-alpine
ENV TZ utc

RUN apk add --no-cache tini
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/lib/node_modules/@subql/query/bin/run"]
CMD ["-f","/app"]
COPY --from=builder /app/app.tgz /app.tgz
RUN tar -xzvf /app.tgz --strip 1 && \
rm /app.tgz && \
yarn install --production && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache
ENTRYPOINT ["/sbin/tini", "--", "bin/run"]
CMD ["-f","/app"]
Loading