| # 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: |
| UID: |
| sh: 'echo {{ if eq OS "windows" }}1000{{ else }}$(id -u){{ end }}' |
| GID: |
| sh: 'echo {{ if eq OS "windows" }}1000{{ else }}$(id -g){{ end }}' |
| SSHDIR: |
| sh: echo ~/.ssh | replace -s \\ -r / --stdin |
| SSHKEY: |
| sh: echo {{.SSHDIR}}/id_miniops |
| DRY: "" |
| EXTRA: "" |
| |
| |
| env: |
| KUBECONFIG: |
| sh: |- |
| if test -e "$OPS_TMP/kubeconfig" |
| then echo "$OPS_TMP/kubeconfig" |
| else echo ~/.kube/config |
| fi |
| |
| tasks: |
| |
| vars: |
| |
| gen-key: |
| silent: true |
| desc: generating an internal ssh key |
| cmds: |
| - | |
| if ! test -e "{{.SSHKEY}}" |
| then mkdir -p "{{.SSHDIR}}" |
| echo Generating key {{.SSHKEY}} |
| ssh-keygen -q -a 100 -t ed25519 -a 100 -N '' -f "{{.SSHKEY}}" -C "miniops key" |
| else |
| echo Using {{.SSHKEY}} |
| fi |
| - | |
| touch "{{.SSHDIR}}/config" |
| if ! rg "Host miniops" ~/.ssh/config >/dev/null |
| then echo Adding miniops entry in ssh config |
| echo -e "\nHost miniops\n Hostname localhost\n Port 2222\n User devel\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null\n IdentityFile ~/.ssh/id_miniops\n" >> ~/.ssh/config |
| else |
| echo Found miniops entry in ssh config |
| fi |
| - | |
| if rg "miniops key" "{{.SSHDIR}}/authorized_keys" 2>/dev/null >/dev/null |
| then |
| echo Access already added |
| else |
| cat "{{.SSHKEY}}.pub" >>"{{.SSHDIR}}/authorized_keys" |
| echo Added key for external Access |
| {{if ne OS "windows"}} |
| chmod 0700 "{{.SSHDIR}}" |
| chmod 0600 "{{.SSHDIR}}/authorized_keys" |
| {{end}} |
| fi |
| |
| deploy: |
| silent: true |
| desc: deploy the devcontainer in kubernetes |
| env: |
| OPS_APIHOST: http://miniops.me |
| OPS_USER: devel |
| OPS_PASSWORD: |
| sh: cat ~/.ops/devel.password |
| cmds: |
| - ops util apihost | rg miniops.me || die "devcontainer requires miniops.me" |
| - task: gen-key |
| - > |
| kubectl -n nuvolaris create secret generic ssh-secret |
| --from-literal=authorized_keys="$(cat {{.SSHKEY}}.pub)" 2>/dev/null || die "devcontainer already exists" |
| - | |
| export IMAGE="{{.IMAGES_DEVCONTAINER}}" |
| envsubst < deployment.yaml >_deployment.yaml |
| kubectl apply -f _deployment.yaml |
| - ops setup kubernetes wait-pod SELECTOR="-l app=ssh-devcontainer" COND=false FILE=_devcontainer |
| - > |
| retry -t 100 -m 600 ssh miniops exit 2>&1 |
| | awk '{s=""; for(i=1;i<=NR;i++) s=s"#"; printf "\rwaiting for ssh: [%s]", s; fflush()}' |
| - echo -e "\nyou can now connect to the devcontainer with 'ssh miniops'" |
| |
| undeploy: |
| silent: true |
| desc: undeploy the devcontainer in kubernetes |
| cmds: |
| - kubectl -n nuvolaris delete sts/ssh-devcontainer secret/ssh-secret |
| - echo Please remove the Host miniops entry from your ~/.ssh/config file if present |
| |
| kind-load: |
| silent: true |
| desc: load the devcontainer image from docker to kind to avoid pulling from outside |
| cmds: |
| - kind load docker-image {{.IMAGES_DEVCONTAINER}} --name nuvolaris |
| |
| docker-run: |
| desc: run the ssh-devcontainer in docker with W=<workspace absolute path> |
| silent: true |
| requires: { vars: [W]} |
| vars: |
| EXTRA: #"--entrypoint=/bin/bash -ti" |
| cmds: |
| - test -e "$OPS_PWD/workspace/package.json" || die "mising workdpace folder with starter" |
| - test -e ~/.ssh/id_rsa.pub || die "please generate an ssh key with 'ssk-keygen -t rsa'" |
| - echo "{{.W}}" | rg '^/' || die "W=<absolute path> required" |
| - docker rm -f ssh-devcontainer 2>/dev/null |
| - > |
| {{.DRY}} docker run |
| --hostname ssh-devcontainer |
| --name ssh-devcontainer --rm |
| -e SSHKEY="$(cat "{{.SSHKEY}}")" |
| -e USERID={{.UID}} |
| --mount "type=bind,src={{.W}},dst=/home/workspace" |
| -p 2223:2222 |
| {{.EXTRA}} |
| {{.IMAGES_DEVCONTAINER}} |
| |
| connect: |
| silent: true |
| desc: specify U=<user> and H=<host> to connect a remote devcontainer |
| requires: |
| vars: [H,U] |
| cmds: |
| - echo Connecting to {{.U}}@{{.H}} |
| - | |
| if ! test -e "{{.SSHKEY}}.pub" |
| then scp "{{.U}}@{{.H}}:.ssh/id_miniops" "{{.SSHKEY}}" && ssh-keygen -f "{{.SSHKEY}}" -y >"{{.SSHKEY}}.pub" |
| fi |
| if test -e "{{.SSHKEY}}.pub" |
| then echo Found "{{.SSHKEY}}" |
| else echo "Remote user has not a miniops configured" ; exit 1 |
| fi |
| - | |
| if ! rg '^Host miniops$' "{{.SSHDIR}}/config" >/dev/null |
| then cat <<EOF >>"{{.SSHDIR}}/config" |
| |
| Host miniops |
| ProxyJump remote-miniops |
| HostName localhost |
| Port 2222 |
| User devel |
| IdentityFile ~/.ssh/id_miniops |
| StrictHostKeyChecking no |
| UserKnownHostsFile /dev/null |
| EOF |
| else |
| echo Found ssh config miniops |
| fi |
| - | |
| if ! rg '^Host remote-miniops$' "{{.SSHDIR}}/config" >/dev/null |
| then cat <<EOF >>"{{.SSHDIR}}/config" |
| |
| Host remote-miniops |
| Hostname {{.H}} |
| User {{.U}} |
| IdentityFile ~/.ssh/id_miniops |
| EOF |
| echo Added ssh config remote-miniops |
| else |
| echo Found ssh config remote-miniops |
| fi |
| |
| - echo "You can now reach devcontainer with ssh miniops" |
| |
| |