| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| version: '3' |
| |
| vars: |
| D: "" |
| RUN: '{{if eq .D ""}}{{else}}echo{{end}}' |
| CAT: '{{if eq .D ""}}true{{else}}cat{{end}}' |
| OS: '{{OS}}' |
| ARCH: '{{ARCH}}' |
| |
| tasks: |
| check-ports: |
| desc: "Check if an array of TCP/UDP ports is free and fail if any are in use" |
| silent: true |
| vars: |
| PORTS: "{{ .PORTS | default \"\" }}" |
| cmds: |
| - | |
| {{if eq OS "windows"}} |
| $ports = "{{ .PORTS }}".Split(" ") |
| foreach ($entry in $ports) { |
| $parts = $entry -split "/" |
| $port = $parts[0] |
| $protocol = $parts[1].ToLower() |
| |
| if ($protocol -eq "tcp" -and (Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue)) { |
| Write-Host "TCP Port $port is in use!" -ForegroundColor Red |
| exit 1 |
| } |
| if ($protocol -eq "udp" -and (Get-NetUDPEndpoint -LocalPort $port -ErrorAction SilentlyContinue)) { |
| Write-Host "UDP Port $port is in use!" -ForegroundColor Red |
| exit 1 |
| } |
| } |
| {{else if eq OS "darwin"}} |
| for entry in {{ .PORTS }}; do |
| port="${entry%/*}" |
| protocol="${entry#*/}" |
| if [[ "$protocol" == "tcp" ]] && lsof -i TCP:$port -sTCP:LISTEN -t > /dev/null 2>&1; then |
| echo "TCP Port $port is in use!" >&2 |
| exit 1 |
| fi |
| if [[ "$protocol" == "udp" ]] && lsof -i UDP:$port -t > /dev/null 2>&1; then |
| echo "UDP Port $port is in use!" >&2 |
| exit 1 |
| fi |
| done |
| {{else}} |
| for entry in {{ .PORTS }}; do |
| port="${entry%/*}" |
| protocol="${entry#*/}" |
| if [[ "$protocol" == "tcp" ]] && ss -tuln | rg -q ":(^| )$port "; then |
| echo "TCP Port $port is in use!" >&2 |
| exit 1 |
| fi |
| if [[ "$protocol" == "udp" ]] && ss -uln | rg -q ":(^| )$port "; then |
| echo "UDP Port $port is in use!" >&2 |
| exit 1 |
| fi |
| done |
| {{end}} |
| |
| prereq: |
| silent: true |
| cmds: |
| - exit 0 |
| |
| devcluster: |
| vars: |
| PORTS: '9010/tcp 9080/tcp 30379/tcp 32817/tcp 3232/tcp 3233/tcp 9644/tcp 7896/tcp 5984/tcp 9092/tcp 9000/tcp 9090/tcp 19530/tcp 9091/tcp, 27017/tcp 80/tcp 443/tcp 57817/tcp' |
| silent: true |
| cmds: |
| - | |
| if {{.__status}} |
| then {{.RUN}} $OPS setup docker status |
| elif {{.__uninstall}} |
| then {{.RUN}} $OPS setup docker delete |
| else |
| if test -z {{.__skip_check_ports}} |
| then |
| task check-ports PORTS="{{ .PORTS }}" |
| fi |
| {{.RUN}} $OPS setup docker create |
| {{.RUN}} $OPS setup kubernetes create |
| {{.RUN}} $OPS setup nuvolaris login |
| config STATUS_LAST=devcluster |
| fi |
| |
| cluster: |
| silent: true |
| cmds: |
| - | |
| if {{.__status}} |
| then {{.RUN}} $OPS setup kubernetes status CONTEXT="{{._context_}}" |
| elif {{.__uninstall}} |
| then {{.RUN}} $OPS setup kubernetes delete CONTEXT="{{._context_}}" |
| else |
| {{.RUN}} $OPS setup kubernetes create CONTEXT="{{._context_}}" |
| {{.RUN}} $OPS setup nuvolaris login |
| config STATUS_LAST=cluster |
| if test -n "{{._context_}}" |
| then config STATUS_CONTEXT="{{._context_}}" |
| fi |
| fi |
| |
| server: |
| silent: true |
| cmds: |
| - | |
| if {{.__status}} |
| then {{.RUN}} $OPS cloud k3s status {{._server_}} {{._user_}} |
| elif {{.__uninstall}} |
| then {{.RUN}} $OPS cloud k3s delete {{._server_}} {{._user_}} |
| else |
| {{.RUN}} $OPS cloud k3s create {{._server_}} {{._user_}} |
| {{.RUN}} $OPS setup kubernetes create |
| {{.RUN}} $OPS setup nuvolaris login |
| config STATUS_LAST=server STATUS_SERVER="{{._server_}}" |
| if test -n "{{._user_}}" |
| then config STATUS_USERNAME="{{._user_}}" |
| fi |
| fi |
| |
| status: |
| silent: true |
| cmds: |
| - | |
| case "$STATUS_LAST" in |
| (devcluster) {{.RUN}} $OPS setup devcluster --status ;; |
| (cluster) {{.RUN}} $OPS setup cluster "$STATUS_CONTEXT" --status ;; |
| (server) {{.RUN}} $OPS setup server "$STATUS_SERVER" "$STATUS_USERNAME" --status ;; |
| (*) echo nothing installed yet |
| esac |
| |
| uninstall: |
| silent: true |
| cmds: |
| - | |
| case "$STATUS_LAST" in |
| (devcluster) |
| {{.RUN}} $OPS setup devcluster --uninstall |
| config -r STATUS_LAST |
| ;; |
| (cluster) |
| if test -n "$STATUS_CONTEXT" |
| then |
| {{.RUN}} $OPS setup cluster "$STATUS_CONTEXT" --uninstall |
| config -r STATUS_CONTEXT |
| else |
| {{.RUN}} $OPS setup cluster --uninstall |
| fi |
| config -r STATUS_LAST |
| ;; |
| (server) |
| if test -z "$STATUS_USERNAME" |
| then |
| {{.RUN}} $OPS setup server "$STATUS_SERVER" --uninstall |
| else |
| {{.RUN}} $OPS setup server "$STATUS_SERVER" "$STATUS_USERNAME" --uninstall |
| config -r STATUS_USERNAME |
| fi |
| config -r STATUS_LAST STATUS_SERVER |
| ;; |
| (*) echo nothing installed yet |
| esac |