Skip to content

Commit 702a3d2

Browse files
committed
feat: add dingo
Signed-off-by: Simon Emms <simon@simonemms.com>
1 parent 6ba1461 commit 702a3d2

5 files changed

Lines changed: 288 additions & 0 deletions

File tree

src/dingo/NOTES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Dingo
2+
3+
A meta-language for Go that adds Result types, error propagation (?), and pattern
4+
matching while maintaining 100% Go ecosystem compatibility
5+
6+
## OS Support
7+
8+
This Feature should work on recent versions of Debian/Ubuntu-based distributions
9+
with the `apt` package manager installed. Golang is also required in the container.
10+
11+
`bash` is required to execute the `install.sh` script.

src/dingo/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Dingo (dingo)
2+
3+
A meta-language for Go that adds Result types, error propagation (?), and pattern matching while maintaining 100% Go ecosystem compatibility
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/mrsimonemms/devcontainers/dingo:1": {}
10+
}
11+
```
12+
13+
## Options
14+
15+
| Options Id | Description | Type | Default Value |
16+
|-----|-----|-----|-----|
17+
| version | Select the version you would like to install | string | latest |
18+
19+
## Dingo
20+
21+
A meta-language for Go that adds Result types, error propagation (?), and pattern
22+
matching while maintaining 100% Go ecosystem compatibility
23+
24+
## OS Support
25+
26+
This Feature should work on recent versions of Debian/Ubuntu-based distributions
27+
with the `apt` package manager installed. Golang is also required in the container.
28+
29+
`bash` is required to execute the `install.sh` script.
30+
31+
32+
---
33+
34+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/mrsimonemms/devcontainers/blob/main/src/dingo/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "Dingo",
3+
"version": "1.0.0",
4+
"id": "dingo",
5+
"description": "A meta-language for Go that adds Result types, error propagation (?), and pattern matching while maintaining 100% Go ecosystem compatibility",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"proposals": [
10+
"latest"
11+
],
12+
"default": "latest",
13+
"description": "Select the version you would like to install"
14+
}
15+
},
16+
"customizations": {
17+
"vscode": {
18+
"extensions": [
19+
"MadAppGang.dingo"
20+
]
21+
}
22+
},
23+
"installsAfter": [
24+
"ghcr.io/devcontainers/features/common-utils",
25+
"ghcr.io/devcontainers/features/go"
26+
]
27+
}

src/dingo/install.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 Simon Emms <simon@simonemms.com>
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
set -e
18+
19+
. ./library_scripts.sh
20+
21+
# nanolayer is a cli utility which keeps container layers as small as possible
22+
# source code: https://github.com/devcontainers-extra/nanolayer
23+
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
24+
# and if missing - will download a temporary copy that automatically get deleted at the end
25+
# of the script
26+
ensure_nanolayer nanolayer_location "v0.5.6"
27+
28+
$nanolayer_location \
29+
install \
30+
devcontainer-feature \
31+
"ghcr.io/devcontainers-extra/features/gh-release:1.0.25" \
32+
--option repo='MadAppGang/dingo' --option binaryNames='dingo' --option version="$VERSION"
33+
34+
echo 'Done!'

src/dingo/library_scripts.sh

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Copyright 2023 Simon Emms <simon@simonemms.com>
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
clean_download() {
16+
# The purpose of this function is to download a file with minimal impact on container layer size
17+
# this means if no valid downloader is found (curl or wget) then we install a downloader (currently wget) in a
18+
# temporary manner, and making sure to
19+
# 1. uninstall the downloader at the return of the function
20+
# 2. revert back any changes to the package installer database/cache (for example apt-get lists)
21+
# The above steps will minimize the leftovers being created while installing the downloader
22+
# Supported distros:
23+
# debian/ubuntu/alpine
24+
25+
url=$1
26+
output_location=$2
27+
tempdir=$(mktemp -d)
28+
downloader_installed=""
29+
30+
_apt_get_install() {
31+
tempdir=$1
32+
33+
# copy current state of apt list - in order to revert back later (minimize contianer layer size)
34+
cp -p -R /var/lib/apt/lists $tempdir
35+
apt-get update -y
36+
apt-get -y install --no-install-recommends wget ca-certificates
37+
}
38+
39+
_apt_get_cleanup() {
40+
tempdir=$1
41+
42+
echo "removing wget"
43+
apt-get -y purge wget --auto-remove
44+
45+
echo "revert back apt lists"
46+
rm -rf /var/lib/apt/lists/*
47+
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
48+
}
49+
50+
_apk_install() {
51+
tempdir=$1
52+
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
53+
cp -p -R /var/cache/apk $tempdir
54+
55+
apk add --no-cache wget
56+
}
57+
58+
_apk_cleanup() {
59+
tempdir=$1
60+
61+
echo "removing wget"
62+
apk del wget
63+
}
64+
# try to use either wget or curl if one of them already installer
65+
if type curl >/dev/null 2>&1; then
66+
downloader=curl
67+
elif type wget >/dev/null 2>&1; then
68+
downloader=wget
69+
else
70+
downloader=""
71+
fi
72+
73+
# in case none of them is installed, install wget temporarly
74+
if [ -z $downloader ] ; then
75+
if [ -x "/usr/bin/apt-get" ] ; then
76+
_apt_get_install $tempdir
77+
elif [ -x "/sbin/apk" ] ; then
78+
_apk_install $tempdir
79+
else
80+
echo "distro not supported"
81+
exit 1
82+
fi
83+
downloader="wget"
84+
downloader_installed="true"
85+
fi
86+
87+
if [ $downloader = "wget" ] ; then
88+
wget -q $url -O $output_location
89+
else
90+
curl -sfL $url -o $output_location
91+
fi
92+
93+
# NOTE: the cleanup procedure was not implemented using `trap X RETURN` only because
94+
# alpine lack bash, and RETURN is not a valid signal under sh shell
95+
if ! [ -z $downloader_installed ] ; then
96+
if [ -x "/usr/bin/apt-get" ] ; then
97+
_apt_get_cleanup $tempdir
98+
elif [ -x "/sbin/apk" ] ; then
99+
_apk_cleanup $tempdir
100+
else
101+
echo "distro not supported"
102+
exit 1
103+
fi
104+
fi
105+
106+
}
107+
108+
109+
ensure_nanolayer() {
110+
# Ensure existance of the nanolayer cli program
111+
local variable_name=$1
112+
113+
local required_version=$2
114+
115+
local __nanolayer_location=""
116+
117+
# If possible - try to use an already installed nanolayer
118+
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
119+
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
120+
if type nanolayer >/dev/null 2>&1; then
121+
echo "Found a pre-existing nanolayer in PATH"
122+
__nanolayer_location=nanolayer
123+
fi
124+
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
125+
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
126+
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
127+
fi
128+
129+
# make sure its of the required version
130+
if ! [ -z "${__nanolayer_location}" ]; then
131+
local current_version
132+
current_version=$($__nanolayer_location --version)
133+
134+
135+
if ! [ $current_version == $required_version ]; then
136+
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
137+
__nanolayer_location=""
138+
fi
139+
fi
140+
141+
fi
142+
143+
# If not previuse installation found, download it temporarly and delete at the end of the script
144+
if [ -z "${__nanolayer_location}" ]; then
145+
146+
if [ "$(uname -sm)" = 'Linux x86_64' ] || [ "$(uname -sm)" = "Linux aarch64" ]; then
147+
tmp_dir=$(mktemp -d -t nanolayer-XXXXXXXXXX)
148+
149+
clean_up () {
150+
ARG=$?
151+
rm -rf $tmp_dir
152+
exit $ARG
153+
}
154+
trap clean_up EXIT
155+
156+
157+
if [ -x "/sbin/apk" ] ; then
158+
clib_type=musl
159+
else
160+
clib_type=gnu
161+
fi
162+
163+
tar_filename=nanolayer-"$(uname -m)"-unknown-linux-$clib_type.tgz
164+
165+
# clean download will minimize leftover in case a downloaderlike wget or curl need to be installed
166+
clean_download https://github.com/devcontainers-extra/nanolayer/releases/download/$required_version/$tar_filename $tmp_dir/$tar_filename
167+
168+
tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
169+
chmod a+x $tmp_dir/nanolayer
170+
__nanolayer_location=$tmp_dir/nanolayer
171+
172+
173+
else
174+
echo "No binaries compiled for non-x86-linux architectures yet: $(uname -m)"
175+
exit 1
176+
fi
177+
fi
178+
179+
# Expose outside the resolved location
180+
export ${variable_name}=$__nanolayer_location
181+
182+
}

0 commit comments

Comments
 (0)