From f1f66a0f3b6a1062ca084894ceff95eb4e339591 Mon Sep 17 00:00:00 2001 From: Brian Cunnie Date: Sun, 3 Oct 2021 14:48:38 +0100 Subject: [PATCH] `dig txt version.sslip.io` returns version I needed a way of determining the version that a server was running. I orginally considered a command-line argument, but then I thought, "Why not create a DNS record for it? That way I can query running servers without needing to ssh onto the machine." The TXT record consists of three distinct strings: version, compile date, and git hash. ```bash dig txt version.sslip.io +short "2.2.1" "2021/10/03-15:08:54+0100" "6a928eb" ``` --- bin/make_all | 10 +++++-- .../sslip.io-dns-server/integration_test.go | 4 +++ .../src/sslip.io-dns-server/xip/xip.go | 26 ++++++++++++++----- docs/DEVELOPER.md | 7 +++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/bin/make_all b/bin/make_all index fd8bda3..de9e67b 100755 --- a/bin/make_all +++ b/bin/make_all @@ -4,12 +4,18 @@ # DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" cd $DIR/../src/sslip.io-dns-server - +ldflags="-X xip/xip.VersionSemantic=2.2.0 \ + -X xip/xip.VersionDate=$(date +%Y/%m/%d-%H:%M:%S%z) \ + -X xip/xip.VersionGitHash=$(git rev-parse --short HEAD)" export GOOS GOARCH + # Bring in ARM64 for my AWS Graviton2 instance for GOARCH in amd64 arm64; do for GOOS in darwin linux freebsd; do - go build -o $DIR/sslip.io-dns-server-$GOOS-$GOARCH main.go + go build \ + -ldflags="$ldflags" \ + -o $DIR/sslip.io-dns-server-$GOOS-$GOARCH \ + main.go done done diff --git a/bosh-release/src/sslip.io-dns-server/integration_test.go b/bosh-release/src/sslip.io-dns-server/integration_test.go index 6ad2be7..8459670 100644 --- a/bosh-release/src/sslip.io-dns-server/integration_test.go +++ b/bosh-release/src/sslip.io-dns-server/integration_test.go @@ -109,6 +109,10 @@ var _ = Describe("sslip.io-dns-server", func() { "@localhost example.com srv +short", `\A\z`, `TypeSRV example.com. \? nil, SOA example.com. briancunnie.gmail.com. 2021080200 900 900 1800 300\n$`), + Entry(`TXT for version.sslip.io is the version number of the xip software (which gets overwritten during linking)`, + "@127.0.0.1 version.sslip.io txt +short", + `\A"dev"\n"today"\n"xxx"\n\z`, + `TypeTXT version.sslip.io. \? \["dev"\], \["today"\], \["xxx"\]`), Entry(`TXT is the querier's IPv4 address and the TLD is "ip."`, "@127.0.0.1 blah.blah.ip txt +short", `127.0.0.1`, diff --git a/bosh-release/src/sslip.io-dns-server/xip/xip.go b/bosh-release/src/sslip.io-dns-server/xip/xip.go index 93861bd..8ba5acf 100644 --- a/bosh-release/src/sslip.io-dns-server/xip/xip.go +++ b/bosh-release/src/sslip.io-dns-server/xip/xip.go @@ -14,7 +14,7 @@ import ( ) // DomainCustomization is a value that is returned for a specific query. -// The map key is the the domain in question, e.g. "sslip.io." (always include trailing dot). +// The map key is the domain in question, e.g. "sslip.io." (always include trailing dot). // For example, when querying for MX records for "sslip.io", return the protonmail servers, // but when querying for MX records for generic queries, e.g. "127.0.0.1.sslip.io", return the // default (which happens to be no MX records). @@ -51,12 +51,17 @@ var ( {NS: nsGce}, } - mbox, _ = dnsmessage.NewName("briancunnie.gmail.com.") - mx1, _ = dnsmessage.NewName("mail.protonmail.ch.") - mx2, _ = dnsmessage.NewName("mailsec.protonmail.ch.") - dkim1, _ = dnsmessage.NewName("protonmail.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") - dkim2, _ = dnsmessage.NewName("protonmail2.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") - dkim3, _ = dnsmessage.NewName("protonmail3.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") + mbox, _ = dnsmessage.NewName("briancunnie.gmail.com.") + mx1, _ = dnsmessage.NewName("mail.protonmail.ch.") + mx2, _ = dnsmessage.NewName("mailsec.protonmail.ch.") + dkim1, _ = dnsmessage.NewName("protonmail.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") + dkim2, _ = dnsmessage.NewName("protonmail2.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") + dkim3, _ = dnsmessage.NewName("protonmail3.domainkey.dw4gykv5i2brtkjglrf34wf6kbxpa5hgtmg2xqopinhgxn5axo73a.domains.proton.ch.") + + VersionSemantic = "dev" + VersionDate = "today" + VersionGitHash = "xxx" + Customizations = DomainCustomizations{ "sslip.io.": { A: []dnsmessage.AResource{ @@ -115,6 +120,13 @@ var ( CNAME: dkim3, }, }, + "version.sslip.io.": { + TXT: []dnsmessage.TXTResource{ + {TXT: []string{VersionSemantic}}, // e.g. "2.2.1' + {TXT: []string{VersionDate}}, // e.g. "2021/10/03-15:08:54+0100" + {TXT: []string{VersionGitHash}}, // e.g. "9339c0d" + }, + }, } ) diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index b1f4e8a..f20c3f2 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -6,9 +6,12 @@ they might not make sense unless you're on my workstation. ```zsh export OLD_VERSION=2.1.2 export VERSION=2.2.0 -cd ~/go/src/github.com/cunnie/sslip.io +cd ~/workspace/sslip.io git pull -r --autostash -sed -i '' "s~/$OLD_VERSION/~/$VERSION/~g" k8s/document_root/index.html # update the download instructions on the website +# update the version number for the TXT record for version.sslip.io +sed -i '' "s/$OLD_VERSION/$VERSION/g" bin/make_all +# update the download instructions on the website +sed -i '' "s~/$OLD_VERSION/~/$VERSION/~g" k8s/document_root/index.html cd bosh-release/ lpass show a # refresh LastPass token . ~/workspace/deployments/.envrc # set BOSH auth