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

update docker to build from source - cosmos #198

Merged
merged 1 commit into from
Nov 5, 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
48 changes: 41 additions & 7 deletions .github/workflows/node-cosmos-docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
name: "Node-to-docker"
on:
release:
types:
- published
workflow_dispatch:
inputs:
isLatest:
description: 'Add latest tag'
default: 'true'
require: true
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:

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 @@ -60,7 +89,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 +116,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 +131,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-cosmos"]
RUN npm i -g --unsafe-perm @subql/node-cosmos@${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-cosmos/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"]
Loading