From caebbb4a9417bb51c2d5c45202eabd8c0c2191be Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 13 Jan 2022 09:38:56 -0300 Subject: [PATCH 1/2] Add docker image for the dotfiles --- Dockerfile | 20 +++++++++++++++++++ home/.chezmoi.yaml.tmpl | 2 ++ home/.chezmoiignore | 6 ++++++ root/.chezmoiexternal.yaml | 2 +- root/.chezmoiignore | 7 +++++++ .../run_after_10-install-apt-packages.sh.tmpl | 18 ++++++++++++----- 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3267e1b4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# syntax=docker/dockerfile:1.2 + +FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-20.04 + +SHELL [ "/bin/bash", "-euxo", "pipefail", "-c" ] + +ENV USER="vscode" +ENV HOME="/home/${USER}" +ENV PATH="${HOME}/.local/bin:${PATH}" + +ARG DEBIAN_FRONTEND="noninteractive" + +USER "${USER}" +WORKDIR "${HOME}" + +RUN --mount=type=bind,target=/tmp/dotfiles,rw \ + export DOTFILES_DOCKERFILE=true; \ + export DOTFILES_ONE_SHOT=true; \ + sh <(curl -fsSL https://git.io/chezmoi) init --one-shot --source /tmp/dotfiles; \ + sudo rm -rf /var/lib/apt/lists/* diff --git a/home/.chezmoi.yaml.tmpl b/home/.chezmoi.yaml.tmpl index 2b03893b..38d8dff8 100644 --- a/home/.chezmoi.yaml.tmpl +++ b/home/.chezmoi.yaml.tmpl @@ -21,6 +21,7 @@ {{- $isWsl := or (env "WSL_DISTRO_NAME") (env "IS_WSL") | not | not -}} {{- $isDevcontainer := or (env "REMOTE_CONTAINERS") (env "CODESPACES") (env "VSCODE_REMOTE_CONTAINERS_SESSION") | not | not -}} +{{- $isDockerfile := env "DOTFILES_DOCKERFILE" | not | not -}} {{- $isGnome := lookPath "gnome-shell" | not | not -}} {{- /* This retains the value passed with --source on chezmoi init, which is used in the ../install.sh script */ -}} @@ -38,6 +39,7 @@ data: is_work: {{ $isWork }} is_wsl: {{ $isWsl }} is_devcontainer: {{ $isDevcontainer }} + is_dockerfile: {{ $isDockerfile }} is_gnome: {{ $isGnome }} personal_name: "{{ $personalName }}" diff --git a/home/.chezmoiignore b/home/.chezmoiignore index 271f6097..10e45344 100644 --- a/home/.chezmoiignore +++ b/home/.chezmoiignore @@ -18,6 +18,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/* diff --git a/root/.chezmoiexternal.yaml b/root/.chezmoiexternal.yaml index 98341a41..08daef1e 100644 --- a/root/.chezmoiexternal.yaml +++ b/root/.chezmoiexternal.yaml @@ -70,7 +70,7 @@ type: archive url: "https://glare.vercel.app/GitCredentialManager/git-credential-manager@v{{ template "get-github-latest-version" list "GitCredentialManager/git-credential-manager" $cache }}/gcmcore-win-x86.+.zip$" exact: true -{{ else }} +{{ else if not .is_dockerfile }} "usr/local/share/gcm-core": type: archive url: "https://glare.vercel.app/GitCredentialManager/git-credential-manager@v{{ template "get-github-latest-version" list "GitCredentialManager/git-credential-manager" $cache }}/gcmcore-linux_amd64.+.tar.gz$" diff --git a/root/.chezmoiignore b/root/.chezmoiignore index adea0015..28a5b281 100644 --- a/root/.chezmoiignore +++ b/root/.chezmoiignore @@ -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 }} diff --git a/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl b/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl index 9a9bf4af..2467634d 100644 --- a/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl +++ b/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl @@ -20,14 +20,17 @@ readonly wanted_packages=( procps zip gzip + xz-utils git jq crudini - docker-ce - docker-ce-cli - containerd.io skopeo asciinema + docker-ce-cli + # {{ if not .is_dockerfile }} + docker-ce + containerd.io + # {{ end }} # {{ if .is_gnome }} yaru-theme-gtk yaru-theme-icon @@ -47,7 +50,7 @@ readonly wanted_packages=( gnome-menus # {{ end }} # {{ end }} - # {{ if not .is_wsl }} + # {{ if and (not .is_wsl) (not .is_dockerfile) }} # {{ if eq .chezmoi.osRelease.versionCodename "bionic" }} linux-generic-hwe-18.04 # {{ else if eq .chezmoi.osRelease.versionCodename "focal" }} @@ -67,5 +70,10 @@ if [[ ${#missing_packages[@]} -gt 0 ]]; then log_task "Installing missing packages with APT: ${missing_packages[*]}" c apt update - 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 From 94dcceb479be3515c2ed4511f0db19b0bf8d09e7 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 5 Sep 2023 21:04:15 -0300 Subject: [PATCH 2/2] Update some things --- Dockerfile | 6 ++---- home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl | 5 +++++ .../run_after_10-install-apt-packages.sh.tmpl | 5 +---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3267e1b4..de81056c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1.2 -FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-20.04 +FROM mcr.microsoft.com/devcontainers/base:1-ubuntu-22.04 SHELL [ "/bin/bash", "-euxo", "pipefail", "-c" ] @@ -8,13 +8,11 @@ ENV USER="vscode" ENV HOME="/home/${USER}" ENV PATH="${HOME}/.local/bin:${PATH}" -ARG DEBIAN_FRONTEND="noninteractive" - USER "${USER}" WORKDIR "${HOME}" RUN --mount=type=bind,target=/tmp/dotfiles,rw \ export DOTFILES_DOCKERFILE=true; \ export DOTFILES_ONE_SHOT=true; \ - sh <(curl -fsSL https://git.io/chezmoi) init --one-shot --source /tmp/dotfiles; \ + /tmp/dotfiles/install.sh; \ sudo rm -rf /var/lib/apt/lists/* diff --git a/home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl b/home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl index 248eaac9..63199692 100644 --- a/home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl +++ b/home/.chezmoiscripts/run_after_20-run-rootmoi.sh.tmpl @@ -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 diff --git a/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl b/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl index 3e385647..a08b2541 100644 --- a/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl +++ b/root/.chezmoiscripts/run_after_10-install-apt-packages.sh.tmpl @@ -21,17 +21,14 @@ readonly wanted_packages=( zip git jq - docker-ce docker-ce-cli - containerd.io docker-compose-plugin docker-buildx-plugin docker-scan-plugin - asciinema - docker-ce-cli # {{ if not .is_dockerfile }} docker-ce containerd.io + asciinema # {{ end }} # {{ if .is_gnome }} yaru-theme-gtk