diff --git a/.gitignore b/.gitignore index daf913b..c5d4355 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _testmain.go *.exe *.test *.prof +linux-amd64 diff --git a/Dockerfile.release b/Dockerfile.release deleted file mode 100644 index 6a1b979..0000000 --- a/Dockerfile.release +++ /dev/null @@ -1,3 +0,0 @@ -FROM microfactory/zero -RUN go get github.com/aktau/github-release -ENTRYPOINT ["./make.sh", "do-release"] diff --git a/VERSION b/VERSION index 1cc5f65..524cb55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1 diff --git a/build.Dockerfile b/build.Dockerfile new file mode 100644 index 0000000..18b7e69 --- /dev/null +++ b/build.Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:14.04 +MAINTAINER Microfactory +RUN apt-get update; apt-get install -y curl unzip git ; + +# install golang runtime +RUN curl -L https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz > /tmp/golang.tar.gz; tar -C /usr/local -xzf /tmp/golang.tar.gz; rm /tmp/golang.tar.gz +ENV GOPATH=/ GO15VENDOREXPERIMENT=1 PATH=$PATH:/usr/local/go/bin +WORKDIR /src/github.com/microfactory/zero +CMD GO15VENDOREXPERIMENT=1 go build -ldflags="-X main.version=`cat VERSION`" -o ./linux-amd64/zero main.go diff --git a/make.sh b/make.sh index 2f98c61..5b4d148 100755 --- a/make.sh +++ b/make.sh @@ -3,60 +3,63 @@ set -e function print_help { printf "Available Commands:\n"; - printf " release\n" - printf " test\n" + awk -v sq="'" '/^function run_([a-zA-Z0-9-]*)\s*/ {print "-e " sq NR "p" sq " -e " sq NR-1 "p" sq }' make.sh \ + | while read line; do eval "sed -n $line make.sh"; done \ + | paste -d"|" - - \ + | sed -e 's/^/ /' -e 's/function run_//' -e 's/#//' -e 's/{/ /' \ + | awk -F '|' '{ print " " $2 "\t" $1}' \ + | expand -t 20 } -#publish a new release to github -function run_release { - git tag v`cat VERSION` || true - git push --tags - - : "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set in order to test}" - run_build_container - docker build -t microfactory/zero:linux-release -f Dockerfile.release . - docker run -it --rm -e "GITHUB_TOKEN=$GITHUB_TOKEN" microfactory/zero:linux-release +function run_build { #build linux binary in a Docker container + docker build -f build.Dockerfile -t microfactory/zero:build-`cat VERSION` . + docker run -it -v $PWD:/src/github.com/microfactory/zero --rm microfactory/zero:build-`cat VERSION` } -function run_build_container { - docker build -t microfactory/zero:`cat VERSION` . - docker tag -f microfactory/zero:`cat VERSION` microfactory/zero:latest -} - -# run a Linux test environment -function run_test { +function run_run { #run a Linux test environment : "${ZT_NET:?ZT_NET environment variable needs to be set in order to test}" : "${ZT_TOKEN:?ZT_TOKEN environment variable needs to be set in order to test}" - run_build_container + docker build -f run.Dockerfile -t microfactory/zero:`cat VERSION` . docker run -it --rm \ --device=/dev/net/tun \ --cap-add=NET_ADMIN \ microfactory/zero:`cat VERSION` -start-daemon -name=test-member $ZT_NET $ZT_TOKEN } -# This is expected to be run INSIDE a container -function do_release { - : "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set in order to test}" - printf "Drafing release...\n" - github-release release \ - --user microfactory \ - --repo zero \ - --tag v`cat VERSION` \ - --pre-release +function run_draft-release { #draft a release for the current version + : "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set}" + printf "Tagging Commit and Push Tag...\n" + git tag v`cat VERSION` || true + git push --tags + printf "Drafting Release...\n" + version=$(cat VERSION) + json=$(printf '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": "Release of version %s","draft": false,"prerelease": false}' $version $version $version) + curl -H "Authorization: token $GITHUB_TOKEN" \ + --data "$json" https://api.github.com/repos/microfactory/zero/releases +} - printf "Uploading...\n" - github-release upload \ - --user microfactory \ - --repo zero \ - --tag v`cat VERSION` \ - --name zero \ - --file /usr/local/bin/zero +function run_upload-release { #upload binaries for current release + : "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set}" + version=$(cat VERSION) + relid=$(curl -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.manifold-preview" \ + "https://api.github.com/repos/microfactory/zero/releases" \ + | jq -c --arg version "$version" '.[] | select(.tag_name | contains($version)) | .id') + + printf "Uploading Files...\n" + curl -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.manifold-preview" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @linux-amd64/zero \ + "https://uploads.github.com/repos/microfactory/zero/releases/$relid/assets?name=zero_linux-amd64" } case $1 in "do-release") do_release ;; - "release") run_release ;; - "test") run_test ;; + "draft-release") run_draft-release ;; + "upload-release") run_upload-release ;; + "build") run_build ;; + "run") run_run ;; *) print_help ;; esac diff --git a/Dockerfile b/run.Dockerfile similarity index 100% rename from Dockerfile rename to run.Dockerfile