Skip to content
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

Add docker image for the dotfiles #63

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1.2

FROM mcr.microsoft.com/devcontainers/base:1-ubuntu-22.04

SHELL [ "/bin/bash", "-euxo", "pipefail", "-c" ]

ENV USER="vscode"
ENV HOME="/home/${USER}"
ENV PATH="${HOME}/.local/bin:${PATH}"

USER "${USER}"
WORKDIR "${HOME}"

RUN --mount=type=bind,target=/tmp/dotfiles,rw \
export DOTFILES_DOCKERFILE=true; \
export DOTFILES_ONE_SHOT=true; \
/tmp/dotfiles/install.sh; \
sudo rm -rf /var/lib/apt/lists/*
2 changes: 2 additions & 0 deletions home/.chezmoi.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{- $wsl := or (env "WSL_DISTRO_NAME") (env "IS_WSL") | not | not -}}
{{- $devcontainer := or (env "REMOTE_CONTAINERS") (env "CODESPACES") (env "VSCODE_REMOTE_CONTAINERS_SESSION") (env "GITPOD_HOST") | not | not -}}
{{- $gnome := lookPath "gnome-shell" | not | not -}}
{{- $dockerfile := env "DOTFILES_DOCKERFILE" | not | not -}}
{{- $headless := or (env "SSH_CLIENT" | not | not) (not (or (env "DISPLAY") (env "WAYLAND_DISPLAY"))) -}}

{{- $minimum := or $devcontainer (not $ubuntu) -}}
Expand Down Expand Up @@ -97,6 +98,7 @@ data:
is_wsl: {{ $wsl }}
is_devcontainer: {{ $minimum }}
is_gnome: {{ $gnome }}
is_dockerfile: {{ $dockerfile }}
is_headless: {{ $headless }}

name: "{{ $name }}"
Expand Down
6 changes: 6 additions & 0 deletions home/.chezmoiignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
.chezmoiscripts/*-install-gnome-extensions.sh
{{- end }}

{{ if .is_dockerfile }}
# The .gitconfig will be copied from the host machine by VS Code
.gitconfig
repos/
{{ end }}

# waiting for chezmoi to leverage .gitignore from archives:
# https://github.com/twpayne/chezmoi/issues/1421#issuecomment-964473844
.oh-my-zsh/cache/*
Expand Down
5 changes: 5 additions & 0 deletions home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ for i in "${!original_args[@]}"; do
continue
fi

# --one-shot is not compatible with apply
if [[ "${original_args[i]}" == "--one-shot" ]]; then
continue
fi

# Remove any positional args, as we will always use apply
if [[ "${original_args[i]}" != "-"* ]]; then
continue
Expand Down
7 changes: 7 additions & 0 deletions root/.chezmoiignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ etc/wsl.conf
.chezmoiscripts/*-fix-permissions.sh
.chezmoiscripts/*-restore-permissions.sh
{{ end }}


{{ if .is_dockerfile }}
usr/local/bin/git-credential-manager-core
etc/docker/
etc/gitconfig
{{ end }}
13 changes: 10 additions & 3 deletions root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ readonly wanted_packages=(
zip
git
jq
docker-ce
docker-ce-cli
containerd.io
docker-compose-plugin
docker-buildx-plugin
docker-scan-plugin
# {{ if not .is_dockerfile }}
docker-ce
containerd.io
asciinema
# {{ end }}
# {{ if .is_gnome }}
yaru-theme-gtk
yaru-theme-icon
Expand Down Expand Up @@ -63,5 +65,10 @@ if [[ ${#missing_packages[@]} -gt 0 ]]; then
log_task "Installing missing packages with APT: ${missing_packages[*]}"

c apt update --yes
c apt install --yes --install-recommends "${missing_packages[@]}"
# {{ if .is_dockerfile }}
extra_args=("--no-install-recommends")
# {{ else }}
extra_args=("--install-recommends")
# {{ end }}
c apt install --yes "${extra_args[@]}" "${missing_packages[@]}"
fi