Skip to content

Commit c11104e

Browse files
committed
Add in a dockerfile
1 parent 3321bd1 commit c11104e

8 files changed

Lines changed: 180 additions & 3 deletions

.chezmoiignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ conda-env
44
terminal-app
55
requirements.txt
66
.shell-secrets
7+
docker
8+
.dockerignore
79

810
{{- if ne .chezmoi.os "darwin" }}
911
.config/karabiner

.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Git
2+
.git
3+
.github
4+
5+
# Docker
6+
docker/
7+
8+
# Documentation
9+
README.md
10+
LICENSE.md
11+
12+
# IDE
13+
.vscode
14+
.idea
15+
16+
# Temporary files
17+
*.log
18+
*.tmp
19+
*.swp
20+
*~

bin/executable_install_bootstrap_dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ elif [[ "$OS" == "Linux" ]]; then
1818
make \
1919
wget \
2020
llvm \
21+
emacs \
2122
build-essential \
2223
libbz2-dev \
2324
libreadline-dev \

docker/Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Dockerfile for chezmoi dotfiles environment
2+
# Based on the CI workflow for Ubuntu
3+
FROM ubuntu:24.04
4+
5+
# Avoid interactive prompts during build
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
8+
# Set default shell to bash for RUN commands
9+
SHELL ["/bin/bash", "-c"]
10+
11+
# Create a non-root user for development
12+
ARG USERNAME=marchdf
13+
ARG USER_UID=1001
14+
ARG USER_GID=$USER_UID
15+
16+
# Install minimal bootstrap dependencies
17+
RUN apt-get update && apt-get install -y \
18+
curl \
19+
sudo \
20+
git \
21+
locales \
22+
hunspell-en-us \
23+
&& locale-gen en_US.UTF-8 \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Set locale environment variables
27+
ENV LANG=en_US.UTF-8
28+
ENV LANGUAGE=en_US:en
29+
ENV LC_ALL=en_US.UTF-8
30+
31+
# Create the user with sudo privileges
32+
RUN groupadd --gid $USER_GID $USERNAME \
33+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
34+
&& mkdir -p /etc/sudoers.d \
35+
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
36+
&& chmod 0440 /etc/sudoers.d/$USERNAME
37+
38+
# Switch to the non-root user
39+
USER $USERNAME
40+
WORKDIR /home/$USERNAME
41+
42+
# Copy bootstrap script and run as user (with sudo)
43+
COPY --chown=$USERNAME:$USERNAME ../bin/executable_install_bootstrap_dependencies.sh /tmp/install_bootstrap.sh
44+
RUN bash /tmp/install_bootstrap.sh && rm /tmp/install_bootstrap.sh
45+
46+
# Ensure chezmoi is in PATH
47+
ENV PATH="/home/$USERNAME/.local/bin:${PATH}"
48+
49+
# Initialize chezmoi with dotfiles from GitHub
50+
RUN chezmoi init https://github.com/marchdf/dotfiles.git \
51+
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f \
52+
--promptString email="marchdf@docker-container.com" \
53+
&& chezmoi apply
54+
55+
# Pre-initialize zinit by running zsh once (this downloads all plugins)
56+
RUN zsh -i -c "exit"
57+
58+
# Pre-initialize Emacs by running in batch mode (installs all use-package packages)
59+
RUN emacs --batch -l ~/.emacs --eval "(message \"Emacs packages initialized\")"
60+
61+
# Set environment variables for interactive shell
62+
ENV TERM=xterm-256color
63+
ENV SHELL=/bin/zsh
64+
ENV IN_DOCKER=true
65+
66+
# Set the default shell to zsh
67+
CMD ["/bin/zsh", "-l"]

