Skip to content

Commit

Permalink
Sqlc fix and general cleanup (#2)
Browse files Browse the repository at this point in the history
* remove lts check from version for sqlc

* cleanup template features

* update test feature matrix

* remove sqlc readme to be autogen

* fix if in install.sh

* adds debian base to test matrix

* only use devcontainer base images in tests for now

* removing extra deps

* no base image in test

* re-enable base images

* only use devcontainer images in test matrix
  • Loading branch information
nickzelei authored Sep 19, 2023
1 parent 121f1d6 commit a433e9d
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 516 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
strategy:
matrix:
features:
- color
- hello
- sqlc
baseImage:
- debian:latest
- ubuntu:latest
# - debian:latest
# - ubuntu:latest
- mcr.microsoft.com/devcontainers/base:ubuntu
- mcr.microsoft.com/devcontainers/base:debian
steps:
- uses: actions/checkout@v3

Expand All @@ -34,8 +34,7 @@ jobs:
strategy:
matrix:
features:
- color
- hello
- sqlc
steps:
- uses: actions/checkout@v3

Expand Down
26 changes: 0 additions & 26 deletions src/color/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions src/color/devcontainer-feature.json

This file was deleted.

26 changes: 0 additions & 26 deletions src/color/install.sh

This file was deleted.

26 changes: 0 additions & 26 deletions src/hello/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions src/hello/devcontainer-feature.json

This file was deleted.

29 changes: 0 additions & 29 deletions src/hello/install.sh

This file was deleted.

26 changes: 0 additions & 26 deletions src/sqlc/README.md

This file was deleted.

19 changes: 2 additions & 17 deletions src/sqlc/install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#!/bin/bash -i

VERSION="${VERSION:-"latest"}"
ORG="sqlc-dev"
REPO="sqlc"

set -e

binary_names="sqlc"

source ./library_scripts.sh
. ./library_scripts.sh

# nanolayer is a cli utility which keeps container layers as small as possible
# source code: https://github.com/devcontainers-contrib/nanolayer
Expand All @@ -17,22 +11,13 @@ source ./library_scripts.sh
# of the script
ensure_nanolayer nanolayer_location "v0.5.3"

# fetch latest version if needed
if [ "${VERSION}" = "latest" ] || [ "${VERSION}" = "lts" ]; then
tag=$(curl -s https://api.github.com/repos/$ORG/$REPO/releases/latest | jq -r .tag_name)
export VERSION="${tag:1}"
fi

$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-contrib/features/gh-release:1.0.21" \
--option repo='sqlc-dev/sqlc' \
--option binaryNames="$binary_names" \
--option binaryNames='sqlc' \
--option version="$VERSION" \
--option assetRegex='.*\.tar\.gz' \
--option libName='sqlc'



echo 'Done!'
69 changes: 21 additions & 48 deletions src/sqlc/library_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
#!/bin/bash -i

# MIT License
#
# Copyright (c) 2022 devcontainers-contrib
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


clean_download() {
# The purpose of this function is to download a file with minimal impact on contaier layer size
# 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
# 1. uninstall the downloader at the return of the function
Expand All @@ -37,7 +15,7 @@ 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)
Expand All @@ -46,7 +24,7 @@ clean_download() {
apt-get -y install --no-install-recommends wget ca-certificates
}

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

echo "removing wget"
Expand All @@ -57,15 +35,15 @@ 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

apk add --no-cache wget
}

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

echo "removing wget"
Expand Down Expand Up @@ -121,45 +99,39 @@ ensure_nanolayer() {
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 [ -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 @@ -183,7 +155,7 @@ ensure_nanolayer() {

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
Expand All @@ -193,6 +165,7 @@ ensure_nanolayer() {
fi

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

}

Loading

0 comments on commit a433e9d

Please sign in to comment.