-
Notifications
You must be signed in to change notification settings - Fork 1
chore: Container builds #283
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
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
51e6c79
wip: starting migrations on docker build
tuliomir d361a5e
fix: migrations config pathing on script
tuliomir 2736455
feat: dedicated container image for migration
tuliomir 3140ecb
wip: almost working version
tuliomir 67d373f
refactor: changed migration entrypoint
tuliomir 0e1b8c4
wip: deamon container not working properly
tuliomir a75fefb
wip: working Daemon PoC, now needs refinement
tuliomir d37155b
fix: improved variable name for fullnode ids
tuliomir b2d8755
feat: aws mock
tuliomir d816193
fix: nodejs 22
tuliomir c1b64bf
feat: working serverless, worsened daemon build
tuliomir 038f844
fix: lambda mock logger
tuliomir a42f5b1
refactor: Daemon Dockerfile to package folder
tuliomir e1fd96c
docs: adds docs to container-related files
tuliomir e7ec00b
docs: improves comments and removes debug cmds
tuliomir 8ab7033
feat: build-daemon script no longer needs aws
tuliomir 61a0188
feat: migrator image built via makefile
tuliomir fe8b2b2
feat: service image built via makefile
tuliomir f96079b
docs: Notes about image size on the Dockerfiles
tuliomir 453f2fc
docs: images instead of builds on examples
tuliomir 2d8b303
feat: script to run serverless with nodejs debug
tuliomir 09c5e84
fix: removes unused code and fixes logger calls
tuliomir e3afa92
revert: unneeded push notification changes
tuliomir f6e123a
docs: improves fetch-fullnode-ids explanations
tuliomir 712a213
docs: improves complementary envs explanations
tuliomir 8be3a2b
docs: improves dockerized explanations
tuliomir bf3e5f6
test: adds coverage on aws-offline-mock
tuliomir 739542a
refactor: simplifies conditionals
tuliomir bd53f73
fix: type validation on tests
tuliomir 3a46102
fix: aws mock credentials for all tests
tuliomir 6592873
fix: dynamic set of mock_aws
tuliomir c8f5556
chore: removes obsolete comments
tuliomir 39768b8
docs: explanations on MOCK_AWS env var
tuliomir 0d198b5
refactor: configurable complementary envs
tuliomir b581b4a
refactor: uses config instead of env directly
tuliomir 089014b
docs: removes redis as a service dependency
tuliomir 5a5b2bd
refactor: conditionally uses merge script
tuliomir 2d2982a
fix: config validation schema
tuliomir 2bbd9f2
refactor: mock fixtures to the tests folder
tuliomir 6490c5f
docs: fix typo
tuliomir 37a1016
fix: aws utils imports naming
tuliomir aa581a7
fix: redis password conditional
tuliomir df34761
Merge branch 'master' into chore/container-builds
tuliomir 3451eac
refactor: improves docker image naming
tuliomir f6546e2
refactor: renames .env to .sh file
tuliomir 5c80f9d
Merge branch 'master' into chore/container-builds
tuliomir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Copyright 2025 Hathor Labs | ||
| # This software is provided ‘as-is’, without any express or implied | ||
| # warranty. In no event will the authors be held liable for any damages | ||
| # arising from the use of this software. | ||
| # This software cannot be redistributed unless explicitly agreed in writing with the authors. | ||
|
|
||
| # ========================================================================= | ||
| # This Dockerfile is intended for migrating the database of a dockerized private blockchain | ||
| # for the Wallet Service Daemon. | ||
| # | ||
| # It serves only as a means to run the migration scripts in an isolated environment. The container will run only | ||
| # for as long as the migration is running, and then it will exit. | ||
| # | ||
| # The migration scripts do not cause any impact if it is ran multiple times, so it is safe to run this container | ||
| # for each deployment of the Wallet Service Daemon. | ||
| # | ||
| # The expected image size is about 250MB as of v1.9.0 | ||
| # | ||
| # Sample usage in a docker-compose.yml: | ||
| # ws-migrator: | ||
| # image: hathornetwork/hathor-wallet-service-migrator | ||
| # restart: "no" # Critical: don't restart migration service | ||
| # depends_on: | ||
| # mysql: # Replace with your actual mysql service name | ||
| # condition: service_healthy | ||
| # environment: | ||
| # DB_ENDPOINT: "mysql" | ||
| # DB_NAME: "wallet_service" | ||
| # DB_USER: "wallet_service_user" | ||
| # DB_PASS: "password" | ||
| # DB_PORT: 3306 | ||
| # networks: | ||
| # - hathor-privnet | ||
|
|
||
| # This Dockerfile is used to build and run the database migration container. | ||
| FROM node:22-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy only the necessary files for the migration | ||
| COPY ./db ./db | ||
| COPY ./db/migrations ./migrations | ||
|
|
||
| # This will install only the exact versions of sequelize, sequelize-cli and mysql2 | ||
| # that are already in use in the project, avoiding any unwanted upgrades. | ||
| # It will also install the dotenv package, but it's not as critical and we can use the latest version. | ||
| # | ||
| # Note that this migrator container does not need to have all the dependencies of the main project, | ||
| # as it will only be used to run the migration scripts. For this, a new package.json is created | ||
| # with only the necessary dependencies, reducing image size. | ||
|
|
||
| ARG SEQUELIZE_VERSION | ||
| ARG SEQUELIZE_CLI_VERSION | ||
| ARG MYSQL2_VERSION | ||
| RUN test -n "$SEQUELIZE_VERSION" \ | ||
| && test -n "$SEQUELIZE_CLI_VERSION" \ | ||
| || (echo "Both SEQUELIZE_VERSION and SEQUELIZE_CLI_VERSION must be set" && exit 1) | ||
| # Avoids potential conflicts with pre-installed v1.x versions of yarn | ||
| RUN npm uninstall -g yarn | ||
| RUN corepack enable | ||
| RUN echo '{"name": "migrator", "private": true}' > package.json | ||
| RUN yarn add sequelize@"$SEQUELIZE_VERSION" sequelize-cli@"$SEQUELIZE_CLI_VERSION" mysql2@"$MYSQL2_VERSION" dotenv | ||
|
|
||
| # Run the migration scripts | ||
| RUN cp /app/db/migration-entrypoint.sh /app; | ||
| ENTRYPOINT ["/bin/sh", "/app/migration-entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # Run the migration script. | ||
| # Note that this is supposed to run from the root of the repository, inside a container | ||
| corepack enable | ||
| yarn sequelize db:migrate --config db/config.js | ||
|
|
||
| # Run the command passed to the entrypoint (if any). | ||
| exec "$@" |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright 2024 Hathor Labs | ||
| # This software is provided ‘as-is’, without any express or implied | ||
| # warranty. In no event will the authors be held liable for any damages | ||
| # arising from the use of this software. | ||
| # This software cannot be redistributed unless explicitly agreed in writing with the authors. | ||
|
|
||
| # ========================================================================= | ||
| # This Dockerfile is used to build and run the Wallet Service Daemon container. | ||
| # It requires: | ||
| # - A MySQL instance, properly migrated ( see /db/Dockerfile ) | ||
| # - A Fullnode instance | ||
| # - A Redis instance | ||
| # | ||
| # The expected image size is about 500MB as of v1.9.0 | ||
| # | ||
| # See the HathorNetwork / Wallet Lib repository for a live example on how to use this Dockerfile, but in short: | ||
| # ws-daemon: | ||
| # image: hathornetwork/hathor-wallet-service-sync-daemon | ||
| # depends_on: | ||
| # ws-migrator: | ||
| # condition: service_completed_successfully | ||
| # fullnode: | ||
| # condition: service_healthy | ||
| # mysql: | ||
| # condition: service_healthy | ||
| # environment: | ||
| # ... | ||
| # ports: | ||
| # - "8081:8081" | ||
| # - "8082:8082" | ||
| # networks: | ||
| # - hathor-privnet | ||
|
|
||
| # Build phase | ||
| FROM node:22-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN apk update && apk add python3 g++ make py3-setuptools | ||
|
|
||
| COPY . . | ||
|
|
||
| # corepack will use the version of yarn specified in package.json | ||
| RUN corepack enable | ||
|
|
||
| # This will install dependencies for all packages, except for the lambdas since | ||
| # they are ignored in .dockerignore | ||
| RUN yarn install | ||
|
|
||
| RUN yarn workspace sync-daemon run build | ||
|
|
||
| # This will remove all dev dependencies and install production deps only | ||
| RUN yarn workspaces focus -A --production | ||
|
|
||
| # Run phase | ||
| FROM node:22-alpine AS dev | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy only the necessary files from the build phase | ||
| COPY --from=builder /app . | ||
|
|
||
| WORKDIR /app/packages/daemon/ | ||
|
|
||
| # The script should already be available from the builder stage copy | ||
| RUN cp /app/scripts/fetch-fullnode-ids.js ./fetch-fullnode-ids.js | ||
| RUN cp /app/scripts/merge-complementary-envs.sh ./merge-complementary-envs.sh | ||
| RUN chmod +x ./merge-complementary-envs.sh | ||
|
tuliomir marked this conversation as resolved.
|
||
|
|
||
| # The daemon could need complementary environment variables dynamically. | ||
| # The entrypoint script manages this before actually running the daemon. | ||
| ENTRYPOINT ["./merge-complementary-envs.sh"] | ||
|
|
||
| FROM node:22-alpine AS prod | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy only the necessary files from the build phase | ||
| COPY --from=builder /app . | ||
|
|
||
| WORKDIR /app/packages/daemon/ | ||
|
|
||
| CMD ["node", "dist/index.js"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| dist/ | ||
| __tests__/ | ||
| .git/ | ||
| ../../.github/ | ||
| .direnv/ | ||
| flake.* | ||
| node_modules/ | ||
| packages/daemon | ||
| packages/wallet-service/dist/ | ||
| packages/wallet-service/node_modules/ | ||
| packages/common/node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22 |
|
tuliomir marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2025 Hathor Labs | ||
| # This software is provided 'as-is', without any express or implied | ||
| # warranty. In no event will the authors be held liable for any damages | ||
| # arising from the use of this software. | ||
| # This software cannot be redistributed unless explicitly agreed in writing with the authors. | ||
|
|
||
| # ========================================================================= | ||
| # This Dockerfile is used to build and run the Wallet Service container. | ||
| # It requires: | ||
| # - A MySQL instance, properly migrated ( see /db/Dockerfile ) | ||
| # - A Fullnode instance | ||
| # - A started Wallet Service Daemon instance ( see /packages/daemon/Dockerfile ) | ||
| # | ||
| # The expected image size is about 1800MB as of v1.9.0. This is because `serverless` is a development | ||
| # dependency and needs to be installed in the final image, reducing the optimization options for | ||
| # reducing this size. | ||
| # | ||
| # To properly connect to a dockerized private network, in the environment variables, you should set `MOCK_AWS=true` | ||
| # to avoid trying to connect to external AWS services, except if the container is being run connected to a publicly | ||
| # available network. | ||
| # | ||
| # See the HathorNetwork / Wallet Lib repository for a live example on how to use this Dockerfile, but in short: | ||
| # ws-serverless: | ||
| # image: hathornetwork/hathor-wallet-service-service | ||
| # depends_on: | ||
| # fullnode: | ||
| # condition: service_healthy | ||
| # mysql: | ||
| # condition: service_healthy | ||
| # ws-daemon: | ||
| # condition: service_started | ||
| # environment: | ||
| # IS_OFFLINE: true | ||
| # ENV MOCK_AWS=true # Necessary to avoid trying to connect to external AWS services | ||
| # ... | ||
| # ports: | ||
| # - "3000:3000" | ||
| # - "3001:3001" | ||
| # networks: | ||
| # - hathor-privnet | ||
|
|
||
| # Build stage | ||
| FROM node:22-alpine | ||
|
|
||
| # Install system dependencies needed for native modules | ||
| RUN apk add --no-cache \ | ||
| python3 \ | ||
| g++ \ | ||
| make \ | ||
| py3-setuptools \ | ||
| git | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy root package files | ||
| COPY . . | ||
|
|
||
| # Enable corepack for yarn | ||
| RUN corepack enable | ||
| RUN yarn install | ||
|
|
||
| WORKDIR /app/packages/wallet-service | ||
|
|
||
| # Expose serverless-offline default port | ||
| EXPOSE 3000 | ||
| # Expose websocket port | ||
| EXPOSE 3001 | ||
|
|
||
| RUN chmod +x ./entrypoint.sh | ||
|
|
||
| # Run serverless offline | ||
| ENTRYPOINT ["./entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
|
|
||
| # When MOCK_AWS is set to true, copy the mocked AWS credentials fixtures to .aws in the working directory | ||
| if [ "$MOCK_AWS" = "true" ]; then | ||
| cp -r tests/fixtures/aws ./.aws | ||
| fi | ||
|
|
||
| yarn serverless offline start --host 0.0.0.0 --httpPort 3000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,11 @@ | |
| "lint": "eslint src/ tests/ --ext .js,.jsx,.ts,.tsx src tests", | ||
| "lint-fix": "eslint src/ tests/ --fix --ext .js,.jsx,.ts,.tsx src tests", | ||
| "check-types": "tsc --noemit --skipLibCheck", | ||
| "test": "jest" | ||
| "test": "jest", | ||
| "debug:offline": "node --inspect-brk ./node_modules/.bin/serverless offline start --host 0.0.0.0 --httpPort 3000" | ||
| }, | ||
| "engines": { | ||
| "node": "22" | ||
| }, | ||
| "author": "Hathor Labs", | ||
| "license": "MIT", | ||
|
|
@@ -64,7 +68,7 @@ | |
| "serverless-api-gateway-throttling": "2.0.3", | ||
| "serverless-better-credentials": "2.0.0", | ||
| "serverless-iam-roles-per-function": "3.2.0", | ||
| "serverless-offline": "13.1.2", | ||
| "serverless-offline": "14.4.0", | ||
|
Comment on lines
-67
to
+71
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old dependency wasn't compatible with NodeJS 22 and had to be upgraded. |
||
| "serverless-plugin-aws-alerts": "1.7.5", | ||
| "serverless-plugin-monorepo": "0.11.0", | ||
| "serverless-plugin-warmup": "8.2.1", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.