Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

chore: docker fixes, including clean bootstrap #372

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tags
# Doom Nvim Contrib files
tools/doom-nvim-contrib
tools/local-share-nvim
tools/local-state
tools/workspace

# User modules
Expand Down
8 changes: 5 additions & 3 deletions lua/doom/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ modules.try_sync()
profiler.stop("framework|doom.core.modules")

-- Execute autocommand for user to hook custom config into
vim.api.nvim_exec_autocmds("User", {
pattern = "DoomStarted",
})
if not modules._needs_sync then
vim.api.nvim_exec_autocmds("User", {
pattern = "DoomStarted",
})
end

-- vim: fdm=marker
10 changes: 8 additions & 2 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV \
PATH="/home/doom/.local/bin:${PATH}"

# Update repositories
RUN pacman -Syy
RUN pacman -Syu --noconfirm

# Install neovim
RUN pacman -Sy neovim --noconfirm
Expand All @@ -25,7 +25,7 @@ RUN pacman -Sy neovim --noconfirm
RUN pacman -Sy ripgrep nodejs-lts-fermium npm git bash gcc jq --noconfirm

# Lua
RUN pacman -Sy luacheck stylua --noconfirm
RUN pacman -Sy luacheck stylua lua-language-server --noconfirm

# Required for nvim-lsp-installer
RUN pacman -Sy wget unzip make --noconfirm
Expand All @@ -36,6 +36,12 @@ RUN npm i -g chokidar-cli
# Required for OCaml language
# RUN pacman -Sy opam diffutils patch ocaml --noconfirm

# For startup time profiling
RUN pacman -Sy hyperfine --noconfirm

# OCaml
RUN pacman -Sy opam diffutils patch ocaml --noconfirm

# Create the doom user and group
RUN groupadd doom
RUN useradd -m -g doom doom
Expand Down
9 changes: 9 additions & 0 deletions tools/docker_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
echo "Executing initial bootstrap/sync"
rm -f local-share-nvim/plugin/packer_compiled.lua
rm -f doom-nvim-contrib/plugin/packer_compiled.lua
rm -rf local-share-nvim/ local-state-nvim/
./start_docker.sh -- --rm --entrypoint='["/usr/bin/nvim","--headless","--cmd","autocmd User PackerComplete quitall","--cmd","autocmd User DoomStarted PackerSync"]'
./start_docker.sh -- --rm --entrypoint='["/usr/bin/nvim","--headless","--cmd","autocmd User PackerComplete quitall","--cmd","autocmd User DoomStarted PackerSync"]'
echo "Testing config"
exec ./start_docker.sh -- --rm --entrypoint='["/usr/bin/nvim","--headless","+qa"]'
7 changes: 7 additions & 0 deletions tools/docker_clean_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
rm local-share-nvim/ local-state-nvim/ -rf
rm -f doom-nvim-contrib/plugin/packer_compiled.lua
echo
echo "Bootstrapping packages"
echo
exec ./start_docker.sh -- --entrypoint='["/usr/bin/nvim","--headless","--cmd","autocmd User PackerComplete quitall"]'
36 changes: 22 additions & 14 deletions tools/start_docker.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env bash

if ! docker info > /dev/null 2>&1; then
DOCKER=$(command -v podman docker | head -n 1)
if ! "${DOCKER}" info > /dev/null 2>&1; then
echo "This script uses docker, and it isn't running - please start docker and try again!"
exit 1
fi

if [ $(basename "${DOCKER}") = "podman" ]; then
DOCKER_RUN_FLAGS="--userns=keep-id"
else
DOCKER_RUN_FLAGS=
fi

############################################################
# Help #
############################################################
Expand Down Expand Up @@ -40,6 +46,7 @@ while getopts "b:h" option; do
exit;;
esac
done
shift $((OPTIND-1))

cd "$SCRIPT_DIR" || exit

Expand Down Expand Up @@ -87,30 +94,31 @@ echo ""

echo "2. Setting up docker environment"
# Ensure docker image exists
if [[ ! "$(docker images -q doom-nvim-contrib)" ]]; then
if [[ ! "$("${DOCKER}" images -q doom-nvim-contrib)" ]]; then
echo " - Docker image does not exist. Building docker image..."
docker build -t doom-nvim-contrib .
"${DOCKER}" build -t doom-nvim-contrib . || exit
fi

if [ "$(docker ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then
if [ "$("${DOCKER}" ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then
echo " - Cleaning up old container..."
# cleanup
docker rm doom-nvim-contrib-container >> /dev/null
"${DOCKER}" rm doom-nvim-contrib-container >> /dev/null
fi

# Create docker container if haven't already
echo " - Success! Running docker container doom-nvim-contrib-container..."
mkdir -p "${SCRIPT_DIR}/local-share-nvim" "${SCRIPT_DIR}/workspace"
mkdir -p "${SCRIPT_DIR}/local-share-nvim" "${SCRIPT_DIR}/local-state" "${SCRIPT_DIR}/workspace"
echo ""
docker run \
${DOCKER} run \
${DOCKER_RUN_FLAGS} \
-it \
-e UID="1000" \
-e GID="1000" \
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim \
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim \
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace \
-v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim:Z \
-v "$SCRIPT_DIR"/local-state:/home/doom/.local/state:Z \
-v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim:Z \
-v "$SCRIPT_DIR"/workspace:/home/doom/workspace:Z \
--name doom-nvim-contrib-container \
--user doom \
doom-nvim-contrib


"$@" \
doom-nvim-contrib \