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 from source - ethereum #197

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
118 changes: 106 additions & 12 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: "Node-to-docker"
on:
release:
types:
- published
workflow_dispatch:
inputs:
isLatest:
Expand All @@ -8,8 +11,30 @@ on:
required: true

jobs:
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,8 +60,12 @@ 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:
push: true
Expand All @@ -46,7 +75,7 @@ jobs:
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:
push: true
Expand All @@ -59,6 +88,8 @@ jobs:
run: echo ${{ steps.docker_build.outputs.digest }}

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

#Changes packages names
- name: Change common ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/common-ethereum/package.json
rename: '@subql/common-flare'

- name: Change types ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/types/package.json
rename: '@subql/types-flare'

- name: Change node ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/node/package.json
rename: '@subql/node-flare'

#update imports

- name: Update imports to flare
run: ./.github/workflows/scripts/update_flare_imports.sh

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

- name: Debug dockerfile
run: cat ./packages/node/Dockerfile
run: cat ./packages/node/Dockerfile-flare

- name: Build and push flare
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 @@ -98,7 +157,7 @@ jobs:
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Build and push flare
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 @@ -111,7 +170,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 @@ -137,8 +197,12 @@ 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:
push: true
Expand All @@ -148,7 +212,7 @@ jobs:
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:
push: true
Expand All @@ -161,6 +225,8 @@ jobs:
run: echo ${{ steps.docker_build.outputs.digest }}

node-flare-build-push-docker-subquery:
needs: check
if: needs.check.outputs.changes_found == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -186,11 +252,39 @@ jobs:
run: |
sh .github/workflows/scripts/nodeVersion.sh

#Changes packages names
- name: Change common ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/common-ethereum/package.json
rename: '@subql/common-flare'

- name: Change types ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/types/package.json
rename: '@subql/types-flare'

- name: Change node ethereum to flare
uses: jaywcjlove/github-action-package@main
with:
path: packages/node/package.json
rename: '@subql/node-flare'

#update imports

- name: Update imports to flare
run: ./.github/workflows/scripts/update_flare_imports.sh

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

- name: Debug dockerfile
run: cat ./packages/node/Dockerfile
run: cat ./packages/node/Dockerfile-flare

- name: Build and push flare
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 @@ -200,7 +294,7 @@ jobs:
build-args: RELEASE_VERSION=${{ steps.get-node-version.outputs.NODE_VERSION }}

- name: Build and push flare
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-ethereum"]
RUN npm i -g --unsafe-perm @subql/node-ethereum@${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-ethereum/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"]
29 changes: 17 additions & 12 deletions packages/node/Dockerfile-flare
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-flare"]
RUN npm i -g --unsafe-perm @subql/node-flare@${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-flare/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"]