From 379e22e239fff9029f91748c229f0d5251b0c7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Tue, 1 Oct 2024 13:05:00 +0200 Subject: [PATCH] chore: init repo --- .devcontainer.json | 25 ++++++++++ .github/dependabot.yml | 6 +++ .github/workflows/release.yaml | 47 +++++++++++++++++++ .github/workflows/test.yaml | 59 +++++++++++++++++++++++ .github/workflows/validate.yml | 16 +++++++ LICENSE | 21 +++++++++ README.md | 9 ++++ src/clusterctl/README.md | 20 ++++++++ src/clusterctl/devcontainer-feature.json | 19 ++++++++ src/clusterctl/install.sh | 60 ++++++++++++++++++++++++ test/clusterctl/test.sh | 46 ++++++++++++++++++ 11 files changed, 328 insertions(+) create mode 100644 .devcontainer.json create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 .github/workflows/validate.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 src/clusterctl/README.md create mode 100644 src/clusterctl/devcontainer-feature.json create mode 100755 src/clusterctl/install.sh create mode 100755 test/clusterctl/test.sh diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..06313b7 --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,25 @@ +{ + "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18", + "customizations": { + "vscode": { + "settings": { + "json.schemas": [ + { + "fileMatch": [ + "*/devcontainer-feature.json" + ], + "url": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainerFeature.schema.json" + } + ] + }, + "extensions": [ + "mads-hartmann.bash-ide-vscode" + ] + } + }, + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + }, + "remoteUser": "node", + "updateContentCommand": "npm install -g @devcontainers/cli" +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0056901 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..22509b2 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,47 @@ +name: "Release dev container features & Generate Documentation" +on: + workflow_dispatch: + +jobs: + deploy: + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + packages: write + steps: + - uses: actions/checkout@v4 + + - name: "Publish Features" + uses: devcontainers/action@v1 + with: + publish-features: "true" + base-path-to-features: "./src" + generate-docs: "true" + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create PR for Documentation + id: push_image_info + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -e + echo "Start." + # Configure git and Push updates + git config --global user.email github-actions@github.com + git config --global user.name github-actions + git config pull.rebase false + branch=automated-documentation-update-$GITHUB_RUN_ID + git checkout -b $branch + message='Automated documentation update' + # Add / update and commit + git add */**/README.md + git commit -m 'Automated documentation update [skip ci]' || export NO_UPDATES=true + # Push + if [ "$NO_UPDATES" != "true" ] ; then + git push origin "$branch" + gh pr create --title "$message" --body "$message" + fi diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..5efed1e --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,59 @@ +name: "CI - Test Features" +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + test-autogenerated: + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + features: + - buf-cli + - dart + baseImage: + - debian:latest + - ubuntu:latest + - mcr.microsoft.com/devcontainers/base:ubuntu + 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: true + strategy: + matrix: + features: + - buf-cli + - dart + + steps: + - uses: actions/checkout@v4 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Generating tests for '${{ matrix.features }}' scenarios" + run: devcontainer features test -f ${{ matrix.features }} --skip-autogenerated . + + test-global: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4 + + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + + - name: "Testing global scenarios" + run: devcontainer features test --global-scenarios-only . diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..863418e --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,16 @@ +name: "Validate devcontainer-feature.json files" +on: + workflow_dispatch: + pull_request: + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: "Validate devcontainer-feature.json files" + uses: devcontainers/action@v1 + with: + validate-only: "true" + base-path-to-features: "./src" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..35bef52 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Microsoft Corporation + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cd44f8f --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# A Dev Container Features Collection + +This repository is based on the +[the `devcontainers/features` repository](https://github.com/devcontainers/features). + +## Contents + +### [`clusterctl`](src/clusterctl/README.md) +Install the `clusterctl` CLI for the Cluster API. \ No newline at end of file diff --git a/src/clusterctl/README.md b/src/clusterctl/README.md new file mode 100644 index 0000000..db19505 --- /dev/null +++ b/src/clusterctl/README.md @@ -0,0 +1,20 @@ + +# `clusterctl` CLI + +The clusterctl CLI tool handles the lifecycle of a Cluster API management cluster. + +## Example Usage + +```json +"features": { + "ghcr.io/zeiss/devcontainer-features/clusterctl:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Choose your version | string | v1.8.3 | + + diff --git a/src/clusterctl/devcontainer-feature.json b/src/clusterctl/devcontainer-feature.json new file mode 100644 index 0000000..8a6d1aa --- /dev/null +++ b/src/clusterctl/devcontainer-feature.json @@ -0,0 +1,19 @@ +{ + "name": "clusterctl CLI", + "id": "clusterctl", + "version": "1.0.1", + "description": "The clusterctl CLI tool handles the lifecycle of a Cluster API management cluster.", + "options": { + "version": { + "type": "string", + "proposals": [ + "v1.8.3" + ], + "default": "v1.8.3", + "description": "Select or enter clusterctl version to install." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} \ No newline at end of file diff --git a/src/clusterctl/install.sh b/src/clusterctl/install.sh new file mode 100755 index 0000000..2de664e --- /dev/null +++ b/src/clusterctl/install.sh @@ -0,0 +1,60 @@ +#!/bin/sh +set -e + +echo "Activating feature 'clusterctl'" + +# Default version +VERSION=${VERSION:-"latest"} + +# Defailt install path +BIN=${BIN:-/usr/local/bin} + +echo "Installing clusterctl version $VERSION" + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Step 1, check if user is root" +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +echo "Step 2, check if architecture is supported" +architecture="$(uname -m)" +if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "${architecture}" != "arm64" ] && [ "${architecture}" != "aarch64" ]; then + echo "(!) Architecture $architecture unsupported" + exit 1 +fi + +apt_get_update() +{ + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +# Install dependencies +check_packages ca-certificates curl unzip + +# Install clusterctl + + +curl -sSL "https://github.com/kubernetes-sigs/cluster-api/releases/download/${VERSION}/clusterctl-linux-${architecture}" -o "${BIN}/clusterctl" +chmod +x "${BIN}/clusterctl" + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" \ No newline at end of file diff --git a/test/clusterctl/test.sh b/test/clusterctl/test.sh new file mode 100755 index 0000000..9cd1fdc --- /dev/null +++ b/test/clusterctl/test.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +# Clean up +rm -rf /var/lib/apt/lists/* + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root to be able to installe dependencies, changing to sudo when installing.' +fi + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + if [ "$(id -u)" -ne 0 ]; then + sudo apt-get update -y + else + apt-get update -y + fi + fi +} + +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + if [ "$(id -u)" -ne 0 ]; then + sudo apt-get -y install --no-install-recommends "$@" + else + apt-get -y install --no-install-recommends "$@" + fi + fi +} +export DEBIAN_FRONTEND=noninteractive + +check_packages ca-certificates curl unzip + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "version" clusterctl --version + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file