From 5c6bdadb7342444ceec9fb52f946e0993c449919 Mon Sep 17 00:00:00 2001 From: brixial Date: Wed, 15 Jan 2025 09:07:34 +0000 Subject: [PATCH] adding release and docker file --- .github/ISSUE_TEMPLATE/feature-request.md | 20 --- .github/ISSUE_TEMPLATE/report-bug.md | 21 --- .../pull-request-template.md | 39 ----- .github/workflows/calc.yml | 31 ---- .github/workflows/gitspiegel-trigger.yml | 22 --- .github/workflows/pr.yml | 156 ------------------ .github/workflows/release.yml | 137 +++++++++++++++ .github/workflows/semantic.yml | 27 --- Dockerfile | 40 ++--- 9 files changed, 153 insertions(+), 340 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/feature-request.md delete mode 100644 .github/ISSUE_TEMPLATE/report-bug.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE/pull-request-template.md delete mode 100644 .github/workflows/calc.yml delete mode 100644 .github/workflows/gitspiegel-trigger.yml delete mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/semantic.yml diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md deleted file mode 100644 index 788075d17..000000000 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature Request -about: Request a new feature or request an improvement to an existing feature. -title: "" -labels: Enhancement -assignees: "" ---- - -**Proposed Change or Idea** - -[Describe your request for a new idea/feature or improvement of an existing -feature.] - -**Alternatives** - -[Are there alternative approaches or solutions that you’ve considered?] - -**Additional Information** - -[Add any other details about the feature request here.] diff --git a/.github/ISSUE_TEMPLATE/report-bug.md b/.github/ISSUE_TEMPLATE/report-bug.md deleted file mode 100644 index 881fb1f09..000000000 --- a/.github/ISSUE_TEMPLATE/report-bug.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: Bug Report -about: Report erroneous or unexpected behavior. -title: "" -labels: "" -assignees: "" ---- - -**Description** - -[Please add a clear description of the bug you are encountering, such as any -details about your machine, the file where you think this bug may be, error -messages, screenshots, versions of software used, etc.] - -**Steps to Reproduce** - -[Provide detailed steps for someone else to reproduce your bug.] - -**Expected vs. Actual Behavior** - -[A clear description of what you expected to happen and what actually happened.] diff --git a/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md b/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md deleted file mode 100644 index 03c0c4162..000000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -name: Pull Request -about: Pull Request Template -title: "" -labels: "" -assignees: "" ---- - -Thank you for your Pull Request! - -Before you submit, please check that: - -- [ ] You mentioned a related Issue if this PR related to it, e.g. `Fixes #228` - or `Related #1337`. -- [ ] You added a brief description of the PR, e.g.: - - - What does it do? - - What important points reviewers should know? - -- [ ] You labeled the PR appropriately with the labels listed in the sidebar. -- [ ] PR status, release notes, various implications/requirements. -- [ ] You asked any particular reviewers to review. If you aren't sure, start - with GH suggestions. -- [ ] Your PR adheres to the style guide. - - In particular, mind the maximal line length of 100 (120 in exceptional - circumstances). - - Run `yarn lint`. - - There is no commented code checked in unless necessary. -- [ ] You updated any documentation that may have changed. - -Refer to Substrates’s -[contributing guide](https://github.com/paritytech/substrate/blob/master/docs/CONTRIBUTING.adoc) -or Sidecar API’s -[contributing guide](https://github.com/paritytech/substrate-api-sidecar/tree/master/src/CONTRIBUTING.md) -for details. - -After you've read this notice feel free to remove it. Thank you! - -✄ ----------------------------------------------------------------------------- diff --git a/.github/workflows/calc.yml b/.github/workflows/calc.yml deleted file mode 100644 index c50f4de0a..000000000 --- a/.github/workflows/calc.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: calc - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - name: Cargo test - runs-on: ubuntu-latest - - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - - - name: Rust Cache - uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 - - - name: Cargo test - uses: actions-rs/cargo@v1.0.3 - with: - command: test - args: --manifest-path=calc/Cargo.toml diff --git a/.github/workflows/gitspiegel-trigger.yml b/.github/workflows/gitspiegel-trigger.yml deleted file mode 100644 index dce3aaf2f..000000000 --- a/.github/workflows/gitspiegel-trigger.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: gitspiegel sync - -# This workflow doesn't do anything, it's only use is to trigger "workflow_run" -# webhook, that'll be consumed by gitspiegel -# This way, gitspiegel won't do mirroring, unless this workflow runs, -# and running the workflow is protected by GitHub - -on: - pull_request: - types: - - opened - - synchronize - - unlocked - - ready_for_review - - reopened - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Do nothing - run: echo "let's go" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 8151bbf4f..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,156 +0,0 @@ -name: pr - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - lint: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - name: Checkout files - uses: actions/checkout@v4 - - - name: Install Node v18 - uses: actions/setup-node@v4 - with: - node-version: '18.14' - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install JS dependencies - run: yarn install - - - name: Linter. - run: yarn lint - tests: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - - name: Checkout files - uses: actions/checkout@v4 - - - name: Install Node v18 - uses: actions/setup-node@v4 - with: - node-version: '18.14' - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install JS dependencies - run: yarn install - - - name: Unit tests. - run: yarn test:ci - - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - - name: Checkout files - uses: actions/checkout@v4 - - - name: Install Node v18 - uses: actions/setup-node@v4 - with: - node-version: '18.14' - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install JS dependencies - run: yarn install - - - name: Build - run: yarn build - - build-docs: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - - name: Checkout files - uses: actions/checkout@v4 - - - name: Install Node v18 - uses: actions/setup-node@v4 - with: - node-version: '18.14' - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install JS dependencies - run: yarn install - - - name: Build Docs - run: yarn build:docs - - build-npm-release: - # This test is to make sure sidecar can release a binary without any errors. - # This script does not publish a release, but instead uses yarn to create a tarball and - # install it locally. Once installed a binary is attached to sidecars node_modules, and that - # binary is then tested against. For more in depth information reference the docs at - # `../../scripts/README.md`. - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x] - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - run: yarn - - run: yarn test:test-release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..05e3ef86e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,137 @@ +name: Release + +on: + push: + tags: + - 'v*' + +env: + NODE_VERSION: '20' + DOCKER_IMAGE: "availj/sidecar-api" + SAS_EXPRESS_BIND_HOST: "0.0.0.0" + SAS_EXPRESS_PORT: "8080" + MAINNET_URL: "wss://mainnet-rpc.avail.so/ws" + TESTNET_URL: "wss://turing-rpc.avail.so/ws" + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get version + id: get_version + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + echo "version=${VERSION}" + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Create release archive + run: | + tar -czf release.tar.gz build/ package.json yarn.lock README.md + + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Build and push mainnet image + - name: Build and push Mainnet Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + build-args: | + SAS_EXPRESS_BIND_HOST=${{ env.SAS_EXPRESS_BIND_HOST }} + SAS_EXPRESS_PORT=${{ env.SAS_EXPRESS_PORT }} + SAS_SUBSTRATE_URL=${{ env.MAINNET_URL }} + tags: | + ${{ env.DOCKER_IMAGE }}:latest + ${{ env.DOCKER_IMAGE }}:${{ steps.get_version.outputs.VERSION }}-mainnet + ${{ env.DOCKER_IMAGE }}:mainnet + + # Build and push testnet image + - name: Build and push Testnet Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + build-args: | + SAS_EXPRESS_BIND_HOST=${{ env.SAS_EXPRESS_BIND_HOST }} + SAS_EXPRESS_PORT=${{ env.SAS_EXPRESS_PORT }} + SAS_SUBSTRATE_URL=${{ env.TESTNET_URL }} + tags: | + ${{ env.DOCKER_IMAGE }}:${{ steps.get_version.outputs.VERSION }}-testnet + ${{ env.DOCKER_IMAGE }}:testnet + + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v1 + with: + files: release.tar.gz + body: | + Release ${{ steps.get_version.outputs.VERSION }} + + ## Docker Images + + ### Mainnet + ```bash + # Latest mainnet version + docker pull ${{ env.DOCKER_IMAGE }}:mainnet + # Specific mainnet version + docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.get_version.outputs.VERSION }}-mainnet + ``` + + ### Testnet (Turing) + ```bash + # Latest testnet version + docker pull ${{ env.DOCKER_IMAGE }}:testnet + # Specific testnet version + docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.get_version.outputs.VERSION }}-testnet + ``` + + ## Running the containers + + ### Mainnet + ```bash + docker run -p 8080:8080 ${{ env.DOCKER_IMAGE }}:mainnet + ``` + + ### Testnet + ```bash + docker run -p 8080:8080 ${{ env.DOCKER_IMAGE }}:testnet + ``` + + notify: + needs: [release] + if: always() + runs-on: ubuntu-latest + steps: + - name: Notify on success + if: ${{ needs.release.result == 'success' }} + run: | + echo "Release completed successfully!" + # Add notification logic here if needed (e.g., Slack, Discord, etc.) + + - name: Notify on failure + if: ${{ needs.release.result == 'failure' }} + run: | + echo "Release failed!" + # Add notification logic here if needed diff --git a/.github/workflows/semantic.yml b/.github/workflows/semantic.yml deleted file mode 100644 index c01e94a51..000000000 --- a/.github/workflows/semantic.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: pr-title - -on: - pull_request: - branches: - - master - types: - - opened - - edited - - synchronize - pull_request_target: - types: - - opened - - edited - - synchronize - -jobs: - validate-title: - permissions: - pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs - name: Validate PR Title - runs-on: ubuntu-latest - steps: - - name: semantic-pull-request - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 97cf2ba1d..60672572b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/library/node:18.12.1-alpine as builder +FROM node:20-alpine as builder WORKDIR /opt/builder @@ -9,33 +9,25 @@ RUN yarn install && \ # --------------------------------- -FROM docker.io/library/node:18.12.1-alpine - -# metadata -ARG VERSION="" -ARG VCS_REF=master -ARG BUILD_DATE="" - -LABEL summary="Substrate-api-sidecar." \ - name="parity/substrate-api-sidecar" \ - maintainer="devops-team@parity.io, chevdor@gmail.com" \ - version="${VERSION}" \ - description="Substrate-api-sidecar image." \ - io.parity.image.vendor="Parity Technologies" \ - io.parity.image.source="https://github.com/paritytech/substrate-api-sidecar/blob/\ -${VCS_REF}/Dockerfile" \ - io.parity.image.documentation="https://github.com/paritytech/substrate-api-sidecar/\ -blob/${VCS_REF}/README.md" \ - io.parity.image.revision="${VCS_REF}" \ - io.parity.image.created="${BUILD_DATE}" +FROM node:20-alpine + +# Environment variables with defaults +ARG SAS_EXPRESS_BIND_HOST=0.0.0.0 +ARG SAS_EXPRESS_PORT=8080 +ARG SAS_SUBSTRATE_URL +ARG SAS_SUBSTRATE_TYPES_BUNDLE="/usr/src/app/dataavail.types.json" + +ENV SAS_EXPRESS_BIND_HOST=${SAS_EXPRESS_BIND_HOST} \ + SAS_EXPRESS_PORT=${SAS_EXPRESS_PORT} \ + SAS_SUBSTRATE_URL=${SAS_SUBSTRATE_URL} \ + SAS_SUBSTRATE_TYPES_BUNDLE=${SAS_SUBSTRATE_TYPES_BUNDLE} WORKDIR /usr/src/app +# Copy built files from builder stage COPY --from=builder /opt/builder /usr/src/app -ENV SAS_EXPRESS_PORT=8080 -ENV SAS_EXPRESS_BIND_HOST=0.0.0.0 - USER node EXPOSE ${SAS_EXPRESS_PORT} -CMD [ "node", "build/src/main.js" ] + +CMD ["node", "build/src/main.js"]