-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devcontainers: add initial dev-container setup and scripts
- Loading branch information
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "exercism-generic", | ||
"image": "vpayno/ci-generic-debian:latest", | ||
"customizations": { | ||
"vscode": { | ||
"settings": {}, | ||
"extensions": [] | ||
} | ||
}, | ||
"portsAttributes": {}, | ||
"postCreateCommand": "cd /workspaces/exercism-workspace/; tree .devcontainer/; ./.devcontainer/scripts/dc-up-post-create-command.sh", | ||
"remoteUser": "root", | ||
"shutdownAction": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
declare devcontainer_id | ||
|
||
devcontainer_id="$(docker ps --format 'json' | jq -r '. | select(.Labels | contains("exercism-workspace")) | select(.Image == "vpayno/ci-generic-debian:latest") | .ID')" | ||
|
||
# delete old container | ||
if [[ -n ${devcontainer_id} ]]; then | ||
printf "Removing old container...\n" | ||
docker rm -f "${devcontainer_id}" | ||
printf "done.\n" | ||
fi | ||
printf "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -x | ||
|
||
if [[ -f ./.devcontainer/scripts/data.tmp ]]; then | ||
# shellcheck disable=SC1091 source=.devcontainer/scripts/data.tmp | ||
source ./.devcontainer/scripts/data.tmp | ||
fi | ||
|
||
if [[ ${1} == --root ]]; then | ||
devcontainer exec --workspace-folder "${PWD}" bash -i | ||
else | ||
devcontainer exec --workspace-folder "${PWD}" sudo -u "${devcontainer_username:-USER}" -i | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
# shellcheck disable=SC2120 | ||
rword() { | ||
local -a words | ||
local word | ||
local -i word_size=${1:-0} | ||
local -i tries | ||
|
||
mapfile -t words </usr/share/dict/words | ||
if [[ ${word_size} -le 7 ]]; then | ||
((word_size = (RANDOM % 11) + 5)) | ||
fi | ||
|
||
tries=0 | ||
while [[ ${#word} -le $((word_size - (RANDOM % 5))) ]] || [[ ${#word} -ge $((word_size - (RANDOM % 5))) ]]; do | ||
word=${words[$((RANDOM * (RANDOM % 2) + RANDOM * (RANDOM % 2 + 2)))]} | ||
((tries += 1)) | ||
[[ ${tries} -ge ${#words[@]} ]] && break | ||
done | ||
|
||
echo "${word}" | ||
} | ||
|
||
declare devcontainer_id | ||
|
||
devcontainer_id="$(docker ps --format 'json' | jq -r '. | select(.Labels | contains("exercism-workspace")) | select(.Image == "vpayno/ci-generic-debian:latest") | .ID')" | ||
|
||
declare -x devcontainer_username | ||
declare -x devcontainer_password | ||
declare -x -i devcontainer_uid | ||
declare -x -i devcontainer_gid | ||
|
||
# create data for setup scripts that run inside dev-container | ||
cat >./.devcontainer/scripts/data.tmp <<-EOF | ||
devcontainer_username="$(id --name --user)" | ||
devcontainer_password="$(rword)" | ||
devcontainer_uid="$(id --user)" | ||
devcontainer_gid="$(id --group)" | ||
EOF | ||
|
||
# delete old container | ||
if [[ -n ${devcontainer_id} ]]; then | ||
printf "Removing old container...\n" | ||
docker rm -f "${devcontainer_id}" | ||
printf "done.\n" | ||
fi | ||
printf "\n" | ||
|
||
# starts up container | ||
time devcontainer up --mount type=bind,source="${HOME}",target="${HOME}" --workspace-folder "${PWD}" | ||
printf "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
set -e | ||
|
||
# shellcheck disable=SC1091 source=.devcontainer/scripts/data.tmp | ||
source /workspaces/exercism-workspace/.devcontainer/scripts/data.tmp | ||
|
||
# shellcheck disable=SC2154 | ||
{ | ||
groupadd --gid "${devcontainer_gid}" "${devcontainer_username}" | ||
useradd --uid "${devcontainer_uid}" --gid "${devcontainer_gid}" --no-create-home --groups docker "${devcontainer_username}" | ||
chsh --shell /bin/bash "${devcontainer_username}" | ||
printf "%s\n%s\n" "${devcontainer_password}" "${devcontainer_password}" | passwd "${devcontainer_username}" | ||
id "${devcontainer_username}" | ||
} | ||
|
||
declare -a cargo_pkgs=( | ||
bacon | ||
cargo-fuzz | ||
cargo-generate | ||
cargo-scaffold | ||
cargo-spellcheck | ||
git-cliff | ||
irust | ||
ripgrep | ||
) | ||
|
||
# these commands also run as root | ||
|
||
cargo install --locked "${cargo_pkgs[@]}" | ||
printf "\n" | ||
|
||
rustup component add rust-analyzer | ||
printf "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,6 @@ rust/index.scip | |
# wasm | ||
node_modules/ | ||
package-lock.json | ||
|
||
# dev-container | ||
/.devcontainer/scripts/data.tmp |