diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8b54e6c..6792153 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -148,6 +148,42 @@ jobs: exit 1 fi + test-with-registry-with-delete-rights: + strategy: + matrix: + version: + - v0.17.0 + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Create kind cluster with registry + uses: ./ + with: + version: "${{ matrix.version }}" + registry_delete: true + + - name: Test + run: | + kubectl cluster-info + kubectl get storageclass standard + + # Checking env variable + if [[ "$KIND_REGISTRY" != "kind-registry:5000" ]]; then + echo "Wrong KIND_REGISTRY env variable: $KIND_REGISTRY" + exit 1 + fi + + # Test registry usage inside cluster + docker pull busybox + docker tag busybox kind-registry:5000/localbusybox + + # Test delete API + DIGEST=$(docker push kind-registry:5000/localbusybox | grep -o -P '(?<=digest: ).*(?= size)') + exit $(curl -X DELETE kind-registry:5000/v2/localbusybox/manifests/$DIGEST) + test-knative: strategy: matrix: diff --git a/README.md b/README.md index cc9cb55..e3a86e7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `wait`: The duration to wait for the control plane to become ready (default: `60s`) - `log_level`: The log level for KinD - `registry`: Configures an insecure registry on `kind-registry:5000` to be used with KinD (default: `true`) +- `registry_delete`: Set to true to enable delete operations on the Image Registry (default is `false`) - `kubectl_version`: The kubectl version to use (default: `v1.26.1`) - `knative_serving`: The version of Knative Serving to install on the Kind cluster (not installed by default - example: `v1.0.0`) - `knative_kourier`: The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: `v1.0.0`) diff --git a/action.yml b/action.yml index f5ada58..da7dc09 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,8 @@ inputs: description: "The log level for KinD" registry: description: "Configures an insecure registry on kind-registry:5000 to be used with KinD (default: true)" + registry_delete: + description: "Enables delete operations on the Image Registry (default is false)" kubectl_version: description: "The version of kubectl to use (default: v1.26.1)" knative_serving: diff --git a/main.sh b/main.sh index 7433fbb..4481e6a 100755 --- a/main.sh +++ b/main.sh @@ -75,6 +75,11 @@ main() { args_registry+=(--memory "${INPUT_MEMORY}") fi + if [[ -n "${INPUT_REGISTRY_DELETE:-}" ]]; then + args_registry+=(--registry-delete "${INPUT_REGISTRY_DELETE}") + fi + + if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then if [[ ${#args_registry[@]} -gt 0 ]]; then "$SCRIPT_DIR/registry.sh" "${args_registry[@]}" diff --git a/registry.sh b/registry.sh index 29cfa8d..18981b3 100755 --- a/registry.sh +++ b/registry.sh @@ -35,6 +35,7 @@ Usage: $(basename "$0") --registry-image The registry image to use (default: $DEFAULT_REGISTRY_IMAGE) --registry-name The registry name to use (default: $DEFAULT_REGISTRY_NAME) --registry-port The local port used to bind the registry (default: $DEFAULT_REGISTRY_PORT) + --registry-delete Enable delete operations on the registry (default is false) -n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)" --document Document the local registry @@ -45,6 +46,7 @@ main() { local registry_image="$DEFAULT_REGISTRY_IMAGE" local registry_name="$DEFAULT_REGISTRY_NAME" local registry_port="$DEFAULT_REGISTRY_PORT" + local registry_delete="false" local cluster_name="$DEFAULT_CLUSTER_NAME" local cpu="$DEFAULT_CPU" local disk="$DEFAULT_DISK" @@ -132,6 +134,16 @@ parse_command_line() { exit 1 fi ;; + --registry-delete) + if [[ -n "${2:-}" ]]; then + registry_delete="$2" + shift + else + echo "ERROR: '--registry-delete' cannot be empty." >&2 + show_help + exit 1 + fi + ;; -n|--cluster-name) if [[ -n "${2:-}" ]]; then cluster_name="$2" @@ -170,9 +182,10 @@ install_docker() { } create_registry() { - echo "Creating registry \"$registry_name\" on port $registry_port from image \"$registry_image\"..." - docker run -d --restart=always -p "${registry_port}:5000" --name "${registry_name}" $registry_image > /dev/null - + echo "Creating registry \"$registry_name\" on port $registry_port from image \"$registry_image\" with delete enabled $registry_delete ..." + docker run -d --restart=always -p "${registry_port}:5000" -e "REGISTRY_STORAGE_DELETE_ENABLED=${registry_delete}" --name "${registry_name}" $registry_image +> /dev/null + # Adding registry to /etc/hosts echo "127.0.0.1 $registry_name" | sudo tee -a /etc/hosts