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
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34b3505
Added initial devcontainer support.
alaurie Dec 10, 2024
4243599
Merge branch 'AlmaLinux:master' into devcontainer
alaurie Dec 10, 2024
092d756
Add python3-pyyaml to dockerfile.
alaurie Dec 10, 2024
0bb24e4
Merge branch 'devcontainer' of https://github.com/alaurie/almalinux.o…
alaurie Dec 10, 2024
ae1cf2a
Add README.md to devcontainer directory.
alaurie Dec 10, 2024
5ccb7da
Several tweaks to #709
codyro Dec 10, 2024
177be2d
Merge pull request #1 from codyro/pr-709-devcontainer-tweaks
alaurie Dec 10, 2024
7738274
Merge branch 'AlmaLinux:master' into devcontainer
alaurie Dec 11, 2024
8af8b91
Revert "Several tweaks to #709"
alaurie Dec 11, 2024
f80f85d
Merge pull request #2 from alaurie/revert-1-pr-709-devcontainer-tweaks
alaurie Dec 11, 2024
36d5a7b
Merge pull request #1 from codyro/pr-709-devcontainer-tweaks
alaurie Dec 11, 2024
010c674
Remove hugo serve command and set overrideCommand to true.
alaurie Dec 11, 2024
beb5103
Add docker extension to vscode.
alaurie Dec 11, 2024
9474397
Testing to see why CMD is failing with hugo server command
codyro Dec 11, 2024
73f6d13
Leverage devcontainer postStartCommand hook
codyro Dec 11, 2024
26b3d55
Update the order of operations to make hugo happy
codyro Dec 11, 2024
52d822d
Quick dockerfile tweaks
codyro Dec 11, 2024
d3979d1
Remove debugging fragments
codyro Dec 11, 2024
f83d720
Merge pull request #3 from codyro/pr-709-devcontainer-tweaks
alaurie Dec 11, 2024
129903c
Merge branch 'AlmaLinux:master' into devcontainer
alaurie Dec 11, 2024
cfbc2aa
Corrected arg naming and added specific version downloading for pinni…
alaurie Jan 17, 2025
3dfec6d
Updated readme.md for recent changes.
alaurie Jan 17, 2025
68625ec
Added devcontainer to main readme.me
alaurie Jan 21, 2025
7d8d0d0
Corrected devcontainer readme link
alaurie Jan 21, 2025
71e314c
Set hugo version to 0.141.0 as latest pinning.
alaurie Jan 21, 2025
2a0dcff
Merge branch 'master' into devcontainer
codyro Mar 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Use AlmaLinux as the base image
FROM almalinux:latest

# Update and install necessary packages
RUN dnf update -y && \
dnf install -y \
git \
python3 \
python3-pyyaml \
wget \
tar \
shadow-utils \
sudo \
&& dnf clean all

# Set up arguments for Hugo installation
ARG HUGO_VERSION=latest
ARG HUGO_VARIANT=hugo_extended

# Download and install Hugo
RUN if [ "$HUGO_VERSION" = "latest" ]; then \
HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}'); \
fi && \
echo "Installing Hugo version: ${HUGO_VERSION}" && \
wget -O hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_VARIANT}_${HUGO_VERSION}_Linux-64bit.tar.gz && \
tar -xzf hugo.tar.gz && \
mv hugo /usr/local/bin/hugo && \
chmod +x /usr/local/bin/hugo && \
rm hugo.tar.gz

# Create a non-root user for development
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

USER vscode

# Expose port for Hugo server
EXPOSE 1313

# Set the working directory
WORKDIR /workspace

# Set the default command to run Hugo server
CMD ["hugo", "server", "--bind=0.0.0.0"]
23 changes: 23 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### 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.
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "AlmaLinux_WWW_Container",
"build": {
"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

}
},

"customizations": {
"vscode": {
"extensions": [
"budparr.language-hugo-vscode",
"ms-python.python",
"esbenp.prettier-vscode",
"yzhang.markdown-all-in-one",
"tamasfe.even-better-toml"
]
},
"terminal.integrated.shell.linux": "/bin/bash"
},
"forwardPorts": [1313],
"remoteUser": "vscode"
}
Loading