Skip to content

Commit

Permalink
Use Orb Development Kit structure
Browse files Browse the repository at this point in the history
This takes the existing sources (with only minor formatting modifications)
and transforms it into the structure proposed by the [CircleCI Orb Template](https://github.com/CircleCI-Public/Orb-Template)
v1.0.3.

This enables automated linting and testing, cf. https://circleci.com/docs/testing-orbs.

FIXME: Needs a `circleci-orb-registry` context for publishing to the CircleCI Orb Registry!
  • Loading branch information
devurandom committed Aug 10, 2022
1 parent ab96676 commit 9b29fdc
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 63 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: 2.1
setup: true
orbs:
orb-tools: circleci/[email protected]
shellcheck: circleci/[email protected]

filters: &filters
tags:
only: /.*/

workflows:
lint-pack:
jobs:
- orb-tools/lint:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/review:
filters: *filters
- shellcheck/check:
filters: *filters
- orb-tools/publish:
orb-name: threecomma/circleci-tailscale
vcs-type: << pipeline.project.type >>
requires:
[orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
context: circleci-orb-registry
filters: *filters
# Triggers the next workflow in the Orb Development Kit.
- orb-tools/continue:
pipeline-number: << pipeline.number >>
vcs-type: << pipeline.project.type >>
requires: [orb-tools/publish]
filters: *filters
41 changes: 41 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2.1
orbs:
circleci-tailscale: threecomma/circleci-tailscale@dev:<<pipeline.git.revision>>
orb-tools: circleci/[email protected]

filters: &filters
tags:
only: /.*/

jobs:
command-tests:
docker:
- image: cimg/base:current
steps:
- circleci-tailscale/download
- run:
name: verify install
command: |
command -v tailscale
command -v tailscaled
workflows:
test-deploy:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
- command-tests:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/publish:
orb-name: threecomma/circleci-tailscale
vcs-type: << pipeline.project.type >>
pub-type: production
requires:
- orb-tools/pack
- command-tests
context: circleci-orb-registry
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
63 changes: 0 additions & 63 deletions orb.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2.1
description: >
CircleCI Orb for connecting to [Tailscale VPN](https://tailscale.com/).
display:
home_url: "https://github.com/threecommaio/circleci-tailscale"
source_url: "https://github.com/threecommaio/circleci-tailscale"
32 changes: 32 additions & 0 deletions src/commands/connect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description: Connect tailscale
parameters:
tailscale-auth-key:
type: env_var_name
description: Your Tailscale authentication key, from the admin panel.
default: TAILSCALE_AUTH_KEY
tailscale-proxy-address:
type: string
description: Proxy address where tailscale should listen.
default: localhost
tailscale-version:
type: string
description: Tailscale version to use.
default: "1.24.2"
steps:
- run:
name: "Download tailscale if not installed"
environment:
VERSION: "<<parameters.tailscale-version>>"
command: <<include(scripts/download.sh)>>
- run:
name: "Run tailscale"
background: true
environment:
PROXY: "<<parameters.tailscale-proxy-address>>"
command: <<include(scripts/run.sh)>>
- run:
name: "Auth tailscale"
environment:
TAILSCALE_AUTH_KEY: "<<parameters.tailscale-auth-key>>"
PROXY: "<<parameters.tailscale-proxy-address>>"
command: <<include(scripts/auth.sh)>>
22 changes: 22 additions & 0 deletions src/examples/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
description: >
1. Set the `TAILSCALE_AUTH_KEY` via your CircleCI project settings or
create a context containing it.
2. In the job that needs a tailscale VPN connection, run the
`circleci-tailscale/connect` step.
- Make sure that job uses the context with `TAILSCALE_AUTH_KEY`,
if you use contexts instead of project settings.
usage:
version: 2.1
orbs:
circleci-tailscale: threecomma/[email protected]
jobs:
job-with-tailscale:
docker:
- image: cimg/base
steps:
- circleci-tailscale/connect
workflows:
workflow-with-tailscale:
jobs:
- job-with-tailscale:
context: <context-with-TAILSCALE_AUTH_KEY>
19 changes: 19 additions & 0 deletions src/scripts/auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

until tailscale \
--socket=/tmp/tailscaled.sock \
up \
--authkey="${TAILSCALE_AUTH_KEY}" \
--hostname="circleci-$(hostname)" \
--accept-routes
do
sleep 1
done

cat <<- EOF >> "${BASH_ENV}"
export ALL_PROXY=socks5h://${PROXY}:1055/
export HTTP_PROXY=http://${PROXY}:1054/
export HTTPS_PROXY=http://${PROXY}:1054/
export http_proxy=http://${PROXY}:1054/
export https_proxy=http://${PROXY}:1054/
EOF
23 changes: 23 additions & 0 deletions src/scripts/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

if ! command -v tailscale --version > /dev/null 2>&1
then
echo "Tailscale is not installed, installing..."
MINOR=$(echo "${VERSION}" | awk -F '.' '{print $2}')

if [ $((MINOR % 2)) -eq 0 ]
then
URL="https://pkgs.tailscale.com/stable/tailscale_${VERSION}_amd64.tgz"
else
URL="https://pkgs.tailscale.com/unstable/tailscale_${VERSION}_amd64.tgz"
fi

curl "${URL}" -o tailscale.tgz
tar -C "${HOME}" -xzf tailscale.tgz
rm tailscale.tgz

TSPATH="${HOME}/tailscale_${VERSION}_amd64"
sudo mv "${TSPATH}/tailscale" "${TSPATH}/tailscaled" /usr/bin
else
echo "Tailscale is already installed"
fi
8 changes: 8 additions & 0 deletions src/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

exec tailscaled \
--tun=userspace-networking \
--outbound-http-proxy-listen="${PROXY}":1054 \
--socks5-server="${PROXY}":1055 \
--socket=/tmp/tailscaled.sock \
2> ~/tailscaled.log
10 changes: 10 additions & 0 deletions src/tests/download.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bats

@test "downloads and installs tailscale" {
env \
VERSION=1.24.2 \
./src/scripts/download.sh

test -x /usr/bin/tailscale
test -x /usr/bin/tailscaled
}

0 comments on commit 9b29fdc

Please sign in to comment.