split up build and run container

This commit is contained in:
Ad van der Veer
2016-02-14 15:01:33 +01:00
parent 4e1095f826
commit 42e2751e4e
5 changed files with 50 additions and 40 deletions

1
.gitignore vendored
View File

@@ -22,3 +22,4 @@ _testmain.go
*.exe *.exe
*.test *.test
*.prof *.prof
linux-amd64

View File

@@ -1,3 +0,0 @@
FROM microfactory/zero
RUN go get github.com/aktau/github-release
ENTRYPOINT ["./make.sh", "do-release"]

9
build.Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
FROM ubuntu:14.04
MAINTAINER Microfactory <info@microfactory.io>
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

77
make.sh
View File

@@ -3,32 +3,34 @@ set -e
function print_help { function print_help {
printf "Available Commands:\n"; printf "Available Commands:\n";
printf " release\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 \
printf " test\n" | 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 { #publish a new release to github
function run_release { # git tag v`cat VERSION` || true
git tag v`cat VERSION` || true # git push --tags
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
# }
: "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set in order to test}" function run_build { #build linux binary in a Docker container
run_build_container docker build -f build.Dockerfile -t microfactory/zero:build-`cat VERSION` .
docker build -t microfactory/zero:linux-release -f Dockerfile.release . docker run -it -v $PWD:/src/github.com/microfactory/zero --rm microfactory/zero:build-`cat VERSION`
docker run -it --rm -e "GITHUB_TOKEN=$GITHUB_TOKEN" microfactory/zero:linux-release
} }
function run_build_container { function run_run { #run a Linux test environment
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 {
: "${ZT_NET:?ZT_NET environment variable needs to be set in order to test}" : "${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}" : "${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 \ docker run -it --rm \
--device=/dev/net/tun \ --device=/dev/net/tun \
--cap-add=NET_ADMIN \ --cap-add=NET_ADMIN \
@@ -36,27 +38,28 @@ function run_test {
} }
# This is expected to be run INSIDE a container # This is expected to be run INSIDE a container
function do_release { # function do_release {
: "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set in order to test}" # : "${GITHUB_TOKEN:?GITHUB_TOKEN environment variable needs to be set in order to test}"
printf "Drafing release...\n" # printf "Drafing release...\n"
github-release release \ # github-release release \
--user microfactory \ # --user microfactory \
--repo zero \ # --repo zero \
--tag v`cat VERSION` \ # --tag v`cat VERSION` \
--pre-release # --pre-release
#
printf "Uploading...\n" # printf "Uploading...\n"
github-release upload \ # github-release upload \
--user microfactory \ # --user microfactory \
--repo zero \ # --repo zero \
--tag v`cat VERSION` \ # --tag v`cat VERSION` \
--name zero \ # --name zero \
--file /usr/local/bin/zero # --file /usr/local/bin/zero
} # }
case $1 in case $1 in
"do-release") do_release ;; "do-release") do_release ;;
"release") run_release ;; # "release") run_release ;;
"test") run_test ;; "build") run_build ;;
"run") run_run ;;
*) print_help ;; *) print_help ;;
esac esac