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 compose overlay file for editable backend container #1098

Merged
merged 14 commits into from
Feb 24, 2024
Merged

Conversation

jbirddog
Copy link
Contributor

@jbirddog jbirddog commented Feb 23, 2024

This provides an overlay file which when used along with the existing docker-compose.yml, allows for editing backend code. Many thanks to @burnettk for getting the unit tests to pass, that was driving me bonkers.

Summary by CodeRabbit

  • New Features
    • Enhanced Docker Compose configurations for improved development environment setup.
    • Added Makefile targets for streamlined development workflows, including server management, testing, and linting.
  • Refactor
    • Updated backend setup with Poetry for dependency management in the development Dockerfile.
    • Simplified backend unit testing configuration for easier management of environment variables.
  • Chores
    • Improved permission handling by adding user and group ID variables to Docker Compose commands.

Copy link
Contributor

coderabbitai bot commented Feb 23, 2024

Walkthrough

Walkthrough

The recent updates enhance the development environment and workflow significantly. Changes include the integration of user and group ID variables, introduction of container configurations for backend and frontend, and adaptation of Docker Compose commands to utilize these settings. Furthermore, new Makefile targets streamline development tasks, backend Docker and Compose files are refined for improved service setup, and backend configuration now includes hardcoded values for simplicity.

Changes

