Skip to content

Commit

Permalink
Feat/30 refactor operational packages (#116)
Browse files Browse the repository at this point in the history
* refactor Operational packages

* fix: refactor operations package to use oclif

* adjusting Dockerfile

* adjusting github action

* Update all-tools.yml

Signed-off-by: Andrei A. <andrei.alexandru@consensys.net>

* adjusting github action

---------

Signed-off-by: Andrei A. <andrei.alexandru@consensys.net>
Co-authored-by: VGau <victorien.gauch@consensys.net>
  • Loading branch information
count-sum and VGau authored Oct 2, 2024
1 parent 3675b24 commit e3d2839
Show file tree
Hide file tree
Showing 52 changed files with 3,169 additions and 26,035 deletions.
29 changes: 13 additions & 16 deletions .github/workflows/all-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ on:
branches:
- main
paths:
- 'operations/**'
- 'operations/'
- '.github/workflows/all-tools.yml'
pull_request:
branches:
- main
paths:
- 'operations/**'

env:
DOCKER_IMAGE_NAME: consensys/linea-alltools
- 'operations/'
- '.github/workflows/all-tools.yml'

jobs:
changes:
runs-on: besu-arm64
name: Filter commit changes
outputs:
all-tools: ${{ steps.filter.outputs.all-tools }}
all-tools: ${{ steps.filter.outputs['all-tools'] }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -43,7 +42,7 @@ jobs:
runs-on: besu-arm64
name: Check image tags exist
needs: [ changes, store_image_name_and_tags ]
if: ${{ needs.changes.outputs.all-tools == 'false' }}
if: ${{ needs.changes.outputs['all-tools'] == 'false' }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -52,15 +51,15 @@ jobs:
with:
last_commit_tag: ${{ needs.store_image_name_and_tags.outputs.last_commit_tag }}
common_ancestor_tag: ${{ needs.store_image_name_and_tags.outputs.common_ancestor_tag }}
image_name: ${{ env.DOCKER_IMAGE_NAME }}
image_name: consensys/linea-alltools
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
docker_password: ${{ secrets.DOCKERHUB_TOKEN }}

all-tools-tag-only:
runs-on: besu-arm64
name: All tools tag only
needs: [ changes, store_image_name_and_tags, check_image_tags_exist ]
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs.all-tools == 'false' }}
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs['all-tools'] == 'false' }}
outputs:
image_tagged: ${{ steps.image_tag_push.outputs.image_tagged }}
steps:
Expand All @@ -75,20 +74,20 @@ jobs:
common_ancestor_tag: ${{ needs.store_image_name_and_tags.outputs.common_ancestor_tag }}
develop_tag: ${{ needs.store_image_name_and_tags.outputs.develop_tag }}
untested_tag_suffix: ${{ needs.store_image_name_and_tags.outputs.untested_tag_suffix }}
image_name: ${{ env.DOCKER_IMAGE_NAME }}
image_name: consensys/linea-alltools
last_commit_tag_exists: ${{ needs.check_image_tags_exist.outputs.last_commit_tag_exists }}
common_ancestor_commit_tag_exists: ${{ needs.check_image_tags_exist.outputs.common_ancestor_commit_tag_exists }}
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
docker_password: ${{ secrets.DOCKERHUB_TOKEN }}

