Skip to content

Commit 440e0bf

Browse files
Add elixir-project Feature
1 parent 3c0613e commit 440e0bf

5 files changed

Lines changed: 127 additions & 0 deletions

File tree

src/elixir-project/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# elixir-project
2+
3+
An opinionated, batteries-included Dev Container Feature for Elixir projects.
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/CargoSense/devcontainer-features/elixir-project:1": {}
10+
}
11+
```
12+
13+
## OS Support
14+
15+
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions.
16+
17+
`bash` is required to execute the `install.sh` script.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"id": "elixir-project",
3+
"version": "1.0.0",
4+
"name": "elixir-project",
5+
"description": "An opinionated, batteries-included Dev Container Feature for Elixir projects.",
6+
"documentationURL": "https://github.com/CargoSense/devcontainer-features/tree/main/src/elixir-project",
7+
"licenseURL": "https://github.com/CargoSense/devcontainer-features/blob/main/LICENSE",
8+
"containerEnv": {
9+
"LESS": "-FMR",
10+
"PAGER": "less"
11+
},
12+
"customizations": {
13+
"vscode": {
14+
"extensions": [
15+
"ExpertLSP.expert"
16+
],
17+
"settings": {
18+
"[elixir]": {
19+
"editor.formatOnSave": true
20+
},
21+
"editor.tabSize": 2,
22+
"files": {
23+
"insertFinalNewline": true,
24+
"trimFinalNewlines": true,
25+
"trimTrailingWhitespace": true
26+
}
27+
}
28+
}
29+
},
30+
"dependsOn": {
31+
"ghcr.io/devcontainers/features/common-utils:2": {
32+
"installZsh": false,
33+
"username": "vscode",
34+
"userUid": 1000,
35+
"userGid": 1000
36+
}
37+
},
38+
"mounts": [
39+
{
40+
"source": "build-cache-${devcontainerId}",
41+
"target": "${containerWorkspaceFolder}/_build",
42+
"type": "volume"
43+
},
44+
{
45+
"source": "dependency-cache-${devcontainerId}",
46+
"target": "${containerWorkspaceFolder}/deps",
47+
"type": "volume"
48+
},
49+
{
50+
"source": "expert-cache-${devcontainerId}",
51+
"target": "${containerWorkspaceFolder}/.expert",
52+
"type": "volume"
53+
}
54+
],
55+
"onCreateCommand": "CONTAINER_WORKSPACE_FOLDER=${containerWorkspaceFolder} /opt/cargosense/elixir-project/onCreateCommand.sh",
56+
"postCreateCommand": "sudo /opt/cargosense/elixir-project/postCreateCommand.sh"
57+
}

src/elixir-project/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
FEATURE_SCRIPTS_PATH="/opt/cargosense/elixir-project"
6+
7+
mkdir -p "${FEATURE_SCRIPTS_PATH}"
8+
9+
cp "${PWD}"/scripts/*.sh "${FEATURE_SCRIPTS_PATH}"
10+
chmod +x "${FEATURE_SCRIPTS_PATH}"/*.sh
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Set permissions on volume mounts
6+
sudo chown -R "${USER}":"${USER}" "${CONTAINER_WORKSPACE_FOLDER:?}"/{_build,deps,.expert}
7+
8+
# Create user Bash configuration directory
9+
BASHRC_DIR="${HOME}/.bashrc.d"
10+
11+
mkdir -p "${BASHRC_DIR}"
12+
chmod 700 "${BASHRC_DIR}"
13+
14+
# Configure environment variables that rely on `CONTAINER_WORKSPACE_FOLDER`
15+
cat << EOF > "${BASHRC_DIR}/elixir-project.bashrc"
16+
export HISTFILE="${CONTAINER_WORKSPACE_FOLDER}/.bash_history"
17+
export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\\"${CONTAINER_WORKSPACE_FOLDER}/.iex_history\\"'"
18+
EOF
19+
20+
chmod +x "${BASHRC_DIR}/elixir-project.bashrc"
21+
22+
BASHRC_FILE="${HOME}/.bashrc"
23+
BASHRC_LINE="for file in \"\${HOME}\"/.bashrc.d/*.bashrc; do source \"\${file}\"; done"
24+
25+
grep -qxF "${BASHRC_LINE}" "${BASHRC_FILE}" || echo "${BASHRC_LINE}" >> "${BASHRC_FILE}"
26+
27+
# Configure workspace `.gitignore`
28+
GITIGNORE_FILE="${CONTAINER_WORKSPACE_FOLDER}/.gitignore"
29+
GITIGNORE_LINES=(.bash_history /_build /.expert /.iex_history /deps)
30+
31+
touch "${GITIGNORE_FILE}"
32+
33+
for line in "${GITIGNORE_LINES[@]}"; do
34+
grep -qxF "${line}" "${GITIGNORE_FILE}" || echo "${line}" >> "${GITIGNORE_FILE}"
35+
done
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
FEATURE_SCRIPTS_PATH="/opt/cargosense/elixir-project"
6+
7+
rm -rf "${FEATURE_SCRIPTS_PATH}"
8+
rmdir --ignore-fail-on-non-empty "$(dirname "${FEATURE_SCRIPTS_PATH}")"

0 commit comments

Comments
 (0)