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

Add Dev Container #8

Merged
merged 3 commits into from
Jun 10, 2024
Merged

Add Dev Container #8

merged 3 commits into from
Jun 10, 2024

Conversation

jgarber623
Copy link

This PR adds a Dev Container to the project for easier project setup and development.

There are a number of IDEs and tools that support Dev Containers, but the following testing instructions will assume VS Code (for good or for ill).

  1. Install Docker Desktop, VS Code, and the VS Code Dev Containers extension
  2. Switch to this branch: git switch add-devcontainer
  3. Open the project in VS Code
  4. Open the command palette (cmd-shift-p on macOS) and serach for "Dev Containers: Reopen in Container"
  5. Wait for the Dev Container to pull and build the development image
  6. Open a new VS Code terminal tab (cmd-j on macOS to show the panel)
  7. Run formatting: mix format --check-formatted
  8. Run tests: mix test
  9. Generate docs: mix docs

🥳

@jgarber623 jgarber623 self-assigned this Jun 10, 2024
Comment on lines +7 to +8
mix local.hex --force
mix deps.get
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 like these are the two most relevant commands to run immediately after creating the container.

Without, an initial run of mix test prompted me to run mix local.hex --force and an initial run of mix docs required running mix deps.get.

For a library like this, are there other helpful commands that should be run after container creation?

Copy link
Member

Choose a reason for hiding this comment

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

Quick note here in case it's instructive: Elixir's build tool mix has a concept of environments. Briefly, each environment is a completely separate build of the project but with slight configuration changes.

:compare_chain itself has no dependencies in the :prod or :test environments. But it does have the :ex_doc dependency in the :dev environment. We can see these two facts from how :compare_chain declares its dependencies in mix.exs:

  defp deps do
    [
      {:ex_doc, "~> 0.31", only: :dev, runtime: false}
                         # ^^^^^^^^^^
    ]
  end

This is why you can run mix test (which runs in the :test environment) without needing mix deps.get, but you do need it to run mix docs (which runs in the :dev environment).

Copy link
Member

Choose a reason for hiding this comment

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

For a library like this, are there other helpful commands that should be run after container creation?

No I think what's there is good!

Comment on lines +29 to +30
"EditorConfig.EditorConfig",
"JakeBecker.elixir-ls"
Copy link
Author

Choose a reason for hiding this comment

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

Are there other popular Elixir extensions for VS Code that would be candidates for inclusion here?

Copy link
Member

Choose a reason for hiding this comment

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

No I think these are sufficient.

@billylanchantin
Copy link
Member

@jgarber623 I'm getting that thing where the terminal is stuck after building the container and I forget how to get past it. Do you remember?

Screen Shot 2024-06-10 at 10 27 40 AM

@jgarber623
Copy link
Author

@billylanchantin You can either click the trash can icon to close that Terminal tab or click the plus icon to create a new Terminal tab.

@billylanchantin
Copy link
Member

The trash icon worked, thanks!

I really need to learn more about VSCode's terminal. It just wasn't obvious to me that what I was looking at was something I could close.

@jgarber623
Copy link
Author

It just wasn't obvious to me that what I was looking at was something I could close.

That specific Terminal (the one aggregating Dev Container creation output) is particularly annoying for this reason. Unlike the Dev Container lifecycle scripts (e.g. postCreateCommand), that one doesn't give you a helpful "press any key to close" message.

This commit adds a basic Elixir Dev Container along with some useful tooling like the latest version of Git, the GitHub CLI, and the Elixir language server extension.
Copy link
Member

@billylanchantin billylanchantin left a comment

Choose a reason for hiding this comment

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

Looking good!

Screen Shot 2024-06-10 at 11 00 50 AM

One concern I have is about publishing to hex. This isn't something we need to worry about on our private repos, but I want to make sure what gets published is as lean as possible. That is, I'd like to make it so our devcontainer code never gets published if we can avoid it.

This is sorta nit-picky since it would be essentially dead code at that point. But I'd still like to read about how mix hex.publish works to see what level of control is possible before we merge.

@jgarber623
Copy link
Author

@billylanchantin Yes! That's a great callout.

Taking a quick look at the documentation:

:files
A list of files and directories to include in the package. Defaults to standard project directories, so you usually don't need to set this property.

That's… ambiguous… unless you happen to know what "standard project directories" are but I would guess that .devcontainer isn't one of them.

@jgarber623
Copy link
Author

@billylanchantin Package and docs publishing can be tested locally:

mix hex.publish package --dry-run
mix hex.publish docs --dry-run

The former yields:

Building compare_chain 0.5.0
  App: compare_chain
  Name: compare_chain
  Files:
    lib
    lib/compare_chain.ex
    lib/compare_chain
    lib/compare_chain/core.ex
    lib/compare_chain/error_message.ex
    .formatter.exs
    mix.exs
    README.md
    LICENSE
    CHANGELOG.md
  Version: 0.5.0
  Build tools: mix
  Description: Chained, semantic comparisons for Elixir
  Licenses: MIT
  Links: 
    GitHub: https://github.com/CargoSense/compare_chain
  Elixir: >= 1.13.0
Before publishing, please read the Code of Conduct: https://hex.pm/policies/codeofconduct

Publishing package to public repository hexpm.
No authenticated user found. Do you want to authenticate now? [Yn]

@billylanchantin
Copy link
Member

@jgarber623 Ah excellent! Yeah doesn't look like the devcontainer stuff is bundled, which makes sense.

I also found these docs to be a bit more detailed:

:files - List of files and directories to include in the package, can include wildcards. Defaults to ["lib", "priv", ".formatter.exs", "mix.exs", "README*", "readme*", "LICENSE*", "license*", "CHANGELOG*", "changelog*", "src", "c_src", "Makefile*"].

I don't know why there are multiple versions of this documentation...

@billylanchantin billylanchantin self-requested a review June 10, 2024 15:46
Copy link
Member

@billylanchantin billylanchantin left a comment

Choose a reason for hiding this comment

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

Nice work! I think this is good to go.

I'm still curious about the intersection of mix environments and devcontainers. I think best practices are still emerging so I don't think we need to solve everything here.

@jgarber623 jgarber623 merged commit 364c811 into main Jun 10, 2024
12 checks passed
@jgarber623 jgarber623 deleted the add-devcontainer branch June 10, 2024 15:49
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.

3 participants