Skip to content

Commit

Permalink
get rid of commons module
Browse files Browse the repository at this point in the history
  • Loading branch information
avarabyeu committed Jul 9, 2024
1 parent a5856a5 commit db7815c
Show file tree
Hide file tree
Showing 18 changed files with 731 additions and 68 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ on:

env:
GODIRS_NOVENDOR: '`go list ./... | grep -v /vendor/`'
PACKAGE_COMMONS: 'github.com/reportportal/commons-go/v5'
PACKAGE_COMMONS: 'github.com/reportportal/service-index'
BINARY_DIR: 'bin'
BUILD_INFO_LDFLAGS: >-
-ldflags "-extldflags '"-static"'
-X ${PACKAGE_COMMONS}/commons.repo=${GITHUB_REPOSITORY}
-X ${PACKAGE_COMMONS}/commons.branch=${GITHUB_SHA}
-X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE}
-X ${PACKAGE_COMMONS}/commons.version=${VERSION}"
-X ${PACKAGE_COMMONS}/buildinfo.repo=${GITHUB_REPOSITORY}
-X ${PACKAGE_COMMONS}/buildinfo.branch=${GITHUB_SHA}
-X ${PACKAGE_COMMONS}/buildinfo.buildDate=${BUILD_DATE}
-X ${PACKAGE_COMMONS}/buildinfo.version=${VERSION}"
jobs:
build:
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG APP_VERSION=develop
ARG PACKAGE_COMMONS=github.com/reportportal/commons-go/v5
ARG PACKAGE_COMMONS=github.com/reportportal/service-index
ARG REPO_NAME=reportportal/service-index
ARG BUILD_BRANCH
ARG BUILD_DATE
Expand All @@ -18,10 +18,10 @@ RUN echo "I am running on ${BUILDPLATFORM}, building for TargetOS: $TARGETOS and

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags "-extldflags '"-static"' \
-X ${PACKAGE_COMMONS}/commons.repo=${REPO_NAME} \
-X ${PACKAGE_COMMONS}/commons.branch=${BUILD_BRANCH} \
-X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE} \
-X ${PACKAGE_COMMONS}/commons.version=${APP_VERSION}" \
-X ${PACKAGE_COMMONS}/buildinfo.repo=${REPO_NAME} \
-X ${PACKAGE_COMMONS}/buildinfo.branch=${BUILD_BRANCH} \
-X ${PACKAGE_COMMONS}/buildinfo.buildDate=${BUILD_DATE} \
-X ${PACKAGE_COMMONS}/buildinfo.version=${APP_VERSION}" \
-o app ./

FROM --platform=${BUILDPLATFORM} alpine:3.20.0
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ BUILD_DEPS:= github.com/avarabyeu/releaser@master
GODIRS_NOVENDOR = $(shell go list ./... | grep -v /vendor/)
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
PWD = $(shell pwd)
PACKAGE_COMMONS=github.com/reportportal/commons-go/v5
PACKAGE_COMMONS=github.com/reportportal/service-index
REPO_NAME=reportportal/service-index

BUILD_INFO_LDFLAGS=-ldflags "-extldflags '"-static"' -X ${PACKAGE_COMMONS}/commons.repo=${REPO_NAME} -X ${PACKAGE_COMMONS}/commons.branch=${COMMIT_HASH} -X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE} -X ${PACKAGE_COMMONS}/commons.version=${v}"
BUILD_INFO_LDFLAGS=-ldflags "-extldflags '"-static"' -X ${PACKAGE_COMMONS}/buildinfo.repo=${REPO_NAME} -X ${PACKAGE_COMMONS}/buildinfo.branch=${COMMIT_HASH} -X ${PACKAGE_COMMONS}/buildinfo.buildDate=${BUILD_DATE} -X ${PACKAGE_COMMONS}/buildinfo.version=${v}"
IMAGE_NAME=reportportal-dev/service-index$(IMAGE_POSTFIX)

.PHONY: get-build-deps vendor test build
Expand Down Expand Up @@ -47,7 +47,7 @@ fmt:
# Builds server
build:
CGO_ENABLED=0 GOOS=linux $(GO) build ${BUILD_INFO_LDFLAGS} -o ${BINARY_DIR}/service-index ./
# CGO_ENABLED=0 $(GO) build ${BUILD_INFO_LDFLAGS} -o ${BINARY_DIR}/service-index ./
#CGO_ENABLED=0 $(GO) build ${BUILD_INFO_LDFLAGS} -o ${BINARY_DIR}/service-index ./


# Builds server
Expand Down
35 changes: 35 additions & 0 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package buildinfo

var (
// Branch contains the current Git revision. Use make to build to make
// sure this gets set.
branch string

// BuildDate contains the date of the current build.
buildDate string

// Version contains version
version string

// Version contains repository name
repo string
)

// BuildInfo contains information about the current build
type BuildInfo struct {
Version string `json:"version,omitempty"`
Branch string `json:"branch,omitempty"`
BuildDate string `json:"build_date,omitempty"`
Name string `json:"name,omitempty"`
Repo string `json:"repo,omitempty"`
}

// GetBuildInfo returns build info data
func GetBuildInfo() *BuildInfo {
return &BuildInfo{
Version: version,
Branch: branch,
BuildDate: buildDate,
Repo: repo,
}
}
27 changes: 27 additions & 0 deletions buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package buildinfo

import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

func TestBuildInfo(t *testing.T) {
buildInfo := GetBuildInfo()
buildInfo.Name = "test"
rr := httptest.NewRecorder()
rr.WriteHeader(http.StatusOK)
e := json.NewEncoder(rr).Encode(buildInfo)
// Check the status code is what we expect.
if nil != e {
t.Error("Something went wrong with serialization")
}

expected := `{"name":"test"}`
if strings.TrimSpace(rr.Body.String()) != expected {
t.Errorf("incorrect build format response: got %v want %v",
rr.Body.String(), expected)
}
}
31 changes: 16 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,55 @@ go 1.22.0
toolchain go1.22.3

require (
github.com/go-chi/chi/v5 v5.0.12
github.com/caarlos0/env/v10 v10.0.0
github.com/go-chi/chi/v5 v5.1.0
github.com/go-playground/validator/v10 v10.22.0
github.com/go-resty/resty/v2 v2.13.1
github.com/reportportal/commons-go/v5 v5.0.12
github.com/onsi/gomega v1.33.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/vulcand/predicate v1.2.0
k8s.io/apimachinery v0.30.1
k8s.io/client-go v0.30.1
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
)

require (
github.com/caarlos0/env/v10 v10.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.17.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gravitational/trace v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.30.1 // indirect
k8s.io/api v0.30.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
Expand Down
Loading

0 comments on commit db7815c

Please sign in to comment.