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

Devcontainer support #709

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Devcontainer support #709

wants to merge 20 commits into from

Conversation

alaurie
Copy link

@alaurie alaurie commented Dec 10, 2024

This pull request introduces initial support for developing the Hugo site on AlmaLinux within a devcontainer. This setup enhances the development experience by providing a consistent, pre-configured environment directly from Visual Studio Code:

Devcontainer Features:

  • VSCode Extensions: Automatically installs the following extensions for optimal Hugo development:
    budparr.language-hugo-vscode - Hugo syntax support
    ms-python.python - Python development support
    esbenp.prettier-vscode - Code formatting
    yzhang.markdown-all-in-one - Enhanced Markdown editing
    tamasfe.even-better-toml - TOML language support

  • Terminal Configuration: Sets the integrated terminal to /bin/bash for a familiar shell experience.

  • Port Forwarding: Configures port 1313 to be forwarded for Hugo's live server.

  • User Configuration: Sets remoteUser to vscode, providing a secure, non-root user environment.

Dockerfile Setup:

  • Base Image: Utilizes the latest AlmaLinux image for compatibility and security.
  • System Updates: Ensures all system packages are up-to-date.
  • Software Installation: Includes essential tools like git, python3, python3-pyyaml, wget, tar, shadow-utils, and sudo.
  • Hugo Installation: Fetches and installs the latest Hugo extended binary for dynamic site generation.
  • User Management: Creates and configures a vscode user with sudo privileges to enhance security and usability.
  • Port Exposure: Exposes port 1313 to allow Hugo's development server to be accessed externally.

This setup aims to streamline the development process by automating the environment setup, ensuring consistency across different machines, and reducing the time spent on configuration. Please review and provide feedback or approval to merge.

@codyro
Copy link
Member

codyro commented Dec 10, 2024

This looks fantastic! I'll give it a test tomorrow morning (local) to see if I can find any quirks.

What do you think about adding what you typed up in the PR to a README.md in the .devcontainer folder so people can see what it does at a glance (without looking for this PR)?

@alaurie
Copy link
Author

alaurie commented Dec 10, 2024

@codyro Good idea, have added!

@codyro codyro self-requested a review December 10, 2024 16:12
- You can find explanations of the changes in
AlmaLinux#709
Copy link
Member

@codyro codyro left a comment

Choose a reason for hiding this comment

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

I've made some comments/suggested changes. Feel free to use/tweak as you see fit.

I've also made a PR to your repo (alaurie#1) with the changes I commented on.

"dockerfile": "Dockerfile",
"args": {
"VARIANT": "hugo",
"VERSION": "latest"
Copy link
Member

Choose a reason for hiding this comment

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

While this should be fine we should verify the site runs fine on the latest Hugo version (v0.139.4) as we currently pin the production site to 0.98.0. This was done at the time to ensure no surprise breakages between versions.

Similar with Python--we pin version 3.11, however we should be able to use the 3.12 in repositories (or we could pin 3.9 to match the devcontainer).

Ultimately I'd like to have a 1:1 environment with our production, so we have two options:

  1. Update the devcontainer versions to match production (very old at this point)
  2. Verify everything runs cleanly on the latest versions of Hugo and Python from the repos (3.12.x) and update the production site to match

I'm thinking option 2 is the move as I'm pretty sure most people working on the site aren't using an ancient version of Hugo..

Copy link
Member

Choose a reason for hiding this comment

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

as a note: I'm not sure the pinning you mentioned is actually working as intended. I recently (maybe as many as a few months ago) hit some snags due to outdated hugo installed on my laptop. I had to upgrade so that what I was doing would match the errors I was seeing as it deployed to dev.

Copy link
Author

@alaurie alaurie Dec 19, 2024

Choose a reason for hiding this comment

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

I think you're correct @bennyvasquez. The latest run I can see in GitHub actions uses the latest version 0.140.0

https://github.com/AlmaLinux/almalinux.org/actions/runs/12401185107/job/34620009233

image

.devcontainer/devcontainer.json Outdated Show resolved Hide resolved
.devcontainer/Dockerfile Outdated Show resolved Hide resolved
.devcontainer/Dockerfile Outdated Show resolved Hide resolved
.devcontainer/devcontainer.json Outdated Show resolved Hide resolved
.devcontainer/devcontainer.json Show resolved Hide resolved
@codyro codyro added the enhancement New feature or request label Dec 10, 2024
- Ensures workspace is properly mounted *before* `hugo server` is ran
  - It attempted to run the command before the `config.yaml` was
available
codyro and others added 4 commits December 11, 2024 15:46
- Accidental nohup log committed
- Test image I built
Fix hugo failing to start in the background successfully
@codyro
Copy link
Member

codyro commented Dec 11, 2024

Assuming we think this is ready to merge, I'll want to get a few community members to test it to ensure there are no lingering quirks and engage with anyone interested in helping out contributing (I just intend to ask in MatterMost, nothing fancy). Once we get some confirmation that everything works flawlessly, let's merge this as-is and then submit a new issue to add documentation. Or we could add documentation to this PR if we feel exceptionally motivated.

We could add a page (or multiple) on the wiki about how to use the devcontainers in projects to contribute (you said you're considering wiki after this, and I'll be looking to use it elsewhere).

Copy link
Member

@codyro codyro left a comment

Choose a reason for hiding this comment

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

Teamwork makes the dream work 🤝

@codyro codyro linked an issue Dec 11, 2024 that may be closed by this pull request
@bennyvasquez
Copy link
Member

Documentation is critical and should be added along with these updates, so I'd like it to be part of this PR.

@codyro
Copy link
Member

codyro commented Dec 12, 2024

Documentation is critical and should be added along with these updates, so I'd like it to be part of this PR.

It doesn't affect production. It's essentially the equivalent of adding a utility script that's unused. The scope of it being in a single PR isn't really realistic.

Splitting it up will be more effective in this case.

rm hugo.tar.gz

# Create a non-root user for development
ARG USERNAME=vscode
Copy link
Member

Choose a reason for hiding this comment

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

I'd propose to call the default user "alma" or "hugosite", something more meaningful in my opinion than "vscode"

Copy link
Member

Choose a reason for hiding this comment

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

The default base image templates (and most other devcontainer documentation) leverage the vscode user by default--so I think anyone familiar with devcontainers wouldn't be confused.

I don't see any reason we cannot switch it--we need to make sure with any future modifications to remember that we're using a "non-standard" username (or just always reference the UID I guess?).

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I wasn't aware that it is a general "practice" and I'm fine with it

Copy link
Member

@codyro codyro Dec 16, 2024

Choose a reason for hiding this comment

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

I don't know if it's "best practice" as much as "path of least resistance" 😄.

It would look better with a different username. I just wanted to provide context as to why that was likely chosen :).

It's up to @alaurie if he wants to rotato potato it or not.

Copy link
Author

Choose a reason for hiding this comment

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

We can switch it the consensus is to do so for Alma. Like @codyro said, its just a general default on a lot of prefab containers on Docker and various other registries.

@pastalian
Copy link
Contributor

Is this intended only for docker users?
In my podman environment, it didn't work without adding --userns=keep-id to runArgs, which isn't available in docker so we can't simply add it here. I guess supporting both docker and podman out of the box is challenging.

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

Successfully merging this pull request may close these issues.

Enhancement: Add devcontainer support to repo.
5 participants