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

# Download and install Hugo
RUN if [ "$VERSION" = "latest" ]; then \
VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}'); \
else \
VERSION=$(echo $VERSION | sed 's/v//'); \
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: ${VERSION}" && \
wget -O hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${VARIANT}_${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=alma_www_user
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 alma_www_user

# 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"]
47 changes: 47 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Devcontainer Features

## VSCode Extensions

Automatically installs the following extensions for optimal Hugo development:

- `budparr.language-hugo-vscode` - Provides syntax highlighting and IntelliSense for Hugo templates.
- `ms-python.python` - Enhances Python development with features like debugging and testing.
- `esbenp.prettier-vscode` - Formats code according to Prettier rules for consistency.
- `yzhang.markdown-all-in-one` - Offers advanced Markdown editing capabilities.
- `tamasfe.even-better-toml` - Adds support for TOML files, which are often used in Hugo configurations.
- `ms-azuretools.vscode-docker` - Integrates Docker functionality for container management.

- **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 `alma_www_user`, 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 Hugo with dynamic version support:

- If `VERSION` is set to `latest`, it downloads the latest Hugo extended binary.
- If a specific version is provided e.g. `v0.139.1`, it downloads and installs that version. This can be specified in `devcontainer.json` under `build.args`.

- **User Management:** Creates and configures an `alma_www_user` with sudo privileges to enhance security and usability.
- **Port Exposure:** Exposes port 1313 to allow Hugo's development server to be accessed externally.
- **Working Directory:** Sets the working directory to the specified `WORKSPACE_DIR`.

## Accessing the Live Server

**Starting the Server:** Upon opening the project in the container, Hugo's live server automatically starts. You can access it by navigating to `http://localhost:1313` in your web browser. This server runs in the background, allowing for real-time testing of your Hugo site.

**Editing and Hot Rebuild:**

- **Editing Files:** You can edit project files directly within your devcontainer supported editor of choice as the container mounts your local project directory, changes are reflected in real-time. This setup is not limited to VS Code; any editor that supports devcontainers will work.

- **Hot Rebuild:** Hugo's live server supports hot reloading. This means that when **changed** files are **saved**, Hugo automatically rebuilds the site, and the changes are immediately reflected in the live server. There's no need to manually restart the live server; just save your edits, and refresh your browser to see the updated site. Note that while hot reloading provides quick updates, it might slightly increase build times or resource usage depending on the complexity of your site.

## Troubleshooting

- **Docker Not Running:** Ensure Docker is installed and running on your machine before opening the project in a devcontainer.
- **Connection Issues:** If `localhost:1313` doesn't work, check your port forwarding settings or ensure no other service is using port 1313.

For more detailed information on Hugo's live server and hot reloading, refer to the [Hugo documentation](https://gohugo.io/getting-started/usage/#livereload).
36 changes: 36 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "AlmaLinux_WWW_Container",
"overrideCommand": false,
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "hugo_extended",
"VERSION": "v0.141.0",
"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": "alma_www_user",
"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"
}
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ This website is built with the [Hugo](https://gohugo.io/) web framework.

## Contributing

We welcome contributions to the website in the form of website updates and design improvements, as well as translations. We've provided specific instructions on how to contribute for each part of the website.
We welcome contributions to the website in the form of website updates and design improvements, as well as translations. We've provided specific instructions on how to contribute for each part of the website.

- Blog content, please see [Contributing - Blog Posts](https://github.com/AlmaLinux/almalinux.org/blob/master/contributing-blog-posts.md)
- Help with our Hugo implementation or design improvements, please see [Contributing - Code and Design](#contributing-code-and-design)
- To help with translations, please see [Contributing - Translations](#localization-and-translation)

## Contributing - Code and Design

All of the development of the AlmaLinux website is done through this repo on GitHub.
All of the development of the AlmaLinux website is done through this repo on GitHub.

### Reporting a Bug

Good bug reports can be very helpful. A bug is a demonstrable problem with the code or functionality.

Please use the [GitHub issues](https://github.com/AlmaLinux/almalinux.org/issues) and check if the issue has already been reported. A good bug report should be as detailed as possible, so that others won't have to follow up for the essential details.
Please use the [GitHub issues](https://github.com/AlmaLinux/almalinux.org/issues) and check if the issue has already been reported. A good bug report should be as detailed as possible, so that others won't have to follow up for the essential details.

### Requesting a Feature

Expand All @@ -37,24 +37,30 @@ This is necessary to avoid more than one contributor working on the same feature

For smaller contributions use this workflow:

* Create an [issue](https://github.com/AlmaLinux/almalinux.org/issues) describing the changes.
* Await confirmation from contributors.
* Fork the project.
* Create a branch for your feature or bug fix.
* Add code changes, relevant documentation, etc.
* Send a pull request. All PRs should be made against the `master` branch. Once your pull PR is approved, a dev site will be automatically created based on the PR.
- Create an [issue](https://github.com/AlmaLinux/almalinux.org/issues) describing the changes.
- Await confirmation from contributors.
- Fork the project.
- Create a branch for your feature or bug fix.
- Add code changes, relevant documentation, etc.
- Send a pull request. All PRs should be made against the `master` branch. Once your pull PR is approved, a dev site will be automatically created based on the PR.

After one of the contributors has checked and approved the changes, they will be merged into master branch and will be automatically deployed to the live site.

#### For developers

##### Local Development

To deploy local development environment, you will need following dependencies installed on your development host:

- hugo

Executing `hugo server` will deploy a nearly complete, ready to go local development environment.

Localization is important to us, and including localization formatting in your PR will be required. After you have formatted your text correctly, please run `find_missing_i18n_strings.py` and `setup-pages-for-supported-languages.py`, and then commit the changes to your branch. If you notice any issues with this script, please create an [issue](https://github.com/AlmaLinux/almalinux.org/issues) with details about the problem.
Localization is important to us, and including localization formatting in your PR will be required. After you have formatted your text correctly, please run `find_missing_i18n_strings.py` and `setup-pages-for-supported-languages.py`, and then commit the changes to your branch. If you notice any issues with this script, please create an [issue](https://github.com/AlmaLinux/almalinux.org/issues) with details about the problem.

##### Container Development

To deploy a container based development environment you will need docker installed and an editor that supports the devcontainer standard. Further details on the container setup can be found in the [README](.devcontainer/README.md).

#### Directories and modules

Expand All @@ -69,7 +75,7 @@ Localization is important to us, and including localization formatting in your P

### Localization and translation

almaLinux.org localization and translation is managed using [Weblate](https://hosted.weblate.org/engage/almalinux/). To contribute translations join the [AlmaLinux](https://hosted.weblate.org/projects/almalinux/) localization project in Weblate. Translations submitted through Weblate are automatically submitted to this repo as a pull request. Those pull requests are then reviewed by a member of the marketing SIG or another team lead, and merged as appropriate.
almaLinux.org localization and translation is managed using [Weblate](https://hosted.weblate.org/engage/almalinux/). To contribute translations join the [AlmaLinux](https://hosted.weblate.org/projects/almalinux/) localization project in Weblate. Translations submitted through Weblate are automatically submitted to this repo as a pull request. Those pull requests are then reviewed by a member of the marketing SIG or another team lead, and merged as appropriate.

You can request new languages to be added by creating a ticket in [GitHub issues](https://github.com/AlmaLinux/almalinux.org/issues).

Expand Down
Loading