Skip to content

Devcontainer support #709

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

Merged
merged 26 commits into from
Mar 4, 2025
Merged

Devcontainer support #709

merged 26 commits into from
Mar 4, 2025

Conversation

alaurie
Copy link
Contributor

@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
Contributor 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
#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 (https://github.com/alaurie/almalinux.org/pull/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
Contributor 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

@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
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.

@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.

@alaurie
Copy link
Contributor Author

alaurie commented Jan 17, 2025

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.

At the moment its just docker. I'll look into dual support with podman as well.

@alaurie
Copy link
Contributor Author

alaurie commented Jan 17, 2025

@bennyvasquez @codyro

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

I've added in some further instructions in the readme.md around how the container is built and hugo live reloading on container start.

@codyro codyro self-requested a review January 18, 2025 16:46
@bennyvasquez
Copy link
Member

I'm good with the documentation you've created so far, @alaurie! Once we think this is ready for everyone to adopt/use for themselves, adding a mention of it to the the root README would be awesome.

@alaurie
Copy link
Contributor Author

alaurie commented Jan 21, 2025

I'm good with the documentation you've created so far, @alaurie! Once we think this is ready for everyone to adopt/use for themselves, adding a mention of it to the the root README would be awesome.

I've added a section to root README and linked to the README in the devcontainer directory.

@bennyvasquez bennyvasquez mentioned this pull request Jan 21, 2025
Copy link
Member

@bennyvasquez bennyvasquez left a comment

Choose a reason for hiding this comment

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

@codyro @alaurie are we waiting on anything else here? It looks to me like we're good to go. I haven't tested the docker deployment, but the steps seem sane to me, and I'm assuming we'll get bug reports if there are problems. :)

@alaurie
Copy link
Contributor Author

alaurie commented Feb 18, 2025

Nothing on my end, its working and I updated the docs in the repo on this commit.

Copy link

trag-bot bot commented Mar 4, 2025

@trag-bot didn't find any issues in the code! ✅✨

Copy link

trag-bot bot commented Mar 4, 2025

Pull request summary

  • Introduced a Dockerfile to set up a development container using AlmaLinux as the base image.
  • Added installation steps for essential packages including Git, Python, and Hugo, with dynamic version support for Hugo.
  • Created a non-root user (alma_www_user) with sudo privileges for enhanced security during development.
  • Configured the devcontainer to automatically install VSCode extensions tailored for Hugo development.
  • Set up port forwarding for Hugo's live server on port 1313 to facilitate real-time testing.
  • Updated the README to include instructions for contributing, bug reporting, and local development setup.
  • Added a devcontainer.json file to define the development environment configuration, including terminal settings and post-creation commands.
  • Enhanced documentation to clarify the process for accessing the live server and utilizing hot reloading features.
  • Improved user experience by ensuring the integrated terminal defaults to /bin/bash.
  • Provided troubleshooting tips for common issues related to Docker and port connectivity.

@codyro codyro merged commit 3313459 into AlmaLinux:master Mar 4, 2025
1 of 2 checks passed
@codyro
Copy link
Member

codyro commented Mar 4, 2025

Better late than never ;)

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