Skip to content

Commit

Permalink
update docker to build from source (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
guplersaxanoid authored Nov 2, 2023
1 parent 047f300 commit f44cc52
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
49 changes: 42 additions & 7 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
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:
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:
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/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 +76,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 @@ -60,7 +90,8 @@ jobs:


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 @@ -86,8 +117,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 @@ -97,7 +132,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 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-near"]
RUN npm i -g --unsafe-perm @subql/node-near@${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-near/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"]

0 comments on commit f44cc52

Please sign in to comment.