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

Docker SDK Usage #432

Closed
wants to merge 11 commits into from
Closed

Docker SDK Usage #432

wants to merge 11 commits into from

Conversation

danstarns
Copy link

What?

Why

Using child_process can be brittle and there are already tested tools that allow us to interact with Docker programmatically, we should use those for better readability and maintainability.

The CLI had few tests, so to make assertive changes here, I first added coverage for the CLI and then returned to make the dockerode / SDK changes.

How

Usage of npm package https://github.com/apocas/dockerode replaces child_process calls.

Vitest is added under pnpm test:unit in the CLI package, mocks are used to interact with and assert the CLI.

Refactors have been made for readability and to enable the mocking of modules in tests.

Copy link

changeset-bot bot commented Aug 25, 2024

⚠️ No Changeset found

Latest commit: 78f491a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

"e2b": "^0.16.2",
"inquirer": "^9.2.12",
"open": "^9.1.0",
"ssh2": "^1.15.0",
Copy link
Author

Choose a reason for hiding this comment

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

Added as a peer of dockerode, resolves issue in testing:

Can't resolve './crypto/build/Release/sshcrypto.node'

Related:

@@ -0,0 +1,118 @@
import * as e2b from 'e2b'
Copy link
Author

Choose a reason for hiding this comment

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

This file was moved from /template/build.js for readability and mocking in the added tests.

@@ -13,7 +13,7 @@ export default defineConfig({
sourcemap: true,
clean: true,
noExternal: Object.keys(packageJSON.dependencies).filter(
f => !excludedPackages.includes(f)
(f) => !excludedPackages.includes(f)
Copy link
Author

Choose a reason for hiding this comment

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

It seems that if I use either:

  1. vscode prettier
  2. npx prettier --fix
  3. npx eslint --fix

They all are formatting the code in different ways, is this known, or a problem with my local environment?

@@ -0,0 +1,158 @@
import { test, expect, describe, vi, afterEach } from 'vitest'
Copy link
Author

Choose a reason for hiding this comment

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

These tests can be executed in the packages/cli directory using pnpm test:unit command, they use vitest to mock the commander template build command. The final test "should perform a build" will mock all points of the build, from requesting and saving a template to pushing and building with docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants