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 20 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
57 changes: 57 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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
ARG WORKSPACE_DIR

# 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 && \
ARCH=$(uname -m) && \
case "$ARCH" in \
"x86_64") HUGO_ARCH="64bit";; \
"arm64"|"aarch64") HUGO_ARCH="arm64";; \
*) echo "Unsupported architecture: $ARCH" && exit 1;; \
esac && \
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-${HUGO_ARCH}.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 to the container workspace directory
WORKDIR ${WORKSPACE_DIR}

ENTRYPOINT ["hugo", "server"]
CMD ["--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.
37 changes: 37 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "AlmaLinux_WWW_Container",
"overrideCommand": false,
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "hugo",
"VERSION": "latest",
"WORKSPACE_DIR": "${containerWorkspaceFolder}"
}
},

"customizations": {
"vscode": {
"extensions": [
"budparr.language-hugo-vscode",
"ms-python.python",
"esbenp.prettier-vscode",
"yzhang.markdown-all-in-one",
"tamasfe.even-better-toml",
"ms-azuretools.vscode-docker"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash",
"icon": "terminal-bash"
}
}
}
}
},
"forwardPorts": [1313],
"remoteUser": "vscode",
"postCreateCommand": "echo 'function git_branch() { local branch; branch=\"$(git symbolic-ref --short HEAD 2> /dev/null)\"; if [[ -n \"$branch\" ]]; then echo -n \"$branch\"; return 0; fi; return 1; } && function git_has_changes() { git diff --quiet HEAD 2> /dev/null || echo -n \"✗\"; } && export WHITE=\"\\[\\033[1;37m\\]\" && export GREEN=\"\\[\\033[0;32m\\]\" && export BLUE=\"\\[\\033[0;94m\\]\" && export RED=\"\\[\\033[1;31m\\]\" && export YELLOW=\"\\[\\033[1;33m\\]\" && export RESET=\"\\[\\033[0m\\]\" && function prompt_command() { PS1=\"${GREEN}\\u${WHITE} ➜ ${BLUE}\\w ${BLUE}(${RED}\\$(git_branch)${YELLOW}\\$(git_has_changes)${BLUE})${RESET}$ \"; } && export PROMPT_COMMAND=\"prompt_command\"' >> ~/.bashrc"
}
Loading