diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3dbaf18..dabe728 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,7 @@ jobs: features: - bitwarden-cli - bitwarden-secrets-manager + - vault baseImage: - debian:latest - ubuntu:latest @@ -29,6 +30,27 @@ jobs: - name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'" run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} . + test-autogenerated-ruby: + runs-on: ubuntu-latest + continue-on-error: false + strategy: + fail-fast: false + matrix: + features: + - kamal + baseImage: + - mcr.microsoft.com/devcontainers/ruby:latest + - ghcr.io/rails/devcontainer/images/ruby:3.4.2 + steps: + - uses: actions/checkout@v4 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'" + run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} . + + test-scenarios: runs-on: ubuntu-latest continue-on-error: false @@ -37,6 +59,8 @@ jobs: features: - bitwarden-cli - bitwarden-secrets-manager + - vault + - kamal steps: - uses: actions/checkout@v4 diff --git a/bin/test_autogenerated b/bin/test_autogenerated index 57fc858..c3b7539 100755 --- a/bin/test_autogenerated +++ b/bin/test_autogenerated @@ -7,14 +7,31 @@ set -o nounset SCRIPT_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) BASE_PATH=$( cd -- "$( dirname -- "${SCRIPT_PATH}" )" &> /dev/null && pwd ) -BASE_IMAGE="${BASE_IMAGE:-mcr.microsoft.com/devcontainers/base:ubuntu}" +BASE_IMAGE_DEFAULT="mcr.microsoft.com/devcontainers/base:ubuntu" +BASE_IMAGES='{ + "kamal": "mcr.microsoft.com/devcontainers/ruby:latest" +}' -PARAM_FEATURES= +error() { + echo "ERROR: $@" + echo "USAGE: $0 " + exit 1 +} -if [ $# -gt 0 ]; then - PARAM_FEATURES="--features $@" +if [ $# -eq 0 ]; then + error "missing feature name" +elif [ $# -gt 1 ]; then + error "you can only test one feature at a time" +elif [[ $1 == +([0-9]) ]]; then + error "a number can't be a features name" fi +FEATURE="$1" +BASE_IMAGE="${BASE_IMAGE:-$(echo $BASE_IMAGES | jq --raw-output ".$FEATURE // empty")}" +BASE_IMAGE="${BASE_IMAGE:-$BASE_IMAGE_DEFAULT}" + cd $BASE_PATH -devcontainer features test --skip-scenarios --skip-duplicated $PARAM_FEATURES --base-image $BASE_IMAGE . +echo $BASE_IMAGE + +devcontainer features test --skip-scenarios --skip-duplicated --features $FEATURE --base-image $BASE_IMAGE --project-folder $BASE_PATH diff --git a/src/kamal/README.md b/src/kamal/README.md new file mode 100644 index 0000000..559ef79 --- /dev/null +++ b/src/kamal/README.md @@ -0,0 +1,24 @@ + +# Kamal Deploy (kamal) + +Installs Kamal Deploy directly via rubygems. + +## Example Usage + +```json +"features": { + "ghcr.io/RouL/devcontainer-features/kamal:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Provides the version to be installed. Defaults to newest available version. | string | - | + + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/RouL/devcontainer-features/blob/main/src/kamal/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/kamal/devcontainer-feature.json b/src/kamal/devcontainer-feature.json new file mode 100644 index 0000000..afd2ae6 --- /dev/null +++ b/src/kamal/devcontainer-feature.json @@ -0,0 +1,17 @@ +{ + "id": "kamal", + "version": "1.0.0", + "name": "Kamal Deploy", + "description": "Installs Kamal Deploy directly via rubygems.", + "installsAfter": [ + "ghcr.io/devcontainers/features/ruby", + "ghcr.io/devcontainers-extra/features/ruby-asdf" + ], + "options": { + "version": { + "description": "Provides the version to be installed. Defaults to newest available version.", + "type": "string", + "default": "" + } + } +} diff --git a/src/kamal/install.sh b/src/kamal/install.sh new file mode 100755 index 0000000..2838834 --- /dev/null +++ b/src/kamal/install.sh @@ -0,0 +1,55 @@ +#!/bin/sh +set -e + +GEM_NAME="kamal" +VERSION="${VERSION}" +USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" + +error() { + echo "$1" >&2 + echo "Exiting..." >&2 + exit 1 +} + +check_ruby_env() { + if command -v ruby > /dev/null; then + export RUBY_ENV="ruby" + elif command -v rbenv > /dev/null; then + export RUBY_ENV="rbenv" + else + error "ERROR: Couldn't find ruby" + fi +} + +gem_install() { + PARAMS="$@" + + case $RUBY_ENV in + ruby) + su $USERNAME -c "gem install $PARAMS" + ;; + rbenv) + su $USERNAME -c "rbenv exec gem install $PARAMS" + ;; + esac +} + +install() { + VERSION_PARAM= + if [ "$VERSION" != "" ]; then + VERSION_PARAM="--version $VERSION" + fi + + gem_install --no-document $VERSION_PARAM $GEM_NAME +} + +check_ruby_env + +echo "(*) Installing Kamal Deploy ($RUBY_ENV)..." + +install + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" diff --git a/test/kamal/functions.sh b/test/kamal/functions.sh new file mode 100644 index 0000000..0a5fc80 --- /dev/null +++ b/test/kamal/functions.sh @@ -0,0 +1,7 @@ +set -e + +check_kamal_version() { + VERSION="$1" + + check "kamal version == $VERSION" bash -c "kamal version | grep -E '^${VERSION//\./\\.}\$' > /dev/null" +} diff --git a/test/kamal/mcr-ruby3.3-kamal1.9.2.sh b/test/kamal/mcr-ruby3.3-kamal1.9.2.sh new file mode 100644 index 0000000..b4820e7 --- /dev/null +++ b/test/kamal/mcr-ruby3.3-kamal1.9.2.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "1.9.2" + +reportResults diff --git a/test/kamal/mcr-ruby3.3-kamal2.4.0.sh b/test/kamal/mcr-ruby3.3-kamal2.4.0.sh new file mode 100644 index 0000000..2f78a33 --- /dev/null +++ b/test/kamal/mcr-ruby3.3-kamal2.4.0.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "2.4.0" + +reportResults diff --git a/test/kamal/mcr-ruby3.3-kamal2.5.0.sh b/test/kamal/mcr-ruby3.3-kamal2.5.0.sh new file mode 100644 index 0000000..f35020d --- /dev/null +++ b/test/kamal/mcr-ruby3.3-kamal2.5.0.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "2.5.0" + +reportResults diff --git a/test/kamal/rails-ruby3.3.7-kamal2.5.0.sh b/test/kamal/rails-ruby3.3.7-kamal2.5.0.sh new file mode 100644 index 0000000..f35020d --- /dev/null +++ b/test/kamal/rails-ruby3.3.7-kamal2.5.0.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "2.5.0" + +reportResults diff --git a/test/kamal/rails-ruby3.4.2-kamal1.9.2.sh b/test/kamal/rails-ruby3.4.2-kamal1.9.2.sh new file mode 100644 index 0000000..b4820e7 --- /dev/null +++ b/test/kamal/rails-ruby3.4.2-kamal1.9.2.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "1.9.2" + +reportResults diff --git a/test/kamal/rails-ruby3.4.2-kamal2.5.0.sh b/test/kamal/rails-ruby3.4.2-kamal2.5.0.sh new file mode 100644 index 0000000..f35020d --- /dev/null +++ b/test/kamal/rails-ruby3.4.2-kamal2.5.0.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "2.5.0" + +reportResults diff --git a/test/kamal/scenarios.json b/test/kamal/scenarios.json new file mode 100644 index 0000000..8fb4c58 --- /dev/null +++ b/test/kamal/scenarios.json @@ -0,0 +1,50 @@ +{ + "mcr-ruby3.3-kamal2.5.0": { + "image": "mcr.microsoft.com/devcontainers/ruby:3.3", + "features": { + "kamal": { + "version": "2.5.0" + } + } + }, + "mcr-ruby3.3-kamal2.4.0": { + "image": "mcr.microsoft.com/devcontainers/ruby:3.3", + "features": { + "kamal": { + "version": "2.4.0" + } + } + }, + "mcr-ruby3.3-kamal1.9.2": { + "image": "mcr.microsoft.com/devcontainers/ruby:3.3", + "features": { + "kamal": { + "version": "1.9.2" + } + } + }, + "rails-ruby3.4.2-kamal2.5.0": { + "image": "ghcr.io/rails/devcontainer/images/ruby:3.4.2", + "features": { + "kamal": { + "version": "2.5.0" + } + } + }, + "rails-ruby3.4.2-kamal1.9.2": { + "image": "ghcr.io/rails/devcontainer/images/ruby:3.4.2", + "features": { + "kamal": { + "version": "1.9.2" + } + } + }, + "rails-ruby3.3.7-kamal2.5.0": { + "image": "ghcr.io/rails/devcontainer/images/ruby:3.3.7", + "features": { + "kamal": { + "version": "2.5.0" + } + } + } +} diff --git a/test/kamal/test.sh b/test/kamal/test.sh new file mode 100644 index 0000000..5d673e3 --- /dev/null +++ b/test/kamal/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +sudo apt-get update -y > /dev/null +sudo apt-get install -y curl jq ca-certificates > /dev/null + +CURRENT_VERSION="$(curl -L --no-progress-meter https://rubygems.org/api/v1/gems/kamal.json | jq --raw-output '.version')" + +source dev-container-features-test-lib +source functions.sh + +check_kamal_version "$CURRENT_VERSION" + +reportResults