docker/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Docker setup for chezmoi dotfiles
2+
3+
This Dockerfile creates an Ubuntu-based development environment with all my dotfiles and CLI utilities configured via chezmoi.
4+
5+
## Quick start
6+
7+
From the `docker` directory:
8+
9+
```bash
10+
cd docker
11+
docker compose build
12+
docker compose run --rm ubuntu-marchdf
13+
```
14+
15+
## Pushing
16+
17+
```bash
18+
docker tag ubuntu-marchdf:latest ${REGISTRY}/${IMAGE_PATH}:${TAG}
19+
docker push ${REGISTRY}/${IMAGE_PATH}:${TAG}
20+
```
21+
22+
## Pulling
23+
24+
```bash
25+
docker pull ${REGISTRY}/${IMAGE_PATH}:${TAG}
26+
```
27+
28+
## Running
29+
30+
```bash
31+
cd $HOME/.local/share/chezmoi/docker
32+
docker compose up -d ubuntu-marchdf
33+
docker compose exec ubuntu-marchdf zsh
34+
```
35+
36+
# Stopping
37+
38+
```bash
39+
docker compose down
40+
```

docker/docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
ubuntu-marchdf:
3+
build:
4+
context: ..
5+
dockerfile: docker/Dockerfile
6+
args:
7+
USERNAME: marchdf
8+
USER_UID: 1001
9+
image: ubuntu-marchdf:latest
10+
container_name: ubuntu-marchdf-dev
11+
hostname: ubuntu-docker
12+
stdin_open: true
13+
tty: true
14+
volumes:
15+
- ubuntu-marchdf-home:/home/marchdf
16+
- ${HOME}:/host-home
17+
environment:
18+
- TERM=xterm-256color
19+
20+
volumes:
21+
ubuntu-marchdf-home:

dot_zshrc.tmpl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]
55
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
66
fi
77

8+
# Docker shares safe state from host home (cli history, zoxide, ssh)
9+
if [[ -n "$IN_DOCKER" ]] && [[ -d "/host-home" ]]; then
10+
if [[ -f "/host-home/.zsh_history" ]] && [[ ! -L "$HOME/.zsh_history" ]]; then
11+
[[ -f "$HOME/.zsh_history" ]] && rm "$HOME/.zsh_history"
12+
ln -sf /host-home/.zsh_history "$HOME/.zsh_history"
13+
fi
14+
15+
if [[ -f "/host-home/.local/share/db.zo" ]]; then
16+
mkdir -p "$HOME/.local/share"
17+
if [[ ! -L "$HOME/.local/share/db.zo" ]]; then
18+
[[ -f "$HOME/.local/share/db.zo" ]] && rm "$HOME/.local/share/db.zo"
19+
ln -sf /host-home/.local/share/db.zo "$HOME/.local/share/db.zo"
20+
fi
21+
fi
22+
23+
if [[ -d "/host-home/.ssh" ]] && [[ ! -L "$HOME/.ssh" ]]; then
24+
[[ -d "$HOME/.ssh" ]] && rm -rf "$HOME/.ssh"
25+
ln -sf /host-home/.ssh "$HOME/.ssh"
26+
fi
27+
fi
28+
829
### Added by Zinit's installer
930
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
1031
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
@@ -99,7 +120,7 @@ fi
99120
{{- end }}
100121

101122
# towards the beginning to make sure some software is loaded
102-
zinit lucid light-mode for "hpc"
123+
zinit lucid atload'unalias zi' light-mode for "hpc"
103124

104125
zinit ice lucid depth"1"
105126
zinit light romkatv/powerlevel10k
@@ -222,7 +243,12 @@ function backup_zoxide_database () {
222243
223244
backup_zoxide_database
224245
225-
[ -f "${HOME}/.shell-secrets" ] && source "${HOME}/.shell-secrets"
246+
# Source shell secrets (prefer host secrets when in Docker)
247+
if [[ -n "$IN_DOCKER" ]] && [[ -f "/host-home/.shell-secrets" ]]; then
248+
source "/host-home/.shell-secrets"
249+
elif [[ -f "${HOME}/.shell-secrets" ]]; then
250+
source "${HOME}/.shell-secrets"
251+
fi
226252
227253
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
228254
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

run_once_before_install-packages-linux.sh.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{- if eq .chezmoi.os "linux" -}}
22
#!/usr/bin/env bash
33

4-
if [[ ! -x "$(command -v pyenv)" ]]; then
4+
if [[ ! -x "$(command -v pyenv)" ]] && [[ ! -d "$HOME/.pyenv" ]]; then
55
curl https://pyenv.run | bash
66
fi
77

0 commit comments

Comments
 (0)