Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
style: standard formating (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbraun89 authored Dec 13, 2023
1 parent 7c6b27a commit 79fbfc5
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 54 deletions.
5 changes: 4 additions & 1 deletion src/composer/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Composer (via Github Releases)

# Composer (via Github Releases) (composer)

Composer is an open source dependency management tool for PHP.

Expand All @@ -15,3 +16,5 @@ Composer is an open source dependency management tool for PHP.
| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| version | Select the version to install. | string | latest |


2 changes: 1 addition & 1 deletion src/composer/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"installsAfter": [
"ghcr.io/devcontainers-contrib/features/gh-release"
]
}
}
11 changes: 7 additions & 4 deletions src/composer/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#!/bin/bash -i

set -e

. ./library_scripts.sh

# nanolayer is a cli utility which keeps container layers as small as possible
# source code: https://github.com/devcontainers-contrib/nanolayer
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# of the script
ensure_nanolayer nanolayer_location "v0.5.4"
ensure_nanolayer nanolayer_location "v0.5.5"


$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-contrib/features/gh-release:1.0.24" \
--option repo='composer/composer' --option binaryNames='composer' --option version="$VERSION"



echo 'Done!'

77 changes: 37 additions & 40 deletions src/composer/library_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash -i


clean_download() {
# The purpose of this function is to download a file with minimal impact on container layer size
# this means if no valid downloader is found (curl or wget) then we install a downloader (currently wget) in a
# temporary manner, and making sure to
# this means if no valid downloader is found (curl or wget) then we install a downloader (currently wget) in a
# temporary manner, and making sure to
# 1. uninstall the downloader at the return of the function
# 2. revert back any changes to the package installer database/cache (for example apt-get lists)
# The above steps will minimize the leftovers being created while installing the downloader
# The above steps will minimize the leftovers being created while installing the downloader
# Supported distros:
# debian/ubuntu/alpine

Expand All @@ -15,16 +15,16 @@ clean_download() {
tempdir=$(mktemp -d)
downloader_installed=""

function _apt_get_install() {
_apt_get_install() {
tempdir=$1

# copy current state of apt list - in order to revert back later (minimize contianer layer size)
cp -p -R /var/lib/apt/lists $tempdir
# copy current state of apt list - in order to revert back later (minimize contianer layer size)
cp -p -R /var/lib/apt/lists $tempdir
apt-get update -y
apt-get -y install --no-install-recommends wget ca-certificates
}

function _apt_get_cleanup() {
_apt_get_cleanup() {
tempdir=$1

echo "removing wget"
Expand All @@ -35,21 +35,20 @@ clean_download() {
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
}

function _apk_install() {
_apk_install() {
tempdir=$1
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
cp -p -R /var/cache/apk $tempdir
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
cp -p -R /var/cache/apk $tempdir

apk add --no-cache wget
}

function _apk_cleanup() {
_apk_cleanup() {
tempdir=$1

echo "removing wget"
apk del wget
apk del wget
}

# try to use either wget or curl if one of them already installer
if type curl >/dev/null 2>&1; then
downloader=curl
Expand All @@ -76,7 +75,7 @@ clean_download() {
if [ $downloader = "wget" ] ; then
wget -q $url -O $output_location
else
curl -sfL $url -o $output_location
curl -sfL $url -o $output_location
fi

# NOTE: the cleanup procedure was not implemented using `trap X RETURN` only because
Expand All @@ -90,54 +89,49 @@ clean_download() {
echo "distro not supported"
exit 1
fi
fi
fi

}


ensure_nanolayer() {
# Ensure existance of the nanolayer cli program
local variable_name=$1

local required_version=$2
# normalize version
if ! [[ $required_version == v* ]]; then
required_version=v$required_version
fi

local nanolayer_location=""
local __nanolayer_location=""

# If possible - try to use an already installed nanolayer
if [[ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]]; then
if [[ -z "${NANOLAYER_CLI_LOCATION}" ]]; then
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
if type nanolayer >/dev/null 2>&1; then
echo "Found a pre-existing nanolayer in PATH"
nanolayer_location=nanolayer
__nanolayer_location=nanolayer
fi
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
nanolayer_location=${NANOLAYER_CLI_LOCATION}
echo "Found a pre-existing nanolayer which were given in env variable: $nanolayer_location"
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
fi

# make sure its of the required version
if ! [[ -z "${nanolayer_location}" ]]; then
if ! [ -z "${__nanolayer_location}" ]; then
local current_version
current_version=$($nanolayer_location --version)
if ! [[ $current_version == v* ]]; then
current_version=v$current_version
fi
current_version=$($__nanolayer_location --version)


if ! [ $current_version == $required_version ]; then
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
nanolayer_location=""
__nanolayer_location=""
fi
fi

fi

# If not previuse installation found, download it temporarly and delete at the end of the script
if [[ -z "${nanolayer_location}" ]]; then
# If not previuse installation found, download it temporarly and delete at the end of the script
if [ -z "${__nanolayer_location}" ]; then

if [ "$(uname -sm)" == "Linux x86_64" ] || [ "$(uname -sm)" == "Linux aarch64" ]; then
if [ "$(uname -sm)" = 'Linux x86_64' ] || [ "$(uname -sm)" = "Linux aarch64" ]; then
tmp_dir=$(mktemp -d -t nanolayer-XXXXXXXXXX)

clean_up () {
Expand All @@ -147,7 +141,7 @@ ensure_nanolayer() {
}
trap clean_up EXIT


if [ -x "/sbin/apk" ] ; then
clib_type=musl
else
Expand All @@ -158,11 +152,11 @@ ensure_nanolayer() {

# clean download will minimize leftover in case a downloaderlike wget or curl need to be installed
clean_download https://github.com/devcontainers-contrib/cli/releases/download/$required_version/$tar_filename $tmp_dir/$tar_filename

tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
chmod a+x $tmp_dir/nanolayer
nanolayer_location=$tmp_dir/nanolayer

__nanolayer_location=$tmp_dir/nanolayer

else
echo "No binaries compiled for non-x86-linux architectures yet: $(uname -m)"
Expand All @@ -171,5 +165,8 @@ ensure_nanolayer() {
fi

# Expose outside the resolved location
declare -g ${variable_name}=$nanolayer_location
export ${variable_name}=$__nanolayer_location

}


1 change: 1 addition & 0 deletions src/sqlfluff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Fluff is an extensible and modular linter designed to help you write good SQL an
| version | Select the version to install. | string | latest |
| plugins | A space delimitered list of sqlfluff plugins (will be injected into the sqlfluff pipx env). See proposals for examples. | string | - |


4 changes: 2 additions & 2 deletions src/sqlfluff/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "sqlfluff",
"version": "1.0.1",
"version": "1.0.2",
"name": "SqlFluff (via pipx)",
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/sqlfluff",
"description": "Fluff is an extensible and modular linter designed to help you write good SQL and catch errors and bad SQL before it hits your database.",
Expand All @@ -27,4 +27,4 @@
"ghcr.io/devcontainers-contrib/features/pipx-package",
"ghcr.io/devcontainers/features/python"
]
}
}
10 changes: 5 additions & 5 deletions src/sqlfluff/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ set -e

# nanolayer is a cli utility which keeps container layers as small as possible
# source code: https://github.com/devcontainers-contrib/nanolayer
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# of the script
ensure_nanolayer nanolayer_location "v0.5.0"
ensure_nanolayer nanolayer_location "v0.5.5"


$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-contrib/features/pipx-package:1.1.7" \
--option package='sqlfluff' --option version="$VERSION" --option injections="$PLUGINS"

--option package='sqlfluff' --option injections="$PLUGINS" --option version="$VERSION"


echo 'Done!'
Expand Down
2 changes: 1 addition & 1 deletion test/composer/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"composer": {}
}
}
}
}

0 comments on commit 79fbfc5

Please sign in to comment.