diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..948c674 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,34 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.8 + working_directory: /go/src/github.com/anaganisk/digitalocean-dynamic-dns-ip + steps: + - checkout + - attach_workspace: + at: ./releases + - run: + name: Build + command: | + echo 'export GO111MODULE=on' >> $BASH_ENV + source $BASH_ENV + ./ci-build-script.sh + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./releases/ + +workflows: + version: 2 + main: + jobs: + - build: + filters: + tags: + only: /^\d+\.\d+\.\d+$/ + - publish-github-release: + requires: + - build + filters: + branches: + ignore: /.*/ + tags: + only: /^\d+\.\d+\.\d+$/ diff --git a/.gitignore b/.gitignore index 7a004cc..42ce9ef 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ digitalocean-dynamic-dns-ip digitalocean-dynamic-ip.json # GoLand IDE -.idea/ \ No newline at end of file +.idea/ +releases \ No newline at end of file diff --git a/README.md b/README.md index 7cbf701..8f3628b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # DIGITAL OCEAN DYNAMIC IP API CLIENT + A simple script in Go language to automatically update Digital ocean DNS records if you have a dynamic IP. Since it can be compiled on any platform, you can use it along with raspberrypi etc. To find your Dynamic IP, this program will call out to https://ipv4bot.whatismyipaddress.com for ipv4 addresses and https://ipv6bot.whatismyipaddress.com for ipv6 addresses. This is to support dual-stack environments. (These URLs can be customized; see Usage, below.) ## Requirements -Requires Git, Go 1.8+, and https://github.com/mitchellh/go-homedir for building. + +Requires Git, Go 1.8+. Requires that the record already exists in DigitalOcean's DNS so that it can be updated. (manually find your IP and add it to DO's DNS it will later be updated) @@ -12,11 +14,18 @@ Requires that the record already exists in DigitalOcean's DNS so that it can be Requires a Digital Ocean API key that can be created at https://cloud.digitalocean.com/account/api/tokens. ## Building -You first need to install the "homedir" module if you aren't using it in another project. To install the module, run `go get github.com/mitchellh/go-homedir` -Once the module is fetched, you should be able to compile the program using `go build` +You first need to install the "homedir" module if you aren't using it in another project. To install the module. + +```bash +# Skip to next step, if you have GO111MODULE=on in your environment it is fetched automatically +go get github.com/mitchellh/go-homedir +# build the project +go build +``` ## Usage + ```bash # clone the repo in ~/go/src/github.com/anaganisk: git clone https://github.com/anaganisk/digitalocean-dynamic-dns-ip.git diff --git a/ci-build-script.sh b/ci-build-script.sh new file mode 100755 index 0000000..43948f4 --- /dev/null +++ b/ci-build-script.sh @@ -0,0 +1,27 @@ +#!/bin/bash +package=$1 +if [[ -z "$package" ]]; then + echo "usage: $0 " + exit 1 +fi +package_split=(${package//\// }) +package_name=${package_split[-1]} + +platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/386" "linux/amd64" "linux/arm" "linux/arm64") +mkdir releases +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + output_name=$package_name'-'$GOOS'-'$GOARCH + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + env GOOS=$GOOS GOARCH=$GOARCH go build -o releases/$output_name $package + if [ $? -ne 0 ]; then + echo 'An error has occurred! Aborting the script execution...' + exit 1 + fi +done \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e9fb58a --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/anaganisk/digitalocean-dynamic-dns-ip + +require github.com/mitchellh/go-homedir v1.1.0 + +go 1.13 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ae38d14 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=