Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Feat: Add stack management endpoints#28

Closed
Its4Nik wants to merge 54 commits intoFeat-more-testfrom
Feat-Stacks
Closed

Feat: Add stack management endpoints#28
Its4Nik wants to merge 54 commits intoFeat-more-testfrom
Feat-Stacks

Conversation

@Its4Nik
Copy link
Owner

@Its4Nik Its4Nik commented Jan 14, 2025

@sourcery-ai

Summary by Sourcery

New Features:

  • Added endpoints for managing Docker Compose stacks.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 14, 2025

Reviewer's Guide by Sourcery

This pull request introduces new endpoints for managing stacks, including creating, starting, and stopping them. It leverages the docker-compose library for stack operations and implements a new stack management module.

Sequence diagram for stack management operations

sequenceDiagram
    participant Client
    participant API
    participant StackHandler
    participant DockerCompose
    participant FileSystem

    %% Create Stack Flow
    Client->>API: POST /stacks/create/{name}
    API->>StackHandler: createStack(name, content)
    StackHandler->>FileSystem: Write docker-compose.yaml
    StackHandler->>FileSystem: Update config file
    StackHandler-->>Client: Success response

    %% Start Stack Flow
    Client->>API: POST /stacks/start/{name}
    API->>StackHandler: start(name)
    StackHandler->>StackHandler: validate(name)
    StackHandler->>DockerCompose: upAll()
    DockerCompose-->>StackHandler: Success
    StackHandler-->>Client: Success response

    %% Stop Stack Flow
    Client->>API: POST /stacks/stop/{name}
    API->>StackHandler: stop(name)
    StackHandler->>StackHandler: validate(name)
    StackHandler->>DockerCompose: downAll()
    DockerCompose-->>StackHandler: Success
    StackHandler-->>Client: Success response
Loading

File-Level Changes

Change Details Files
Added stack management endpoints
  • Added new paths for stack creation, starting, and stopping: /stacks/create/{name}, /stacks/start/{name}, and /stacks/stop/{name}
  • Included request body schema for /stacks/create/{name} to define the structure of the docker-compose file content.
  • Added a new tag Stacks to categorize these endpoints in the Swagger documentation.
  • Defined responses for each endpoint, including success and error scenarios (200, 402, 403, 500, 503).
src/config/swagger.yaml
Implemented stack management handlers and logic
  • Created new handlers for stack operations (create, start, stop) in src/handlers/stack.ts.
  • Added stack management routes in src/routes/stack/routes.ts to handle incoming requests.
  • Defined types for docker-compose files and stack configurations in src/typings/dockerCompose.ts and src/typings/stackConfig.ts.
  • Implemented functions to create, start, and stop stacks using the docker-compose library.
  • Added a new route for stack management in src/init.ts.
  • Created helper functions to manage stack configurations and validate stack names in src/config/stacks.ts.
  • Implemented error handling and logging for stack operations using a response handler and logger from existing utilities.
  • Added a validation step to ensure the requested stack exists before performing start/stop operations.
  • Implemented a function to update the stack configuration file after creating a new stack.
  • Used YAML library to handle docker-compose file content.
  • Defined a regular expression for validating stack names.
  • Defined the project root path for file operations.
  • Imported necessary modules and libraries (express, docker-compose, fs, path, etc.).
src/init.ts
src/handlers/stack.ts
src/routes/stack/routes.ts
src/typings/dockerCompose.ts
src/config/stacks.ts
src/typings/stackConfig.ts
Updated dependencies and documentation
  • Added new dependencies for stack management, including docker-compose, i, and npm.
  • Updated package-lock.json to reflect the changes in dependencies.
  • Updated CREDITS.md to include the new dependencies and their licenses (Apache 2.0, Artistic-2.0, BlueOak-1.0.0).
CREDITS.md
package.json
package-lock.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Feat: Add stack management endpoints Jan 14, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Its4Nik - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The success message in the stack.stop handler incorrectly says 'Stack started' instead of 'Stack stopped'
  • The 'i' and 'npm' package dependencies appear to be unnecessary and should be removed
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Its4Nik and others added 8 commits January 14, 2025 14:31
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Its4Nik
Copy link
Owner Author

Its4Nik commented Jan 14, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Its4Nik - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a proper configuration management system instead of storing compose files directly on disk. This would provide better security, versioning and cleanup capabilities.
  • The error handling could be more specific - catching unknown errors and converting them to strings may mask important error details. Consider handling specific error types separately.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Its4Nik and others added 4 commits January 15, 2025 20:12
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…th expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…th expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Its4Nik and others added 2 commits January 17, 2025 07:57
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Its4Nik and others added 28 commits January 29, 2025 18:54
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…properties.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Its4Nik Its4Nik closed this Mar 11, 2025
@Its4Nik Its4Nik deleted the Feat-Stacks branch March 11, 2025 17:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant