From 66acc82e0b6d8350b2873806f8985e7f3f11da65 Mon Sep 17 00:00:00 2001 From: Naveen V Date: Wed, 1 Nov 2023 06:28:11 +0000 Subject: [PATCH] update docker to build from source --- .github/workflows/node-docker.yml | 48 +++++++++++++++++++++++++++---- packages/node/Dockerfile | 29 +++++++++++-------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/.github/workflows/node-docker.yml b/.github/workflows/node-docker.yml index a05210db..438280ca 100644 --- a/.github/workflows/node-docker.yml +++ b/.github/workflows/node-docker.yml @@ -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 @@ -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 @@ -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 @@ -59,6 +89,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: @@ -85,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 @@ -96,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 diff --git a/packages/node/Dockerfile b/packages/node/Dockerfile index 120dad14..6e68ca1f 100644 --- a/packages/node/Dockerfile +++ b/packages/node/Dockerfile @@ -1,14 +1,19 @@ -# production images -FROM node:18 as builder -ARG RELEASE_VERSION -ENTRYPOINT ["subql-node-algorand"] -RUN npm i -g --unsafe-perm @subql/node-algorand@${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-algorand/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"] \ No newline at end of file