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: ability to work with Blockscout code base within a VSCode devcontainer #10838

Merged
merged 13 commits into from
Oct 4, 2024

Conversation

akolotov
Copy link
Contributor

@akolotov akolotov commented Sep 28, 2024

Resolves #10432

Motivation

Setting up a local development environment for Blockscout was time-consuming and error-prone, requiring manual installation of Elixir, Phoenix, Node.js, and other dependencies. To streamline this process, a pre-configured dev container using Docker was introduced. This containerized environment allows developers to work with the Blockscout codebase without needing to install and configure dependencies on their local machines. It also ensures consistency across development environments, reducing the risk of version conflicts and setup errors. Additionally, database management was simplified by including a PostgreSQL service, and essential VS Code extensions were integrated to enhance productivity. By using this dev container, contributors can get started more quickly, allowing them to focus on development rather than setup.

This feature also enables seamless development for Blockscout using GitHub Codespaces, allowing contributors to work directly in a cloud-based environment without the need to install or configure VS Code locally. By leveraging Codespaces, developers can instantly spin up a fully-configured dev environment, further reducing setup time and making it easier to contribute from any device.

image

Key features introduced by these changes include:

  1. Pre-configured Development Environment: The .devcontainer directory provides a full development environment with Elixir, Phoenix, and Node.js pre-configured, automatically installs project dependencies, and includes scripts for common development tasks, further streamlining the setup and development process.

  2. Integrated PostgreSQL Database Service: The docker-compose.yml file sets up a PostgreSQL service alongside the Elixir application, simplifying database management and allowing immediate use with pre-defined environment settings.

  3. Port Forwarding for Local Access: Specific ports (4000, 4001, 5432) are forwarded through the container, enabling easy local access to the Blockscout application and database.

  4. VS Code Customizations, Extensions, and Features: The devcontainer.json file integrates useful VS Code extensions and features for Blockscout development, including Elixir LS, GitHub Copilot, PostgreSQL tools and persistent shell history, enhancing developer productivity and experience in the containerized environment.

  5. Optional GitHub SSH Authorization: The devcontainer.json file includes a commented-out section that provides an optional configuration to mount SSH keys, allowing developers to authenticate and push changes to GitHub directly from within the dev container.

  6. Development Task Orchestration: A new bs script has been added to simplify common development tasks such as initializing the project, managing the database, and running the server.

Changelog

Enhancements

  • devcontainer.json:

    • Configures VS Code extensions such as Elixir LS, PostgreSQL tools, and GitHub Copilot to streamline development within the container.
    • Includes a post-create command to set the workspace as a safe directory for Git operations and to run mix deps.get, ensuring all project dependencies are installed automatically upon container creation.
    • Updated to include the new bin directory in the PATH, making the development scripts easily accessible.
    • Provides port forwarding (4000, 4001, 5432) for accessing the Blockscout application and PostgreSQL database.
    • Integrated the shell-history feature to provide persistent command history in the development container.
    • Includes an optional, commented-out section to mount SSH keys for GitHub authentication, enabling developers to push code directly from within the container.
  • docker-compose.yml:

    • The Elixir service uses a pre-built image maintained in the repository https://github.com/blockscout/devcontainer-elixir, improving setup speed and consistency.
    • Sets up and orchestrates the services within the dev container, including an Elixir service and a PostgreSQL database service.
    • The PostgreSQL service is pre-configured with default credentials (postgres), simplifying local database setup and integration.
    • Utilizes a shared network mode to allow direct interaction between the Elixir service and the PostgreSQL service.
  • Development Scripts:

    • Added a bs script in .devcontainer/bin/ to orchestrate typical development tasks such as project initialization, database management, and server execution.
    • Included chain-specific checks in .devcontainer/bin/chain-specific-checks to perform checks based on the CHAIN_TYPE.
    • Added utility functions in .devcontainer/bin/utils for checking RPC endpoints availability and accessibility.
  • Configuration:

    • Added a .blockscout_config.example file to provide a template for Blockscout configuration settings.
  • Dockerfile:

Checklist for your Pull Request (PR)

  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • I checked whether I should update the docs and did so by submitting a PR to docs repository.
  • If I added/changed/removed ENV var, I submitted a PR to docs repository to update the list of env vars and I updated the version to master in the Version column. If I removed variable, I added it to Deprecated ENV Variables page. After merging docs PR, changes will be reflected in these pages.
  • If I added new DB indices, I checked, that they are not redundant, with PGHero or other tools.
  • If I added/removed chain type, I modified the Github CI matrix and PR labels accordingly.

Copy link
Member

@k1rill-fedoseev k1rill-fedoseev left a comment

Choose a reason for hiding this comment

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

Let's also add a small instruction to CONTRIBUTING.md on how to use this with Github codespaces for new contributors.

.devcontainer/docker-compose.yml Outdated Show resolved Hide resolved
.devcontainer/Dockerfile Outdated Show resolved Hide resolved
@akolotov
Copy link
Contributor Author

akolotov commented Oct 1, 2024

@k1rill-fedoseev please take a look one more time

@akolotov
Copy link
Contributor Author

akolotov commented Oct 3, 2024

Let's also add a small instruction to CONTRIBUTING.md on how to use this with Github codespaces for new contributors.

@k1rill-fedoseev I have added .devcontainer/README.md and the script .devcontainer/bin/bs that helps with the basic tasks.

.blockscout_config.example Outdated Show resolved Hide resolved
.devcontainer/bin/bs Show resolved Hide resolved
@akolotov akolotov changed the title chore: ability to work with Blockscout code base within a VSCode devcontainer. chore: ability to work with Blockscout code base within a VSCode devcontainer Oct 3, 2024
@@ -65,3 +65,4 @@ dump.rdb
*.env.example
*.env.local
*.env.staging
.devcontainer/.blockscout_config
Copy link
Member

Choose a reason for hiding this comment

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

Let's add .devcontainer/ to .dockerignore too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 410bb41

@akolotov akolotov merged commit 3a8e9f4 into master Oct 4, 2024
16 checks passed
@akolotov akolotov deleted the feat/common/devcontainer-intro branch October 4, 2024 14:48
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.

Create devcontainer configuration
3 participants