Files Change Summary
Makefile Added user/group IDs, container variables, Docker Compose commands, new targets (stop-dev, be-sh, etc.), and refactored service/test commands.
spiffworkflow-backend/dev.Dockerfile, dev.docker-compose.yml Introduced Python environment setup with Poetry in dev.Dockerfile, configured spiffworkflow-backend service in dev.docker-compose.yml with essential settings.
spiffworkflow-backend/src/.../config/unit_testing.py Assigned hardcoded values to SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME and introduced SPIFFWORKFLOW_BACKEND_URL.
spiffworkflow-frontend/dev.docker-compose.yml Added user: "${RUN_AS}" configuration under the services section.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 8

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 336f559 and dbd59e0.
Files selected for processing (5)
  • Makefile (1 hunks)
  • spiffworkflow-backend/dev.Dockerfile (1 hunks)
  • spiffworkflow-backend/dev.docker-compose.yml (1 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py (1 hunks)
  • spiffworkflow-frontend/dev.docker-compose.yml (1 hunks)
Additional comments: 2
spiffworkflow-backend/dev.Dockerfile (1)
  • 14-14: Using poetry install --no-root is a good practice to avoid installing the project package itself. However, ensure that this aligns with the project's requirements, especially if the project package needs to be available for certain commands or scripts to run correctly.
spiffworkflow-backend/src/spiffworkflow_backend/config/unit_testing.py (1)
  • 8-8: Hardcoding the SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME to "unit_testing.yml" simplifies the configuration for testing. Ensure that this file is appropriately configured and available in the testing environment.

@@ -3,6 +3,7 @@ services:
build:
context: spiffworkflow-frontend
dockerfile: dev.Dockerfile
user: "${RUN_AS}"
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 23, 2024

Choose a reason for hiding this comment

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

The addition of the user: "${RUN_AS}" configuration is a good practice for managing file permissions between the host and the container. However, it's crucial to ensure that the ${RUN_AS} environment variable is well-documented and validated to prevent potential runtime issues. Consider adding documentation on how to set this variable and validating its presence before container startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

crucial seems strong.

Copy link
Contributor

Choose a reason for hiding this comment

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

@burnettk, I appreciate your perspective. The intention was to highlight the benefits of documenting and validating the ${RUN_AS} environment variable to ensure a seamless development experience, especially for new contributors or when changes are made to the development setup. It's indeed important to balance the guidance with the practicalities of the development process. Thank you for pointing that out.

Comment on lines +5 to +8
RUN apt-get update \
&& apt-get install -y -q \
gcc libssl-dev libpq-dev default-libmysqlclient-dev \
pkg-config libffi-dev git-core curl
Copy link
Contributor

Choose a reason for hiding this comment

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

Installing system dependencies with apt-get install is necessary, but consider cleaning up the apt cache with rm -rf /var/lib/apt/lists/* at the end of the command to reduce the image size.

pkg-config libffi-dev git-core curl

RUN pip install --upgrade pip
RUN pip install poetry==1.6.1 pytest-xdist
Copy link
Contributor

Choose a reason for hiding this comment

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

Specifying the Poetry version is a good practice for ensuring consistent builds. However, consider using a lock file or a more controlled environment to manage the exact versions of all dependencies, including pytest-xdist, to further enhance reproducibility.

Comment on lines +8 to +10
# TODO: would like to figure out the permissions issue that is preventing this
#
#user: "${RUN_AS}"
Copy link
Contributor

Choose a reason for hiding this comment

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

The commented-out user configuration due to permissions issues is noteworthy. Resolving this to align with the frontend's approach of running containers with specific user permissions would enhance consistency and potentially avoid permission issues with mounted volumes. Consider investigating and documenting the permissions issue further.

Comment on lines +1 to +3
MY_USER := $(shell id -u)
MY_GROUP := $(shell id -g)
ME := $(MY_USER):$(MY_GROUP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Defining MY_USER and MY_GROUP variables at the beginning of the Makefile is a good practice for managing file permissions consistently. Ensure that there's documentation on how these variables are used and any prerequisites for the development environment setup.

Comment on lines +11 to +13
DOCKER_COMPOSE ?= RUN_AS=$(ME) docker compose $(YML_FILES)
IN_BACKEND ?= $(DOCKER_COMPOSE) run $(BACKEND_CONTAINER)
IN_FRONTEND ?= $(DOCKER_COMPOSE) run $(FRONTEND_CONTAINER)
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of RUN_AS=$(ME) in Docker Compose commands is a smart way to ensure consistent user permissions. However, ensure that there's clear documentation on how these commands work and any necessary environment setup, especially for new contributors.


SPIFFWORKFLOW_BACKEND_URL = "http://localhost:7000"
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 23, 2024

Choose a reason for hiding this comment

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

Introducing a hardcoded SPIFFWORKFLOW_BACKEND_URL value can simplify testing by providing a consistent base URL. However, consider the implications for testing in environments where the backend URL might differ, and ensure there's a way to override this value if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

i can't think of a case where you would want it to differ. respecting environment variables in this file was one of things making the unit tests less portable to this new environment. using good known values seems safest.

Copy link
Contributor

Choose a reason for hiding this comment

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

@burnettk: Your point about prioritizing portability and simplicity in the test environment setup is well taken. Hardcoding SPIFFWORKFLOW_BACKEND_URL does indeed streamline the process and ensures consistency across different testing scenarios, which aligns with the objectives of making the development workflow more efficient. It's clear that in the context of your project, the benefits of this approach outweigh the potential limitations. Should the need arise to accommodate different backend URLs in the future, adjustments could be made to introduce flexibility without significantly complicating the current setup. Your strategy seems well-considered for the project's current requirements.


SPIFFWORKFLOW_BACKEND_URL = "http://localhost:7000"
Copy link
Contributor

Choose a reason for hiding this comment

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

i can't think of a case where you would want it to differ. respecting environment variables in this file was one of things making the unit tests less portable to this new environment. using good known values seems safest.

@@ -3,6 +3,7 @@ services:
build:
context: spiffworkflow-frontend
dockerfile: dev.Dockerfile
user: "${RUN_AS}"
Copy link
Contributor

Choose a reason for hiding this comment

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

crucial seems strong.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between dbd59e0 and 910ce2a.
Files selected for processing (1)
  • Makefile (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Makefile

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 910ce2a and 427f0f8.
Files selected for processing (1)
  • Makefile (1 hunks)
Additional comments: 17
Makefile (17)
  • 1-3: Variables MY_USER, MY_GROUP, and ME are well-defined, leveraging shell commands to dynamically assign user and group IDs. This approach ensures that file permissions are handled correctly across different development environments.
  • 5-7: Defining variables for the backend container and its development overlay is a good practice. It enhances modularity and makes the Makefile more maintainable by allowing easy updates to container names and paths.
  • 8-8: Variables for the frontend container and its development overlay are defined without explicit line number annotations. This is consistent with the backend definitions and follows the same best practices for modularity and maintainability.
  • 11-13: The DOCKER_COMPOSE and IN_BACKEND, IN_FRONTEND command variables are well-structured, incorporating the user and group ID variables for consistent permission management. This setup facilitates running Docker Compose commands with the correct user permissions, reducing potential issues related to file ownership.
  • 22-24: The build-images target uses the DOCKER_COMPOSE variable to build Docker images. This is a straightforward and effective way to encapsulate the build process. Ensure that all necessary images are included in the Docker Compose configurations to avoid partial builds.
  • 25-26: The dev-env target depends on build-images, fe-npm-i, and be-recreate-db, which is a logical sequence for setting up the development environment. This target ensures that the environment is fully prepared before any development begins.
  • 28-29: The start-dev target correctly uses the DOCKER_COMPOSE variable to start the development environment in detached mode. This allows developers to continue using their terminal while the services are running.
  • 32-32: The stop-dev target is essential for cleanly shutting down the development environment. Using the DOCKER_COMPOSE variable ensures consistency with other Docker-related commands.
  • 34-35: The be-recreate-db target is crucial for database management in the backend. It uses the IN_BACKEND variable to run a script inside the backend container, ensuring the command is executed in the correct context.
  • 37-38: The be-sh target provides a convenient way to access the backend container's shell. This is useful for debugging and manual intervention when necessary.
  • 40-41: The be-tests target is well-defined, using Poetry within the backend container to run tests. This encapsulation ensures that tests are run in an environment identical to the production setup.
  • 43-44: The be-tests-par target uses the -n auto option with pytest to run tests in parallel, which can significantly reduce test execution time. However, ensure that tests are designed to be run in parallel without causing interference or race conditions.
  • 47-47: The fe-lint-fix target automates the process of fixing linting issues in the frontend codebase. This is a valuable tool for maintaining code quality and consistency.
  • 49-50: The fe-npm-i target ensures that all necessary npm packages are installed in the frontend container. This is crucial for a consistent development environment.
  • 53-53: The fe-sh target provides a convenient way to access the frontend container's shell, similar to the be-sh target. This facilitates debugging and manual tasks within the frontend environment.
  • 55-56: The take-ownership target is a practical solution for resolving file ownership issues that may arise from containerized development environments. It uses the ME variable to ensure that the current user regains ownership of all project files.
  • 58-62: The .PHONY declaration correctly lists all targets to ensure Make doesn't confuse them with filenames. This is a best practice for Makefiles to avoid unexpected behavior.

Comment on lines +15 to +17
YML_FILES := -f docker-compose.yml \
-f $(BACKEND_DEV_OVERLAY) \
-f $(FRONTEND_DEV_OVERLAY)
Copy link
Contributor

Choose a reason for hiding this comment

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

The YML_FILES variable concatenates the main Docker Compose file with the backend and frontend development overlays. This approach ensures flexibility and modularity in managing Docker Compose configurations. However, ensure that indentation is consistent across the Makefile to improve readability.

-		-f $(BACKEND_DEV_OVERLAY) \
-		-f $(FRONTEND_DEV_OVERLAY)
+       -f $(BACKEND_DEV_OVERLAY) \
+       -f $(FRONTEND_DEV_OVERLAY)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
YML_FILES := -f docker-compose.yml \
-f $(BACKEND_DEV_OVERLAY) \
-f $(FRONTEND_DEV_OVERLAY)
YML_FILES := -f docker-compose.yml \
-f $(BACKEND_DEV_OVERLAY) \
-f $(FRONTEND_DEV_OVERLAY)

Comment on lines +19 to +20
all: dev-env start-dev be-tests-par
@/bin/true
Copy link
Contributor

Choose a reason for hiding this comment

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

The all target is a convenient entry point for setting up the development environment. It's good practice to include a brief comment or documentation section explaining what this target does and when it should be used, to make it more accessible to new developers.

Would you like me to add a comment explaining the all target for clarity?

@jbirddog jbirddog merged commit ea9336e into main Feb 24, 2024
20 of 22 checks passed
@jbirddog jbirddog deleted the dev_be2 branch February 24, 2024 00:13
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.

None yet

2 participants