-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated to travis-CI and simple build
- Loading branch information
Showing
21 changed files
with
458 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
.git | ||
/.idea | ||
*.iml | ||
.idea | ||
build/gopath | ||
.gradle | ||
vendor | ||
/out | ||
/var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/.idea | ||
*.iml | ||
.idea | ||
build | ||
.gradle | ||
vendor | ||
/out | ||
/dist | ||
/var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
language: go | ||
go: | ||
- 1.12.3 | ||
install: skip | ||
os: | ||
- linux | ||
services: | ||
- docker | ||
env: | ||
global: | ||
- GO111MODULE=on | ||
- CGO_ENABLED=0 | ||
- GOOS=linux | ||
- GOARCH=amd64 | ||
cache: | ||
directories: | ||
- $HOME/.cache/go-build | ||
- $HOME/gopath/pkg/mod | ||
script: skip | ||
|
||
jobs: | ||
include: | ||
- stage: test | ||
name: Run Tests | ||
script: | ||
- go run ./build test | ||
- stage: release | ||
name: Release | ||
if: tag =~ ^v\d+\.\d+\.\d+|snapshot-.+$ | ||
before_script: | ||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | ||
script: | ||
- go run ./build build-and-deploy | ||
deploy: | ||
provider: releases | ||
api_key: "$GITHUB_DEPLOY_TOKEN" | ||
file_glob: true | ||
file: dist/* | ||
skip_cleanup: true | ||
name: $TRAVIS_TAG | ||
on: | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
FROM scratch | ||
MAINTAINER [email protected] | ||
|
||
COPY build/out/site24x7_exporter-linux-amd64 /usr/bin/site24x7_exporter | ||
ENV PATH=/usr/bin | ||
COPY dist/site24x7_exporter-linux-amd64 /usr/bin/site24x7_exporter | ||
|
||
ENTRYPOINT ["/usr/bin/site24x7_exporter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func build(branch, commit string) { | ||
buildBinaries(branch, commit) | ||
|
||
if withDocker { | ||
buildDocker(branch, dv, false) | ||
tagDocker(branch, dv, false) | ||
} | ||
} | ||
|
||
func buildBinaries(branch, commit string) { | ||
for _, t := range targets { | ||
buildBinary(branch, commit, t, false) | ||
} | ||
} | ||
|
||
func buildBinary(branch, commit string, t target, forTesting bool) { | ||
ldFlags := buildLdFlagsFor(branch, commit, forTesting) | ||
outputName := t.outputName() | ||
must(os.MkdirAll(filepath.Dir(outputName), 0755)) | ||
executeTo(func(cmd *exec.Cmd) { | ||
cmd.Env = append(os.Environ(), "GOOS="+t.os, "GOARCH="+t.arch) | ||
}, os.Stderr, os.Stdout, "go", "build", "-ldflags", ldFlags, "-o", outputName, ".") | ||
} | ||
|
||
func buildLdFlagsFor(branch, commit string, forTesting bool) string { | ||
testPrefix := "" | ||
testSuffix := "" | ||
if forTesting { | ||
testPrefix = "TEST" | ||
testSuffix = "TEST" | ||
} | ||
return fmt.Sprintf("-X main.version=%s%s%s", testPrefix, branch, testSuffix) + | ||
fmt.Sprintf(" -X main.revision=%s%s%s", testPrefix, commit, testSuffix) + | ||
fmt.Sprintf(" -X main.compiled=%s", startTime.Format("2006-01-02T15:04:05Z")) | ||
} | ||
|
||
func buildDocker(branch string, v dockerVariant, forTesting bool) { | ||
version := branch | ||
if forTesting { | ||
version = "TEST" + version + "TEST" | ||
} | ||
execute("docker", "build", "-t", v.imageName(version), "-f", v.dockerFile, "--build-arg", "image="+imagePrefix, "--build-arg", "version="+version, ".") | ||
} | ||
|
||
func tagDocker(branch string, v dockerVariant, forTesting bool) { | ||
version := branch | ||
if forTesting { | ||
version = "TEST" + version + "TEST" | ||
} | ||
executeForVersionParts(version, func(tagSuffix string) { | ||
tagDockerWith(version, v, v.imageName(tagSuffix)) | ||
}) | ||
if latestVersionPattern != nil && latestVersionPattern.MatchString(version) { | ||
tagDockerWith(version, v, v.baseImageName()) | ||
} | ||
if v.main { | ||
tagDockerWith(version, v, imagePrefix+":"+version) | ||
executeForVersionParts(version, func(tagSuffix string) { | ||
tagDockerWith(version, v, imagePrefix+":"+tagSuffix) | ||
}) | ||
if latestVersionPattern != nil && latestVersionPattern.MatchString(version) { | ||
tagDockerWith(version, v, imagePrefix+":latest") | ||
} | ||
} | ||
} | ||
|
||
func tagDockerWith(branch string, v dockerVariant, tag string) { | ||
execute("docker", "tag", v.imageName(branch), tag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
func deploy(branch string) { | ||
deployDocker(branch, dv) | ||
} | ||
|
||
func deployDocker(branch string, v dockerVariant) { | ||
deployDockerTag(v.imageName(branch)) | ||
executeForVersionParts(branch, func(tagSuffix string) { | ||
deployDockerTag(v.imageName(tagSuffix)) | ||
}) | ||
if latestVersionPattern != nil && latestVersionPattern.MatchString(branch) { | ||
deployDockerTag(v.baseImageName()) | ||
} | ||
if v.main { | ||
deployDockerTag(imagePrefix + ":" + branch) | ||
executeForVersionParts(branch, func(tagSuffix string) { | ||
deployDockerTag(imagePrefix + ":" + tagSuffix) | ||
}) | ||
if latestVersionPattern != nil && latestVersionPattern.MatchString(branch) { | ||
deployDockerTag(imagePrefix + ":latest") | ||
} | ||
} | ||
} | ||
|
||
func deployDockerTag(tag string) { | ||
execute("docker", "push", tag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
) | ||
|
||
var ( | ||
branch = "snapshot" | ||
commit = "unknown" | ||
withDocker = true | ||
plainLatestVersionPattern string | ||
latestVersionPattern *regexp.Regexp | ||
) | ||
|
||
func init() { | ||
flag.StringVar(&branch, "branch", os.Getenv("TRAVIS_BRANCH"), "something like either main, v1.2.3 or snapshot-feature-foo") | ||
flag.StringVar(&commit, "commit", os.Getenv("TRAVIS_COMMIT"), "something like 463e189796d5e96a7b605ab51985458faf8fd0d4") | ||
flag.BoolVar(&withDocker, "withDocker", true, "enables docker tests and builds") | ||
flag.StringVar(&plainLatestVersionPattern, "latestVersionPattern", os.Getenv("LATEST_VERSION_PATTERN"), "everything what matches here will be a latest tag") | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
if branch == "" { | ||
branch = "development" | ||
} | ||
if commit == "" { | ||
commit = "development" | ||
} | ||
if compiled, err := regexp.Compile(plainLatestVersionPattern); err != nil { | ||
panic(err) | ||
} else { | ||
latestVersionPattern = compiled | ||
} | ||
fArgs := flag.Args() | ||
if len(fArgs) != 1 { | ||
usage() | ||
} | ||
switch fArgs[0] { | ||
case "build": | ||
build(branch, commit) | ||
case "test": | ||
test(branch, commit) | ||
case "deploy": | ||
deploy(branch) | ||
case "build-and-deploy": | ||
build(branch, commit) | ||
deploy(branch) | ||
default: | ||
usage() | ||
} | ||
} | ||
|
||
func usage() { | ||
_, _ = fmt.Fprintf(os.Stderr, "Usage: %s [flags] <command>", os.Args[0]) | ||
os.Exit(1) | ||
} |
Oops, something went wrong.