build-and-publish:
needs: [ changes, store_image_name_and_tags, all-tools-tag-only ]
if: ${{ always() && (needs.changes.outputs.all-tools == 'true' || needs.all-tools-tag-only.result != 'success' || needs.all-tools-tag-only.outputs.image_tagged != 'true') }}
if: ${{ always() && (needs.changes.outputs['all-tools'] == 'true' || needs.all-tools-tag-only.result != 'success' || needs.all-tools-tag-only.outputs.image_tagged != 'true') }}
runs-on: ubuntu-22.04
env:
COMMIT_TAG: ${{ needs.store_image_name_and_tags.outputs.commit_tag }}
DEVELOP_TAG: ${{ needs.store_image_name_and_tags.outputs.develop_tag }}
IMAGE_NAME: ${{ env.DOCKER_IMAGE_NAME }}
IMAGE_NAME: consensys/linea-alltools
name: All tools build and push
steps:
- name: Checkout
Expand Down Expand Up @@ -116,15 +115,13 @@ jobs:
- name: Show the "version" build argument
run: |
echo "We inject the commit tag in the docker image ${{ env.COMMIT_TAG }}"
echo COMMIT_TAG=${{ env.COMMIT_TAG }} >> $GITHUB_ENV
echo COMMIT_TAG=${{ env.COMMIT_TAG }} >> GITHUB_ENV
- name: Build and push all tools image
uses: docker/build-push-action@v6
with:
context: .
file: ./operations/Dockerfile
platforms: linux/amd64
# Note: Build amd64 image only
# platforms: linux/amd64,linux/arm64
platforms: linux/amd64 # Note: Build amd64 image only
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE_NAME }}:${{ env.COMMIT_TAG }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.run/**.run.xml
.envrc
bin/
!operations/src/synctx/bin/
!operations/bin/
target/
tmp/
build/
Expand Down
2 changes: 1 addition & 1 deletion operations/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
node_modules
src/synctx/
coverage
File renamed without changes.
2 changes: 1 addition & 1 deletion operations/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
node_modules
src/synctx/
coverage
File renamed without changes.
52 changes: 12 additions & 40 deletions operations/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,31 @@
# syntax=docker/dockerfile:1.2
FROM node:18-slim AS builder
FROM node:20-slim AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable

FROM base AS builder

WORKDIR /usr/src/app

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json ./
COPY ./operations/package.json ./operations/package.json

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prefer-offline && npm install -g typescript

COPY . .

RUN rm -rf src/synctx && pnpm run -F operations build

FROM node:18-slim AS builder-synctx

ARG TARGETPLATFORM

WORKDIR /opt/synctx
COPY operations/ ./operations/

COPY ./operations/src/synctx .
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
RUN pnpm run -F operations build
RUN pnpm deploy --filter=./operations --prod ./prod

RUN apt-get update \
&& apt-get install --no-install-recommends -y git xz-utils perl \
&& OCLIF_TARGET=$(echo ${TARGETPLATFORM} | sed 's#/#-#;s#amd64#x64#') \
&& yarn global add oclif && yarn && yarn run build && yarn install --production --ignore-scripts --prefer-offline \
&& git init \
&& git config user.email "sre@consensys.net" \
&& git config user.name "cs-sre" \
&& git commit --allow-empty -m "dummy commit" \
&& oclif pack tarballs --targets="${OCLIF_TARGET}" \
&& tar -xvf dist/synctx-*.tar.gz

FROM node:18-slim AS release
FROM node:20-slim AS release

ENV NODE_ENV=production
ENV PATH="${PATH}:/opt/synctx/bin"

WORKDIR /usr/src/app

# Install pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

COPY package.json pnpm-lock.yaml ./

RUN pnpm install --prod --frozen-lockfile --prefer-offline

COPY --chown=node:node --from=builder /usr/src/app/operations/dist ./dist
COPY --chown=node:node --from=builder-synctx /opt/synctx/synctx /opt/synctx/
USER node

USER node:node
COPY --from=builder /usr/src/app/prod ./

ENTRYPOINT ["node"]
ENTRYPOINT ["./bin/run.js"]
49 changes: 0 additions & 49 deletions operations/Dockerfile.alpine

This file was deleted.

File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions operations/bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning

// eslint-disable-next-line n/shebang
import {execute} from '@oclif/core'

await execute({development: true, dir: import.meta.url})
File renamed without changes.
5 changes: 5 additions & 0 deletions operations/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import {execute} from '@oclif/core'

await execute({dir: import.meta.url})
18 changes: 18 additions & 0 deletions operations/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
testRegex: "test.ts$",
transform: {
"^.+\\.ts$": ["ts-jest", { useESM: true }],
},
verbose: true,
collectCoverage: true,
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: [".ts"],
collectCoverageFrom: ["src/**/*.ts"],
coverageReporters: ["html", "lcov", "text"],
testPathIgnorePatterns: [],
coveragePathIgnorePatterns: [],
};
12 changes: 0 additions & 12 deletions operations/jest.config.js

This file was deleted.

65 changes: 47 additions & 18 deletions operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,56 @@
"author": "Consensys Software Inc.",
"license": "Apache-2.0",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "shx rm -rf dist && tsc -p tsconfig.build.json",
"prettier": "prettier -c '**/*.{js,ts}'",
"prettier:fix": "prettier -w '**/*.{js,ts}'",
"lint:ts": "npx eslint '**/*.{js,ts}'",
"lint:ts:fix": "npx eslint --fix '**/*.{js,ts}'",
"test": "npx jest --bail --detectOpenHandles --forceExit",
"lint:fix": "npm run lint:ts:fix && npm run prettier:fix",
"clean": "rimraf node_modules"
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest --bail --detectOpenHandles --forceExit",
"clean": "rimraf node_modules dist coverage",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "pnpm run lint",
"prepack": "oclif manifest && oclif readme",
"version": "oclif readme && git add README.md"
},
"dependencies": {
"axios": "^1.6.0",
"ethers": "^6.8.1",
"yargs": "^17.7.2"
"@oclif/core": "4.0.23",
"@oclif/plugin-help": "6.2.13",
"@oclif/plugin-plugins": "5.4.10",
"axios": "1.7.7",
"ethers": "6.13.2"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.7",
"@types/yargs": "^17.0.29",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.5",
"ts-jest": "^29.1.1",
"rimraf": "^3.0.2"
}
}
"@jest/globals": "29.7.0",
"@oclif/test": "4.0.9",
"@types/jest": "29.5.13",
"jest": "29.7.0",
"jest-mock-extended": "3.0.5",
"shx": "0.3.4",
"ts-jest": "29.2.5"
},
"engines": {
"node": ">=20"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"bin": {
"operations": "./bin/run.js"
},
"oclif": {
"bin": "operations",
"dirname": "operations",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help",
"@oclif/plugin-plugins"
],
"topicSeparator": " "
},
"files": [
"/bin",
"/dist",
"/oclif.manifest.json"
]
}
Loading

0 comments on commit e3d2839

Please sign in to comment.