Skip to content
Merged
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
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"features": {
"ghcr.io/CargoSense/devcontainer-features/shellcheck:1": {
"version": "1.1.0",
"resolved": "ghcr.io/cargosense/devcontainer-features/shellcheck@sha256:bd2efc29446b238a25771a5f80416d69e0f264d5c102c00f8b1de3da013c640d",
"integrity": "sha256:bd2efc29446b238a25771a5f80416d69e0f264d5c102c00f8b1de3da013c640d"
},
"ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {
"version": "1.0.1",
"resolved": "ghcr.io/devcontainers-extra/features/devcontainers-cli@sha256:855f5c6a10d1d1353fc3127216171653527f2dadaa50bee3ef4c55a261e19749",
"integrity": "sha256:855f5c6a10d1d1353fc3127216171653527f2dadaa50bee3ef4c55a261e19749"
},
"ghcr.io/devcontainers-extra/features/shfmt:1": {
"version": "1.0.2",
"resolved": "ghcr.io/devcontainers-extra/features/shfmt@sha256:9d87bdd69e7b37554488291e79b37a40d1e18beddfa151454570d5bf72423df8",
"integrity": "sha256:9d87bdd69e7b37554488291e79b37a40d1e18beddfa151454570d5bf72423df8"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "2.16.0",
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:31ef1bbfde793bcc62c52fa847c02a15fe659d69e48b2d8c1cfbd4db95f97cf7",
"integrity": "sha256:31ef1bbfde793bcc62c52fa847c02a15fe659d69e48b2d8c1cfbd4db95f97cf7"
}
}
}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
features:
- actionlint
- elixir-project
- google-cloud-cli
- node
- postgresql-client
Expand Down
17 changes: 17 additions & 0 deletions src/elixir-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# elixir-project

An opinionated, batteries-included Dev Container Feature for Elixir projects.

## Usage

```json
"features": {
"ghcr.io/CargoSense/devcontainer-features/elixir-project:1": {}
}
```

## OS Support

This Feature should work on recent versions of Debian/Ubuntu and Linux distributions.

`bash` is required to execute the `install.sh` script.
57 changes: 57 additions & 0 deletions src/elixir-project/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"id": "elixir-project",
"version": "1.0.0",
"name": "elixir-project",
"description": "An opinionated, batteries-included Dev Container Feature for Elixir projects.",
"documentationURL": "https://github.com/CargoSense/devcontainer-features/tree/main/src/elixir-project",
"licenseURL": "https://github.com/CargoSense/devcontainer-features/blob/main/LICENSE",
"containerEnv": {
"LESS": "-FMR",
"PAGER": "less"
},
"customizations": {
"vscode": {
"extensions": [
"ExpertLSP.expert"
],
"settings": {
"[elixir]": {
"editor.formatOnSave": true
},
"editor.tabSize": 2,
"files": {
"insertFinalNewline": true,
"trimFinalNewlines": true,
"trimTrailingWhitespace": true
}
}
}
},
"dependsOn": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": false,
"username": "vscode",
"userUid": 1000,
"userGid": 1000
}
},
"mounts": [
{
"source": "build-cache-${devcontainerId}",
"target": "${containerWorkspaceFolder}/_build",
"type": "volume"
},
{
"source": "dependency-cache-${devcontainerId}",
"target": "${containerWorkspaceFolder}/deps",
"type": "volume"
},
{
"source": "expert-cache-${devcontainerId}",
"target": "${containerWorkspaceFolder}/.expert",
"type": "volume"
}
],
"onCreateCommand": "CONTAINER_WORKSPACE_FOLDER=${containerWorkspaceFolder} /opt/cargosense/elixir-project/onCreateCommand.sh",
"postCreateCommand": "sudo /opt/cargosense/elixir-project/postCreateCommand.sh"
}
10 changes: 10 additions & 0 deletions src/elixir-project/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

FEATURE_SCRIPTS_PATH="/opt/cargosense/elixir-project"

mkdir -p "${FEATURE_SCRIPTS_PATH}"

cp "${PWD}"/scripts/*.sh "${FEATURE_SCRIPTS_PATH}"
chmod +x "${FEATURE_SCRIPTS_PATH}"/*.sh
35 changes: 35 additions & 0 deletions src/elixir-project/scripts/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

# Set permissions on volume mounts
sudo chown -R "${USER}":"${USER}" "${CONTAINER_WORKSPACE_FOLDER:?}"/{_build,deps,.expert}

# Create user Bash configuration directory
BASHRC_DIR="${HOME}/.bashrc.d"

mkdir -p "${BASHRC_DIR}"
chmod 700 "${BASHRC_DIR}"

# Configure environment variables that rely on `CONTAINER_WORKSPACE_FOLDER`
cat << EOF > "${BASHRC_DIR}/elixir-project.bashrc"
export HISTFILE="${CONTAINER_WORKSPACE_FOLDER}/.bash_history"
export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\\"${CONTAINER_WORKSPACE_FOLDER}/.iex_history\\"'"
EOF

chmod +x "${BASHRC_DIR}/elixir-project.bashrc"

BASHRC_FILE="${HOME}/.bashrc"
BASHRC_LINE="for file in \"\${HOME}\"/.bashrc.d/*.bashrc; do source \"\${file}\"; done"

grep -qxF "${BASHRC_LINE}" "${BASHRC_FILE}" || echo "${BASHRC_LINE}" >> "${BASHRC_FILE}"

# Configure workspace `.gitignore`
GITIGNORE_FILE="${CONTAINER_WORKSPACE_FOLDER}/.gitignore"
GITIGNORE_LINES=(.bash_history /_build /.expert /.iex_history /deps)

touch "${GITIGNORE_FILE}"

for line in "${GITIGNORE_LINES[@]}"; do
grep -qxF "${line}" "${GITIGNORE_FILE}" || echo "${line}" >> "${GITIGNORE_FILE}"
done
8 changes: 8 additions & 0 deletions src/elixir-project/scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

FEATURE_SCRIPTS_PATH="/opt/cargosense/elixir-project"

rm -rf "${FEATURE_SCRIPTS_PATH}"
rmdir --ignore-fail-on-non-empty "$(dirname "${FEATURE_SCRIPTS_PATH}")"
14 changes: 14 additions & 0 deletions test/elixir-project/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
check "environment" bash -c "env | grep ERL_AFLAGS"
check "gitignore" grep -xF .bash_history .gitignore

# Report result
reportResults