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

chore: OpenAPI spec changes & other support for running localenv in docker windows #2530

Merged
merged 44 commits into from
Mar 19, 2024

Conversation

mkurapov
Copy link
Contributor

@mkurapov mkurapov commented Mar 12, 2024

Changes proposed in this pull request

  • Update how we handle OpenAPI specs in the repo
  • Remove the BEFORE_MERGED variable from our localenv:compose commands
  • Add doc section to local playground overview with known issues

Context

This PR makes localenv work inside docker for windows (whether that's through hyper-v or WSL).

Symlinked Schemas

The main issue that prevented this working previously were the symlinked OpenAPI schemas (in packages/*/src/openapi) that docker for windows couldn't copy over as a proper file when creating the docker images.
This led me down the road to a bigger refactor of how we were handling OpenAPI specs in the repo in general.

Usually, we used the fetch-schemas script to pull the latest OpenAPI schemas into the root openapi folder, where we would from there, symlink to them from packages/(backend | auth | token-introspection)/src/openapi. We needed to do that for:

  1. Creating OpenAPI validators with (eg):
await createOpenAPI(
   path.resolve(__dirname, './openapi/resource-server.yaml')
)
  1. Being able to have references to the schemas, so we could reference components in auth-server.yaml, for example, how we do in token-introspection.yaml:
    access:
    $ref: ./auth-server.yaml#/components/schemas/access

The first "problem" was solved by being able to directly import the OpenAPI objects from the updated open-payments library:

allowing us to do validation as such:

container.singleton('openApi', async () => {
const resourceServerSpec = await getResourceServerOpenAPI()
const walletAddressServerSpec = await getWalletAddressServerOpenAPI()
return {
resourceServerSpec,
walletAddressServerSpec
}
})

This is handy because it allows us to remove the fetch-schemas script, and it means that the spec in the open payments client we use in the repo will always be consistent with the spec that we validate against when checking the Open Payment API requests and responses.

However, this didn't fully solve the issue 2: how can we still have references to the yaml files such that we could extend them in our other OpenAPI files (namely, token-introspection.yaml and id-provided.yaml, which both reference the auth-server.yaml & shared schemas.yaml?

This was a bit tricky, and maybe there is a better solution, but this ends up working by using a postinstall command, that copies over the bundled yaml files in the node_modules/@interledger/open-payments/...folder into the respective (auth | token-introspection)/src/openapi/specs folder when doing pnpm install:

"copy-op-schemas": "cp ./node_modules/@interledger/open-payments/dist/openapi/specs/auth-server.yaml ./node_modules/@interledger/open-payments/dist/openapi/specs/schemas.yaml ./src/openapi/specs/",
"generate:types": "openapi-typescript ../../openapi/token-introspection.yaml --output src/openapi/generated/types.ts -t",
"postinstall":"pnpm copy-op-schemas",

Since this ends up being kind of a generated file, we should .gitignore them:

rafiki/.gitignore

Lines 60 to 64 in aa55604

# Open Payments schemas
packages/**/src/openapi/specs/schemas.yaml
packages/**/src/openapi/specs/auth-server.yaml
packages/**/src/openapi/specs/resource-server.yaml
packages/**/src/openapi/specs/wallet-address-server.yaml

Question

Related to a suggestion from @BlairCurrey: should we have a sibling openapi package in the repo that basically holds all of our OpenAPI yaml files, such that we can export and use the the OpenAPI validators in backend and auth all from
one spot?
This way, we can just do this postinstall command in one place to get the Open Payments specs. The downsides of this: the files that backend and auth use separately are not in their corresponding repos and we would need to reference this package when generating the TS types for the token-introspection package.

Other issues

Other issues that prevented running localenv in windows docker were:

  • the pnpm localenv:compose commands do not work because of the BEFORE_MERGED variable usage
    • this was fixed just by writing out the commands in-line
  • the tigerbeetle container was killed upon startup:
    • this was actually a documented issue , and its fixed just by increasing the available RAM in the VM. I added documentation for this.

Fixes #1562

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass
  • Bruno collection updated

@github-actions github-actions bot added pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. type: source Changes business logic pkg: auth Changes in the GNAP auth package. pkg: mock-ase labels Mar 12, 2024
Copy link

netlify bot commented Mar 12, 2024

Deploy Preview for brilliant-pasca-3e80ec ready!

Name Link
🔨 Latest commit d7d597b
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/65f9a9004361cd000869f00e
😎 Deploy Preview https://deploy-preview-2530--brilliant-pasca-3e80ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added pkg: documentation Changes in the documentation package. type: documentation (archived) Improvements or additions to documentation labels Mar 15, 2024
@mkurapov mkurapov marked this pull request as ready for review March 15, 2024 12:41
@github-actions github-actions bot added the type: localenv Local playground label Mar 15, 2024
Comment on lines -10 to -13
RUN apk add --no-cache \
python3 \
make \
g++
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was breaking on windows, and looks like not needed in general

Copy link
Contributor

@BlairCurrey BlairCurrey Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raducristianpopa specified in the original pr that this is for node-gyp. #1795 (comment) Could node-gyp be included with pnpm? It's liable to be used by some of our packages and its hard to say what. I did remove from backend and start localenv OK FWIW. Looks like npm does include an internal version (so maybe pnpm does too), although im not clear on if this would be available to packages: https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md#updating-the-npm-bundled-version-of-node-gyp

Copy link
Member

@raducristianpopa raducristianpopa Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a dependency chain within testcontainers that needed these packages (Python, C/C++ compiler) and I was following their requirements. I recall discussing with Max about this some time ago and it was working for me without installing them at that time.

@@ -0,0 +1,116 @@
openapi: 3.1.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no changes, just moved under openapi/specs folder

@BlairCurrey
Copy link
Contributor

BlairCurrey commented Mar 18, 2024

noticed when trying to setup on windows that pnpm -r build (in README.md docs) fails (see it on mac too). Looks like the spec dir gets created by token-introspection then fails when we try to do it again:

blaircurrey@blairs-MacBook-Pro-2 rafiki % pnpm -r build
Scope: 6 of 7 workspace projects
localenv/mock-account-servicing-entity build$ remix build
│ [info] building... (NODE_ENV=production)
│ [info] built (340ms)
└─ Done in 2.3s
packages/token-introspection build$ pnpm clean && tsc --build tsconfig.json && pnpm copy-files
│ > token-introspection@ clean /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > rm -fr dist/
│ > token-introspection@ copy-files /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > mkdir ./dist/openapi/specs && cp -r ./src/openapi/specs/*.yaml ./dist/openapi/specs/
└─ Done in 1.1s
packages/frontend build$ remix build
│ [info] building... (NODE_ENV=production)
│ [info] built (770ms)
└─ Done in 2.3s
packages/auth build$ pnpm build:deps && pnpm clean && tsc --build tsconfig.json && pnpm copy-files
│ > auth@ build:deps /Users/blaircurrey/code/interledger/rafiki/packages/auth
│ > pnpm --filter token-introspection build
│ > token-introspection@ build /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > pnpm clean && tsc --build tsconfig.json && pnpm copy-files
│ > token-introspection@ clean /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > rm -fr dist/
│ > token-introspection@ copy-files /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > mkdir ./dist/openapi/specs && cp -r ./src/openapi/specs/*.yaml ./dist/openapi/specs/
│ mkdir: ./dist/openapi/specs: File exists
│  ELIFECYCLE  Command failed with exit code 1.
│ /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection:
│  ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  token-introspection@ build: `pnpm clean && tsc --build tsconfig.json && pnpm copy-files`
│ Exit status 1
│  ELIFECYCLE  Command failed with exit code 1.
└─ Failed in 1.5s at /Users/blaircurrey/code/interledger/rafiki/packages/auth
packages/backend build$ pnpm build:deps && pnpm clean && tsc --build tsconfig.json && pnpm copy-files
│ > backend@ build:deps /Users/blaircurrey/code/interledger/rafiki/packages/backend
│ > pnpm --filter token-introspection build
│ > token-introspection@ build /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > pnpm clean && tsc --build tsconfig.json && pnpm copy-files
│ > token-introspection@ clean /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > rm -fr dist/
│ > token-introspection@ copy-files /Users/blaircurrey/code/interledger/rafiki/packages/token-introspection
│ > mkdir ./dist/openapi/specs && cp -r ./src/openapi/specs/*.yaml ./dist/openapi/specs/
└─ Running...
/Users/blaircurrey/code/interledger/rafiki/packages/auth:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  auth@ build: `pnpm build:deps && pnpm clean && tsc --build tsconfig.json && pnpm copy-files`
Exit status 1

See mkdir: ./dist/openapi/specs: File exists in auth build

@mkurapov
Copy link
Contributor Author

@BlairCurrey got it, thanks! Updated the mkdir command

Copy link
Member

@sabineschaller sabineschaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something in the docs that talks about when to run the postinstall?

@mkurapov
Copy link
Contributor Author

@sabineschaller

Is there something in the docs that talks about when to run the postinstall?

postinstall runs automatically after every pnpm i: https://docs.npmjs.com/cli/v10/using-npm/scripts#life-cycle-operation-order

@sabineschaller
Copy link
Member

Of course 🤦‍♀️

@mkurapov mkurapov merged commit f089930 into main Mar 19, 2024
22 checks passed
@mkurapov mkurapov deleted the windows branch March 19, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package. pkg: documentation Changes in the documentation package. pkg: frontend Changes in the frontend package. pkg: mock-ase type: ci Changes to the CI type: documentation (archived) Improvements or additions to documentation type: localenv Local playground type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Be able to run Rafiki in Windows Docker
4 participants