├── .github └── workflows │ └── test.yaml ├── .gitignore ├── LICENSE ├── README.md ├── action.yml ├── cleanup.js ├── cleanup.sh ├── kind.sh ├── knative.sh ├── main.js ├── main.sh └── registry.sh /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | push: 8 | branches: 9 | - main 10 | schedule: 11 | - cron: "0 5 * * *" 12 | workflow_dispatch: 13 | inputs: 14 | 15 | concurrency: 16 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 17 | cancel-in-progress: true 18 | 19 | jobs: 20 | 21 | test-default: 22 | strategy: 23 | matrix: 24 | os: [ubuntu-latest, macos-13] 25 | runs-on: ${{ matrix.os }} 26 | steps: 27 | - name: Checkout 28 | uses: actions/checkout@v1 29 | 30 | - name: Create kind cluster 31 | uses: ./ 32 | 33 | - name: Test 34 | run: | 35 | kubectl cluster-info 36 | kubectl get storageclass standard 37 | 38 | test-with-custom-resource-limits: 39 | runs-on: macos-13 40 | steps: 41 | - name: Checkout 42 | uses: actions/checkout@v1 43 | 44 | - name: Create kind cluster with custom resource limits 45 | uses: ./ 46 | with: 47 | cpu: "3" 48 | disk: "5" 49 | memory: "11" 50 | - name: Test 51 | run: | 52 | kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="CPU:.status.capacity.cpu" | grep "3" 1> /dev/null && echo "CPU OK" 53 | kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="DISK:.status.capacity.ephemeral-storage" | grep -E "5\d{6}Ki" 1> /dev/null && echo "Disk OK" 54 | kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="MEMORY:.status.capacity.memory" | grep -E "11\d{6}Ki" 1> /dev/null && echo "Memory OK" 55 | 56 | test-with-custom-name: 57 | strategy: 58 | matrix: 59 | version: 60 | - v0.17.0 61 | - v0.16.0 62 | os: [ubuntu-latest, macos-13] 63 | runs-on: ${{ matrix.os }} 64 | steps: 65 | - name: Checkout 66 | uses: actions/checkout@v1 67 | 68 | - name: Create kind cluster with custom name and registry 69 | uses: ./ 70 | with: 71 | version: "${{ matrix.version }}" 72 | cluster_name: "custom-name" 73 | 74 | - name: Test 75 | run: | 76 | kubectl cluster-info 77 | kubectl get storageclass standard 78 | 79 | test-without-registry: 80 | strategy: 81 | matrix: 82 | version: 83 | - v0.17.0 84 | - v0.16.0 85 | os: [ubuntu-latest, macos-13] 86 | runs-on: ${{ matrix.os }} 87 | steps: 88 | - name: Checkout 89 | uses: actions/checkout@v1 90 | 91 | - name: Create kind cluster with custom name and without registry 92 | uses: ./ 93 | with: 94 | version: "${{ matrix.version }}" 95 | cluster_name: "custom-name" 96 | registry: false 97 | 98 | - name: Test 99 | run: | 100 | kubectl cluster-info 101 | kubectl get storageclass standard 102 | 103 | registry_id=$(docker ps --filter "name=kind-registry" --format "{{.ID}}") 104 | if [[ -n "$registry_id" ]]; then 105 | echo "Registry present" 106 | exit 1 107 | fi 108 | 109 | 110 | 111 | test-with-registry: 112 | strategy: 113 | matrix: 114 | version: 115 | - v0.17.0 116 | os: [ubuntu-latest, macos-13] 117 | runs-on: ${{ matrix.os }} 118 | steps: 119 | - name: Checkout 120 | uses: actions/checkout@v1 121 | 122 | - name: Create kind cluster with registry 123 | uses: ./ 124 | with: 125 | version: "${{ matrix.version }}" 126 | 127 | - name: Test 128 | run: | 129 | kubectl cluster-info 130 | kubectl get storageclass standard 131 | 132 | # Checking env variable 133 | if [[ "$KIND_REGISTRY" != "kind-registry:5000" ]]; then 134 | echo "Wrong KIND_REGISTRY env variable: $KIND_REGISTRY" 135 | exit 1 136 | fi 137 | 138 | TEST_REGISTRY="kind-registry:5000" 139 | if [ "$RUNNER_OS" == "macOS" ]; then 140 | TEST_REGISTRY="127.0.0.1:5000" 141 | fi 142 | 143 | # Test registry usage inside cluster 144 | docker pull busybox 145 | docker tag busybox $TEST_REGISTRY/localbusybox 146 | docker push $TEST_REGISTRY/localbusybox 147 | 148 | kubectl create job test --image=kind-registry:5000/localbusybox 149 | i=1 150 | max=60 151 | while [[ $i -le $max ]] && [[ $(kubectl get pods -l job-name=test -o 'jsonpath={..status.phase}') != "Succeeded" ]]; do 152 | echo "Waiting for pod to complete ($i/$max)..." 153 | ((i++)) 154 | sleep 1 155 | done 156 | if [[ $i -ge $max ]]; then 157 | echo "ERROR: Pod did not complete!" 158 | kubectl get pods -o yaml 159 | exit 1 160 | fi 161 | 162 | test-with-registry-with-delete-rights: 163 | strategy: 164 | matrix: 165 | version: 166 | - v0.17.0 167 | os: [ubuntu-latest, macos-13] 168 | runs-on: ${{ matrix.os }} 169 | steps: 170 | - name: Checkout 171 | uses: actions/checkout@v1 172 | 173 | - name: Create kind cluster with registry 174 | uses: ./ 175 | with: 176 | version: "${{ matrix.version }}" 177 | registry_delete: true 178 | 179 | - name: Test 180 | run: | 181 | kubectl cluster-info 182 | kubectl get storageclass standard 183 | 184 | # Checking env variable 185 | if [[ "$KIND_REGISTRY" != "kind-registry:5000" ]]; then 186 | echo "Wrong KIND_REGISTRY env variable: $KIND_REGISTRY" 187 | exit 1 188 | fi 189 | 190 | TEST_REGISTRY="kind-registry:5000" 191 | if [ "$RUNNER_OS" == "macOS" ]; then 192 | TEST_REGISTRY="127.0.0.1:5000" 193 | fi 194 | 195 | # Test registry usage inside cluster 196 | docker pull busybox 197 | docker tag busybox $TEST_REGISTRY/localbusybox 198 | 199 | # Test delete API 200 | OUTPUT=$(docker push $TEST_REGISTRY/localbusybox | grep -o 'digest.*size') 201 | TRIM=${OUTPUT//digest: /} 202 | DIGEST=${TRIM// size/} 203 | exit $(curl -X DELETE kind-registry:5000/v2/localbusybox/manifests/$DIGEST) 204 | 205 | test-knative: 206 | strategy: 207 | matrix: 208 | knative_version: 209 | - v1.9.0 210 | os: [ubuntu-latest, macos-13] 211 | runs-on: ${{ matrix.os }} 212 | steps: 213 | - name: Checkout 214 | uses: actions/checkout@v1 215 | 216 | - name: Create kind cluster 217 | uses: ./ 218 | with: 219 | knative_serving: "${{ matrix.knative_version }}" 220 | knative_kourier: "${{ matrix.knative_version }}" 221 | knative_eventing: "${{ matrix.knative_version }}" 222 | 223 | - name: Test 224 | run: | 225 | kubectl cluster-info 226 | kubectl get storageclass standard 227 | 228 | cat << EOF | kubectl apply -f - 229 | apiVersion: messaging.knative.dev/v1 230 | kind: InMemoryChannel 231 | metadata: 232 | name: messages 233 | EOF 234 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .project 3 | .settings 4 | .vscode 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes KinD Cluster Action 2 | 3 | [![](https://github.com/container-tools/kind-action/workflows/Test/badge.svg?branch=main)](https://github.com/container-tools/kind-action/actions) 4 | 5 | A GitHub Action for starting a Kubernetes cluster with a local registry and optional addons (Knative) using [KinD](https://kind.sigs.k8s.io/). 6 | 7 | This action provides an insecure registry on `kind-registry:5000` by default: it can be used to publish and deploy container images into KinD. 8 | 9 | ## Usage 10 | 11 | ### Pre-requisites 12 | 13 | Create a workflow YAML file in your `.github/workflows` directory. An [example workflow](#example-workflow) is available below. 14 | For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). 15 | 16 | ### Inputs 17 | 18 | For more information on inputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#input) 19 | 20 | - `version`: The KinD version to use (default: `v0.17.0`) 21 | - `config`: The path to the KinD config file 22 | - `node_image`: The Docker image for the cluster nodes 23 | - `cluster_name`: The name of the cluster to create (default: `kind`) 24 | - `wait`: The duration to wait for the control plane to become ready (default: `60s`) 25 | - `log_level`: The log level for KinD 26 | - `registry`: Configures an insecure registry on `kind-registry:5000` to be used with KinD (default: `true`) 27 | - `registry_delete`: Set to true to enable delete operations on the Image Registry (default is `false`) 28 | - `kubectl_version`: The kubectl version to use (default: `v1.26.1`) 29 | - `knative_serving`: The version of Knative Serving to install on the Kind cluster (not installed by default - example: `v1.0.0`) 30 | - `knative_kourier`: The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: `v1.0.0`) 31 | - `knative_eventing`: The version of Knative Eventing to install on the Kind cluster (not installed by default - example: `v1.0.0`) 32 | - `cpu`: Number of CPUs to be allocated to the virtual machine (default: 2). For Mac OS only. 33 | - `memory`: Size of the memory in GiB to be allocated to the virtual machine (default: 12). For Mac OS only. 34 | - `disk`: Size of the disk in GiB to be allocated to the virtual machine (default: 60). For Mac OS only. 35 | 36 | ### Example Workflow 37 | 38 | Create a workflow (eg: `.github/workflows/create-cluster.yml`): 39 | 40 | ```yaml 41 | name: Create Cluster 42 | 43 | on: pull_request 44 | 45 | jobs: 46 | create-cluster: 47 | runs-on: ubuntu-latest 48 | steps: 49 | - name: Kubernetes KinD Cluster 50 | uses: container-tools/kind-action@v1 51 | ``` 52 | 53 | This uses [@container-tools/kind-action](https://www.github.com/container-tools/kind-action) GitHub Action to spin up a [KinD](https://kind.sigs.k8s.io/) Kubernetes cluster on every Pull Request. 54 | 55 | A container registry will be created with address `kind-registry:5000` on both the host and the cluster. 56 | The registry address is stored in the `KIND_REGISTRY` environment variable, also for the subsequent steps. 57 | 58 | ### Configuring Addons 59 | 60 | Create a workflow (eg: `.github/workflows/create-cluster-with-addons.yml`): 61 | 62 | ```yaml 63 | name: Create Cluster with Addons 64 | 65 | on: pull_request 66 | 67 | jobs: 68 | create-cluster-with-addons: 69 | runs-on: ubuntu-latest 70 | steps: 71 | - name: Kubernetes KinD Cluster 72 | uses: container-tools/kind-action@v1 73 | with: 74 | knative_serving: v1.0.0 75 | knative_kourier: v1.0.0 76 | knative_eventing: v1.0.0 77 | ``` 78 | 79 | This will install Knative Serving, Eventing and a Kourier Ingress on your Kind cluster. To make Knative run on Kind, resource request and limits are removed from the original Knative descriptors. 80 | 81 | ## Credits 82 | 83 | This action leverages the good work done by the Helm community on [@helm/kind-action](https://www.github.com/helm/kind-action). 84 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Kubernetes KinD Cluster" 2 | description: "Create a KinD (Kubernetes in Docker) cluster with a container image registry and optional addons (Knative)" 3 | author: "Container Tools developers" 4 | branding: 5 | color: blue 6 | icon: cloud 7 | inputs: 8 | version: 9 | description: "The KinD version to use (default: v0.17.0)" 10 | config: 11 | description: "The path to the KinD config file" 12 | node_image: 13 | description: "The Docker image for the cluster nodes" 14 | cluster_name: 15 | description: "The name of the cluster to create (default: kind)" 16 | wait: 17 | description: "The duration to wait for the control plane to become ready (default: 60s)" 18 | log_level: 19 | description: "The log level for KinD" 20 | registry: 21 | description: "Configures an insecure registry on kind-registry:5000 to be used with KinD (default: true)" 22 | registry_delete: 23 | description: "Enables delete operations on the Image Registry (default is false)" 24 | kubectl_version: 25 | description: "The version of kubectl to use (default: v1.26.1)" 26 | knative_serving: 27 | description: "The version of Knative Serving to install on the Kind cluster (not installed by default - example: v1.0.0)" 28 | knative_kourier: 29 | description: "The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: v1.0.0)" 30 | knative_eventing: 31 | description: "The version of Knative Eventing to install on the Kind cluster (not installed by default - example: v1.0.0)" 32 | cpu: 33 | description: "For Mac OS only: Number of CPUs to be allocated to the virtual machine (default: 2)" 34 | memory: 35 | description: "For Mac OS only: Size of the memory in GiB to be allocated to the virtual machine (default: 12)" 36 | disk: 37 | description: "For Mac OS only: Size of the disk in GiB to be allocated to the virtual machine (default: 60)" 38 | runs: 39 | using: "node20" 40 | main: "main.js" 41 | post: "cleanup.js" 42 | -------------------------------------------------------------------------------- /cleanup.js: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // # You may obtain a copy of the License at 4 | // 5 | // https://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // # See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | const spawnSync = require('child_process').spawnSync; 14 | const path = require("path"); 15 | 16 | const proc = spawnSync('bash', [path.join(__dirname, 'cleanup.sh')], {stdio: 'inherit'}); 17 | process.exit(proc.status) 18 | -------------------------------------------------------------------------------- /cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set -o errexit 16 | set -o nounset 17 | set -o pipefail 18 | 19 | DEFAULT_CLUSTER_NAME=kind 20 | 21 | main() { 22 | args=() 23 | 24 | if [[ -n "${INPUT_CLUSTER_NAME:-}" ]]; then 25 | args+=(--name "${INPUT_CLUSTER_NAME}") 26 | else 27 | args+=(--name "${DEFAULT_CLUSTER_NAME}") 28 | fi 29 | 30 | kind delete cluster "${args[@]}" 31 | 32 | registry_id=$(docker ps --filter "name=kind-registry" --format "{{.ID}}") 33 | if [[ -n "$registry_id" ]]; then 34 | echo "Deleting kind-registry..." 35 | docker rm --force kind-registry 36 | fi 37 | } 38 | 39 | main 40 | -------------------------------------------------------------------------------- /kind.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set -o errexit 16 | set -o nounset 17 | set -o pipefail 18 | 19 | DEFAULT_KIND_VERSION=v0.17.0 20 | DEFAULT_CLUSTER_NAME=kind 21 | DEFAULT_KUBECTL_VERSION=v1.26.1 22 | 23 | show_help() { 24 | cat << EOF 25 | Usage: $(basename "$0") 26 | 27 | -h, --help Display help 28 | -v, --version The kind version to use (default: $DEFAULT_KIND_VERSION)" 29 | -k, --kubectl-version The kubectl version to use (default: $DEFAULT_KUBECTL_VERSION)" 30 | -c, --config The path to the kind config file" 31 | -i, --node-image The Docker image for the cluster nodes" 32 | -n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)" 33 | -w, --wait The duration to wait for the control plane to become ready (default: 60s)" 34 | -l, --log-level The log level for kind [panic, fatal, error, warning, info, debug, trace] (default: warning) 35 | 36 | EOF 37 | } 38 | 39 | main() { 40 | local version="$DEFAULT_KIND_VERSION" 41 | local kubectl_version="$DEFAULT_KUBECTL_VERSION" 42 | local config= 43 | local node_image= 44 | local cluster_name="$DEFAULT_CLUSTER_NAME" 45 | local wait=60s 46 | local log_level= 47 | 48 | parse_command_line "$@" 49 | 50 | install_kind 51 | install_kubectl 52 | install_docker 53 | create_kind_cluster 54 | 55 | } 56 | 57 | parse_command_line() { 58 | while :; do 59 | case "${1:-}" in 60 | -h|--help) 61 | show_help 62 | exit 63 | ;; 64 | -v|--version) 65 | if [[ -n "${2:-}" ]]; then 66 | version="$2" 67 | shift 68 | else 69 | echo "ERROR: '-v|--version' cannot be empty." >&2 70 | show_help 71 | exit 1 72 | fi 73 | ;; 74 | -k|--kubectl-version) 75 | if [[ -n "${2:-}" ]]; then 76 | kubectl_version="$2" 77 | shift 78 | else 79 | echo "ERROR: '-k|--kubectl-version' cannot be empty." >&2 80 | show_help 81 | exit 1 82 | fi 83 | ;; 84 | -c|--config) 85 | if [[ -n "${2:-}" ]]; then 86 | config="$2" 87 | shift 88 | else 89 | echo "ERROR: '--config' cannot be empty." >&2 90 | show_help 91 | exit 1 92 | fi 93 | ;; 94 | -i|--node-image) 95 | if [[ -n "${2:-}" ]]; then 96 | node_image="$2" 97 | shift 98 | else 99 | echo "ERROR: '-i|--node-image' cannot be empty." >&2 100 | show_help 101 | exit 1 102 | fi 103 | ;; 104 | -n|--cluster-name) 105 | if [[ -n "${2:-}" ]]; then 106 | cluster_name="$2" 107 | shift 108 | else 109 | echo "ERROR: '-n|--cluster-name' cannot be empty." >&2 110 | show_help 111 | exit 1 112 | fi 113 | ;; 114 | -w|--wait) 115 | if [[ -n "${2:-}" ]]; then 116 | wait="$2" 117 | shift 118 | else 119 | echo "ERROR: '--wait' cannot be empty." >&2 120 | show_help 121 | exit 1 122 | fi 123 | ;; 124 | -l|--log-level) 125 | if [[ -n "${2:-}" ]]; then 126 | log_level="$2" 127 | shift 128 | else 129 | echo "ERROR: '--log-level' cannot be empty." >&2 130 | show_help 131 | exit 1 132 | fi 133 | ;; 134 | *) 135 | break 136 | ;; 137 | esac 138 | 139 | shift 140 | done 141 | } 142 | 143 | install_kind() { 144 | echo 'Installing kind...' 145 | if [ "$RUNNER_OS" == "macOS" ]; then 146 | # for Intel Macs 147 | [ $(uname -m) = x86_64 ] && curl -sSLo kind "https://kind.sigs.k8s.io/dl/$version/kind-darwin-amd64" 148 | # for M1 / ARM Macs 149 | [ $(uname -m) = arm64 ] && curl -sSLo kind "https://kind.sigs.k8s.io/dl/$version/kind-darwin-arm64" 150 | else 151 | curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$version/kind-linux-amd64" 152 | fi 153 | chmod +x kind 154 | sudo mv kind /usr/local/bin/kind 155 | kind version 156 | } 157 | 158 | install_kubectl() { 159 | echo 'Installing kubectl...' 160 | if [ "$RUNNER_OS" == "macOS" ]; then 161 | # for Intel Macs 162 | [ $(uname -m) = x86_64 ] && curl -sSLo kubectl "https://dl.k8s.io/release/$kubectl_version/bin/darwin/amd64/kubectl" 163 | # for M1 / ARM Macs 164 | [ $(uname -m) = arm64 ] && curl -sSLo kubectl "https://dl.k8s.io/release/$kubectl_version/bin/darwin/arm64/kubectl" 165 | else 166 | curl -sSLO "https://dl.k8s.io/release/$kubectl_version/bin/linux/amd64/kubectl" 167 | fi 168 | chmod +x kubectl 169 | sudo mv kubectl /usr/local/bin/kubectl 170 | kubectl version --client --output=yaml 171 | } 172 | 173 | install_docker() { 174 | if [ "$RUNNER_OS" == "macOS" ] && ! [ -x "$(command -v docker)" ]; then 175 | echo 'Installing docker...' 176 | brew install docker docker-buildx colima 177 | mkdir -p ~/.docker/cli-plugins 178 | ln -sfn /usr/local/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx 179 | colima start 180 | fi 181 | } 182 | 183 | create_kind_cluster() { 184 | echo 'Creating kind cluster...' 185 | local args=(create cluster "--name=$cluster_name" "--wait=$wait") 186 | 187 | if [[ -n "$node_image" ]]; then 188 | args+=("--image=$node_image") 189 | fi 190 | 191 | if [[ -n "$config" ]]; then 192 | args+=("--config=$config") 193 | fi 194 | 195 | if [[ -n "$log_level" ]]; then 196 | args+=("--loglevel=$log_level") 197 | fi 198 | 199 | kind "${args[@]}" 200 | } 201 | 202 | main "$@" 203 | -------------------------------------------------------------------------------- /knative.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set -o errexit 16 | set -o nounset 17 | set -o pipefail 18 | 19 | show_help() { 20 | cat << EOF 21 | Usage: $(basename "$0") 22 | 23 | -h, --help Display help 24 | --knative-serving The version of Knative Serving to use 25 | --knative-eventing The version of Knative Eventing to use 26 | --knative-kourier The version of Knative Net Kourier to use 27 | 28 | EOF 29 | } 30 | 31 | main() { 32 | local serving_version= 33 | local eventing_version= 34 | local kourier_version= 35 | 36 | parse_command_line "$@" 37 | 38 | if [[ "$serving_version" != "" ]] || [[ "$eventing_version" != "" ]] || [[ "$kourier_version" != "" ]] 39 | then 40 | install_prerequisites 41 | fi 42 | 43 | if [[ "$serving_version" != "" ]] 44 | then 45 | install_serving 46 | fi 47 | 48 | if [[ "$kourier_version" != "" ]] 49 | then 50 | install_kourier 51 | fi 52 | 53 | if [[ "$eventing_version" != "" ]] 54 | then 55 | install_eventing 56 | fi 57 | 58 | } 59 | 60 | parse_command_line() { 61 | while :; do 62 | case "${1:-}" in 63 | -h|--help) 64 | show_help 65 | exit 66 | ;; 67 | --knative-serving) 68 | if [[ -n "${2:-}" ]]; then 69 | serving_version="$2" 70 | shift 71 | else 72 | echo "ERROR: '--serving-version' cannot be empty." >&2 73 | show_help 74 | exit 1 75 | fi 76 | ;; 77 | --knative-kourier) 78 | if [[ -n "${2:-}" ]]; then 79 | kourier_version="$2" 80 | shift 81 | else 82 | echo "ERROR: '--kourier-version' cannot be empty." >&2 83 | show_help 84 | exit 1 85 | fi 86 | ;; 87 | --knative-eventing) 88 | if [[ -n "${2:-}" ]]; then 89 | eventing_version="$2" 90 | shift 91 | else 92 | echo "ERROR: '--eventing-version' cannot be empty." >&2 93 | show_help 94 | exit 1 95 | fi 96 | ;; 97 | *) 98 | break 99 | ;; 100 | esac 101 | 102 | shift 103 | done 104 | } 105 | 106 | install_prerequisites() { 107 | echo "Installing yq for patching Knative resources..." 108 | if [ "$RUNNER_OS" == "macOS" ]; then 109 | brew install yq 110 | else 111 | wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq 112 | chmod +x /usr/local/bin/yq 113 | fi 114 | yq --version 115 | } 116 | 117 | install_serving() { 118 | # TODO find alternative to sleep 119 | echo "Installing Knative Serving $serving_version..." 120 | base=https://github.com/knative/serving/releases/download/$serving_version 121 | if [[ $serving_version = v1* ]]; then 122 | base=https://github.com/knative/serving/releases/download/knative-$serving_version 123 | fi 124 | kubectl apply --filename $base/serving-crds.yaml 125 | echo "Waiting for resources to be initialized..." 126 | sleep 5 127 | curl -L -s $base/serving-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' | yq 'del(.metadata.annotations."knative.dev/example-checksum")' | kubectl apply -f - 128 | echo "Waiting for resources to be initialized..." 129 | sleep 60 130 | kubectl get pod -n knative-serving 131 | } 132 | 133 | install_kourier() { 134 | # TODO find alternative to sleep 135 | echo "Installing Knative Net Kourier $kourier_version..." 136 | base=https://github.com/knative-sandbox/net-kourier/releases/download/$kourier_version 137 | if [[ $serving_version = v1* ]]; then 138 | base=https://github.com/knative-sandbox/net-kourier/releases/download/knative-$kourier_version 139 | fi 140 | kubectl apply --filename $base/kourier.yaml 141 | kubectl patch configmap/config-network \ 142 | --namespace knative-serving \ 143 | --type merge \ 144 | --patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}' 145 | echo "Waiting for resources to be initialized..." 146 | sleep 30 147 | kubectl get pod -n kourier-system 148 | } 149 | 150 | install_eventing() { 151 | # TODO find alternative to sleep 152 | echo "Installing Knative Eventing $eventing_version..." 153 | base=https://github.com/knative/eventing/releases/download/$eventing_version 154 | if [[ $serving_version = v1* ]]; then 155 | base=https://github.com/knative/eventing/releases/download/knative-$eventing_version 156 | fi 157 | kubectl apply --filename $base/eventing-crds.yaml 158 | echo "Waiting for resources to be initialized..." 159 | sleep 5 160 | curl -L -s $base/eventing-core.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' | yq 'del(.metadata.annotations."knative.dev/example-checksum")' | kubectl apply -f - 161 | # Eventing channels 162 | set +e 163 | curl -L -s $base/in-memory-channel.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' | yq 'del(.metadata.annotations."knative.dev/example-checksum")' | kubectl apply -f - 164 | if [ $? -ne 0 ]; then 165 | set -e 166 | curl -L -s $base/in-memory-channel.yaml | kubectl apply -f - 167 | fi 168 | set -e 169 | # Eventing broker 170 | curl -L -s $base/mt-channel-broker.yaml | yq 'del(.spec.template.spec.containers[]?.resources)' | yq 'del(.metadata.annotations."knative.dev/example-checksum")' | kubectl apply -f - 171 | echo "Waiting for resources to be initialized..." 172 | sleep 30 173 | kubectl get pod -n knative-eventing 174 | } 175 | 176 | main "$@" 177 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // # You may obtain a copy of the License at 4 | // 5 | // https://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // # See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | const spawnSync = require('child_process').spawnSync; 14 | const path = require("path"); 15 | 16 | const proc = spawnSync('bash', [path.join(__dirname, 'main.sh')], {stdio: 'inherit'}); 17 | process.exit(proc.status) 18 | -------------------------------------------------------------------------------- /main.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set -o errexit 16 | set -o nounset 17 | set -o pipefail 18 | 19 | SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")") 20 | 21 | main() { 22 | args_kind=() 23 | args_knative=() 24 | args_registry=() 25 | 26 | if [[ -n "${INPUT_VERSION:-}" ]]; then 27 | args_kind+=(--version "${INPUT_VERSION}") 28 | fi 29 | 30 | if [[ -n "${INPUT_CONFIG:-}" ]]; then 31 | args_kind+=(--config "${INPUT_CONFIG}") 32 | fi 33 | 34 | if [[ -n "${INPUT_NODE_IMAGE:-}" ]]; then 35 | args_kind+=(--node-image "${INPUT_NODE_IMAGE}") 36 | fi 37 | 38 | if [[ -n "${INPUT_CLUSTER_NAME:-}" ]]; then 39 | args_kind+=(--cluster-name "${INPUT_CLUSTER_NAME}") 40 | fi 41 | 42 | if [[ -n "${INPUT_WAIT:-}" ]]; then 43 | args_kind+=(--wait "${INPUT_WAIT}") 44 | fi 45 | 46 | if [[ -n "${INPUT_LOG_LEVEL:-}" ]]; then 47 | args_kind+=(--log-level "${INPUT_LOG_LEVEL}") 48 | fi 49 | 50 | if [[ -n "${INPUT_KUBECTL_VERSION:-}" ]]; then 51 | args_kind+=(--kubectl-version "${INPUT_KUBECTL_VERSION}") 52 | fi 53 | 54 | if [[ -n "${INPUT_KNATIVE_SERVING:-}" ]]; then 55 | args_knative+=(--knative-serving "${INPUT_KNATIVE_SERVING}") 56 | fi 57 | 58 | if [[ -n "${INPUT_KNATIVE_KOURIER:-}" ]]; then 59 | args_knative+=(--knative-kourier "${INPUT_KNATIVE_KOURIER}") 60 | fi 61 | 62 | if [[ -n "${INPUT_KNATIVE_EVENTING:-}" ]]; then 63 | args_knative+=(--knative-eventing "${INPUT_KNATIVE_EVENTING}") 64 | fi 65 | 66 | if [[ -n "${INPUT_CPU:-}" ]]; then 67 | args_registry+=(--cpu "${INPUT_CPU}") 68 | fi 69 | 70 | if [[ -n "${INPUT_DISK:-}" ]]; then 71 | args_registry+=(--disk "${INPUT_DISK}") 72 | fi 73 | 74 | if [[ -n "${INPUT_MEMORY:-}" ]]; then 75 | args_registry+=(--memory "${INPUT_MEMORY}") 76 | fi 77 | 78 | if [[ -n "${INPUT_REGISTRY_DELETE:-}" ]]; then 79 | args_registry+=(--registry-delete "${INPUT_REGISTRY_DELETE}") 80 | fi 81 | 82 | 83 | if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then 84 | if [[ ${#args_registry[@]} -gt 0 ]]; then 85 | "$SCRIPT_DIR/registry.sh" "${args_registry[@]}" 86 | else 87 | "$SCRIPT_DIR/registry.sh" 88 | fi 89 | 90 | 91 | if [[ -n "${INPUT_CONFIG:-}" ]]; then 92 | echo 'WARNING: when using the "config" option, you need to manually configure the registry in the provided configuration' 93 | else 94 | args_kind+=(--config "/etc/kind-registry/config.yaml") 95 | fi 96 | fi 97 | if [[ ${#args_kind[@]} -gt 0 ]]; then 98 | "$SCRIPT_DIR/kind.sh" "${args_kind[@]}" 99 | else 100 | "$SCRIPT_DIR/kind.sh" 101 | fi 102 | 103 | if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then 104 | if [[ ${#args_registry[@]} -gt 0 ]]; then 105 | "$SCRIPT_DIR/registry.sh" "--document" "true" "${args_registry[@]}" 106 | else 107 | "$SCRIPT_DIR/registry.sh" "--document" "true" 108 | fi 109 | fi 110 | if [[ ${#args_knative[@]} -gt 0 ]]; then 111 | "$SCRIPT_DIR/knative.sh" "${args_knative[@]}" 112 | else 113 | "$SCRIPT_DIR/knative.sh" 114 | fi 115 | } 116 | 117 | main 118 | -------------------------------------------------------------------------------- /registry.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set -o errexit 16 | set -o nounset 17 | set -o pipefail 18 | 19 | DEFAULT_REGISTRY_IMAGE=registry:2 20 | DEFAULT_REGISTRY_NAME=kind-registry 21 | DEFAULT_REGISTRY_PORT=5000 22 | DEFAULT_CLUSTER_NAME=kind 23 | DEFAULT_CPU=2 24 | DEFAULT_MEMORY=12 25 | DEFAULT_DISK=60 26 | 27 | show_help() { 28 | cat << EOF 29 | Usage: $(basename "$0") 30 | 31 | -h, --help Display help 32 | --cpu Number of CPUs to be allocated to the virtual machine (default: $DEFAULT_CPU). For Mac OS only 33 | --disk Size of the disk in GiB to be allocated to the virtual machine (default: $DEFAULT_DISK). For Mac OS only 34 | --memory Size of the memory in GiB to be allocated to the virtual machine (default: $DEFAULT_MEMORY). For Mac OS only 35 | --registry-image The registry image to use (default: $DEFAULT_REGISTRY_IMAGE) 36 | --registry-name The registry name to use (default: $DEFAULT_REGISTRY_NAME) 37 | --registry-port The local port used to bind the registry (default: $DEFAULT_REGISTRY_PORT) 38 | --registry-delete Enable delete operations on the registry (default is false) 39 | -n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)" 40 | --document Document the local registry 41 | 42 | EOF 43 | } 44 | 45 | main() { 46 | local registry_image="$DEFAULT_REGISTRY_IMAGE" 47 | local registry_name="$DEFAULT_REGISTRY_NAME" 48 | local registry_port="$DEFAULT_REGISTRY_PORT" 49 | local registry_delete="false" 50 | local cluster_name="$DEFAULT_CLUSTER_NAME" 51 | local cpu="$DEFAULT_CPU" 52 | local disk="$DEFAULT_DISK" 53 | local memory="$DEFAULT_MEMORY" 54 | local document=false 55 | 56 | parse_command_line "$@" 57 | 58 | if [[ "$document" = "false" ]] 59 | then 60 | install_docker 61 | create_registry 62 | connect_registry 63 | create_kind_config 64 | else 65 | document 66 | fi 67 | 68 | } 69 | 70 | parse_command_line() { 71 | while :; do 72 | case "${1:-}" in 73 | -h|--help) 74 | show_help 75 | exit 76 | ;; 77 | --cpu) 78 | if [[ -n "${2:-}" ]]; then 79 | cpu="$2" 80 | shift 81 | else 82 | echo "ERROR: '--cpu' cannot be empty." >&2 83 | show_help 84 | exit 1 85 | fi 86 | ;; 87 | --disk) 88 | if [[ -n "${2:-}" ]]; then 89 | disk="$2" 90 | shift 91 | else 92 | echo "ERROR: '--disk' cannot be empty." >&2 93 | show_help 94 | exit 1 95 | fi 96 | ;; 97 | --memory) 98 | if [[ -n "${2:-}" ]]; then 99 | memory="$2" 100 | shift 101 | else 102 | echo "ERROR: '--memory' cannot be empty." >&2 103 | show_help 104 | exit 1 105 | fi 106 | ;; 107 | --registry-image) 108 | if [[ -n "${2:-}" ]]; then 109 | registry_image="$2" 110 | shift 111 | else 112 | echo "ERROR: '--registry-image' cannot be empty." >&2 113 | show_help 114 | exit 1 115 | fi 116 | ;; 117 | --registry-name) 118 | if [[ -n "${2:-}" ]]; then 119 | registry_name="$2" 120 | shift 121 | else 122 | echo "ERROR: '--registry-name' cannot be empty." >&2 123 | show_help 124 | exit 1 125 | fi 126 | ;; 127 | --registry-port) 128 | if [[ -n "${2:-}" ]]; then 129 | registry_port="$2" 130 | shift 131 | else 132 | echo "ERROR: '--registry-port' cannot be empty." >&2 133 | show_help 134 | exit 1 135 | fi 136 | ;; 137 | --registry-delete) 138 | if [[ -n "${2:-}" ]]; then 139 | registry_delete="$2" 140 | shift 141 | else 142 | echo "ERROR: '--registry-delete' cannot be empty." >&2 143 | show_help 144 | exit 1 145 | fi 146 | ;; 147 | -n|--cluster-name) 148 | if [[ -n "${2:-}" ]]; then 149 | cluster_name="$2" 150 | shift 151 | else 152 | echo "ERROR: '-n|--cluster-name' cannot be empty." >&2 153 | show_help 154 | exit 1 155 | fi 156 | ;; 157 | --document) 158 | if [[ -n "${2:-}" ]]; then 159 | document="$2" 160 | shift 161 | else 162 | echo "ERROR: '--document' cannot be empty." >&2 163 | show_help 164 | exit 1 165 | fi 166 | ;; 167 | *) 168 | break 169 | ;; 170 | esac 171 | 172 | shift 173 | done 174 | } 175 | 176 | install_docker() { 177 | if [ "$RUNNER_OS" == "macOS" ] && ! [ -x "$(command -v docker)" ]; then 178 | echo 'Installing docker...' 179 | brew install docker docker-buildx colima 180 | mkdir -p ~/.docker/cli-plugins 181 | ln -sfn /usr/local/opt/docker-buildx/bin/docker-buildx ~/.docker/cli-plugins/docker-buildx 182 | colima start --cpu "$cpu" --memory "$memory" --disk "$disk" 183 | fi 184 | } 185 | 186 | create_registry() { 187 | echo "Creating registry \"$registry_name\" on port $registry_port from image \"$registry_image\" with delete enabled $registry_delete ..." 188 | docker run -d --restart=always -p "${registry_port}:5000" -e "REGISTRY_STORAGE_DELETE_ENABLED=${registry_delete}" --name "${registry_name}" $registry_image 189 | > /dev/null 190 | 191 | # Adding registry to /etc/hosts 192 | echo "127.0.0.1 $registry_name" | sudo tee -a /etc/hosts 193 | 194 | # Exporting the registry location for subsequent jobs 195 | echo "KIND_REGISTRY=${registry_name}:${registry_port}" >> $GITHUB_ENV 196 | } 197 | 198 | connect_registry() { 199 | echo 'Connecting registry to the "kind" network...' 200 | docker network create kind 201 | docker network connect "kind" "${registry_name}" 202 | } 203 | 204 | create_kind_config() { 205 | sudo mkdir -p /etc/kind-registry 206 | cat <