Skip to content

Commit 3def2d3

Browse files
authored
feat: install basic tooling
1 parent ee3307a commit 3def2d3

8 files changed

Lines changed: 508 additions & 23 deletions

File tree

.devcontainer/Brewfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
brew "bash-completion@2"
2+
brew "direnv"
3+
brew "fd"
4+
brew "gcc"
5+
brew "gh"
6+
brew "git"
7+
brew "moreutils"
8+
brew "the_silver_searcher"
9+
10+
# TODO
11+
# -----------------------------------------------------------------------------
12+
13+
# - [ ] ripgrep
14+
# - [ ] fzf
15+
# - [ ] Install https://github.com/junegunn/fzf in devcontainer
16+
# - [ ] Install hooks in dotfiles repo

.devcontainer/Brewfile.lock.json

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.

.devcontainer/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Use the latest Debian release
22
FROM mcr.microsoft.com/vscode/devcontainers/base:bullseye as base
33

4+
ENV HOMEBREW_INSTALL_FROM_API='true'
45
ENV BREW_BIN='/home/linuxbrew/.linuxbrew/bin'
6+
ENV BREW_SBIN='/home/linuxbrew/.linuxbrew/sbin'
57
ENV SYS_PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
6-
ENV PATH="${BREW_BIN}:${SYS_PATH}"
8+
ENV PATH="${BREW_SBIN}:${BREW_BIN}:${SYS_PATH}"
79

810
COPY . /opt/devcontainer
911
WORKDIR /opt/devcontainer
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh -ex
2+
3+
# Fix Homebrew ownership
4+
# =============================================================================
5+
6+
# Allow the current user to make changes to Homebrew by changing ownership of
7+
# the `HOMEBREW_PREFIX` directory and its contents to the current user
8+
9+
if test -z "${HOMEBREW_PREFIX:=}"; then
10+
HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew"
11+
fi
12+
13+
whoami="$(whoami)"
14+
15+
sudo chown -R "${whoami}" "${HOMEBREW_PREFIX}"

.devcontainer/run.d/01_npm.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/bash -e
22

3+
sudo npm update --global
4+
5+
# Install `shellcheck` and `shfmt` independently from Trunk to avoid VS Code
6+
# extension errors when editing shell scripts outside of a Trunk project or
7+
# before initializing Trunk.
8+
39
npm install --global \
10+
shellcheck \
11+
shfmt \
412
trunk

.devcontainer/run.d/02_homebrew.sh

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
#!/bin/sh -e
1+
#!/bin/sh -ex
22

33
GH_RAW_URL=https://raw.githubusercontent.com
44
INSTALL_SCRIPT=install.sh
55
INSTALL_URL="${GH_RAW_URL}/Homebrew/install/HEAD/${INSTALL_SCRIPT}"
66

77
# Signal to the Homebrew installer that we can run as root
8-
touch /.dockerenv
8+
sudo touch /.dockerenv
99

1010
tmp_dir="$(mktemp -d)"
1111
clean() { rm -rf "${tmp_dir}"; }
1212
trap clean EXIT
1313

14-
cd "${tmp_dir}"
15-
wget -q "${INSTALL_URL}" -O "${INSTALL_SCRIPT}"
16-
chmod 755 "${INSTALL_SCRIPT}"
17-
NONINTERACTIVE=false
18-
export NONINTERACTIVE
19-
HOMEBREW_INSTALL_FROM_API=true
20-
export HOMEBREW_INSTALL_FROM_API
21-
"./${INSTALL_SCRIPT}"
14+
# Run the installation in a subshell to allow us to snap back to the original
15+
# working directory on exit
16+
(
17+
cd "${tmp_dir}"
18+
wget -q "${INSTALL_URL}" -O "${INSTALL_SCRIPT}"
19+
chmod 755 "${INSTALL_SCRIPT}"
20+
NONINTERACTIVE=false
21+
export NONINTERACTIVE
22+
HOMEBREW_INSTALL_FROM_API=true
23+
export HOMEBREW_INSTALL_FROM_API
24+
"./${INSTALL_SCRIPT}"
25+
)
2226

23-
brew install \
24-
bash-completion@2 \
25-
direnv \
26-
gcc \
27-
gh \
28-
git
27+
# Get absolute path to script directory
28+
script_path="$(realpath "${0}")"
29+
script_dir="$(dirname "${script_path}")"
30+
31+
# Fix Homebrew owner
32+
"${script_dir}/../fix-homebrew-owner.sh"
33+
34+
brew update
35+
brew bundle
36+
brew doctor

.devcontainer/update-content.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
#!/bin/sh -ex
22

3+
# Update content
4+
# ============================================================================
5+
36
# Run whenever the contents of the workspace mount are updated
47
# https://containers.dev/implementors/json_reference/#lifecycle-scripts
58

6-
workspace_dir="${1:=}"
7-
9+
# Print help if no argument is provided
10+
workspace_dir="${1}"
811
if test -z "${workspace_dir}"; then
912
echo "Usage: ${0} WORKSPACE_DIR" >&2
1013
exit 1
1114
fi
1215

13-
# Remove ACLs on files in the workspace mount so that the default system umask
14-
# is respected
15-
# https://github.com/orgs/community/discussions/26026#discussioncomment-3250078
1616
whoami="$(whoami)"
17+
18+
# Fix workspace umask
19+
# ----------------------------------------------------------------------------
20+
21+
# After applying the changes below, the current user's default umask will
22+
# be respected for all files in the workspace directory
23+
24+
# Change the ownership of the workspace directory and its contents to the
25+
# current user
1726
sudo chown -R "${whoami}" "${workspace_dir}"
27+
# Remove all extended ACL entries (preserved by Docker during mount)
1828
sudo setfacl -bnR "${workspace_dir}"
1929

30+
# Fix Homebrew ownership
31+
# ----------------------------------------------------------------------------
32+
33+
./fix-homebrew-owner.sh
34+
35+
# Allow direnv
36+
# ----------------------------------------------------------------------------
37+
2038
# The `PATH` variable set in Dockerfile should be picked up when image is built
2139
# and used as devcontainer (but it seems this is not the case)
2240
echo "${PATH}"

.trunk/trunk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ lint:
1414
- gitleaks@8.16.3
1515
- hadolint@2.12.0
1616
- prettier@2.8.8
17-
- semgrep@1.20.0
17+
- semgrep@1.21.0
1818
- shellcheck@0.9.0
1919
- shfmt@3.5.0
2020
- yamllint@1.31.0

0 commit comments

Comments
 (0)