Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Migrate to go module (#35)
Browse files Browse the repository at this point in the history
migrate to go module
  • Loading branch information
honnix authored and wild-endeavor committed Jan 27, 2020
1 parent 519fcb1 commit 4e87c2c
Show file tree
Hide file tree
Showing 14 changed files with 1,624 additions and 32 deletions.
9 changes: 4 additions & 5 deletions flyteadmin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

# Using go1.10.4
FROM golang:1.13.3-alpine3.10 as builder
RUN apk add git openssh-client make curl dep
RUN apk add git openssh-client make curl

# COPY only the dep files for efficient caching
COPY Gopkg.* /go/src/github.com/lyft/flyteadmin/
# COPY only the go mod files for efficient caching
COPY go.mod go.sum /go/src/github.com/lyft/flyteadmin/
WORKDIR /go/src/github.com/lyft/flyteadmin

# Pull dependencies
RUN dep ensure -vendor-only
RUN go mod download

# COPY the rest of the source code
COPY . /go/src/github.com/lyft/flyteadmin/
Expand Down
6 changes: 1 addition & 5 deletions flyteadmin/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export GO111MODULE=off
export REPOSITORY=flyteadmin
include boilerplate/lyft/docker_build/Makefile
include boilerplate/lyft/golang_test_targets/Makefile
Expand Down Expand Up @@ -37,8 +36,5 @@ seed_projects:

all: compile

generate:
which pflags || (go get github.com/lyft/flytestdlib/cli/pflags)
which mockery || (go get github.com/enghabu/mockery/cmd/mockery)
which enumer || (go get github.com/alvaroloes/enumer)
generate: download_tooling
@go generate ./...
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

# Using go1.10.4
FROM golang:1.10.4-alpine3.8 as builder
RUN apk add git openssh-client make curl dep
FROM golang:1.13.3-alpine3.10 as builder
RUN apk add git openssh-client make curl

# COPY only the dep files for efficient caching
COPY Gopkg.* /go/src/github.com/lyft/{{REPOSITORY}}/
# COPY only the go mod files for efficient caching
COPY go.mod go.sum /go/src/github.com/lyft/{{REPOSITORY}}/
WORKDIR /go/src/github.com/lyft/{{REPOSITORY}}

# Pull dependencies
RUN dep ensure -vendor-only
RUN go mod download

# COPY the rest of the source code
COPY . /go/src/github.com/lyft/{{REPOSITORY}}/
Expand All @@ -25,7 +24,7 @@ RUN make linux_compile
ENV PATH="/artifacts:${PATH}"

# This will eventually move to centurylink/ca-certs:latest for minimum possible image size
FROM alpine:3.8
FROM alpine:3.10
COPY --from=builder /artifacts /bin

RUN apk --update add ca-certificates
Expand Down
12 changes: 12 additions & 0 deletions flyteadmin/boilerplate/lyft/golang_support_tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/lyft/boilerplate

go 1.13

require (
github.com/alvaroloes/enumer v1.1.2
github.com/golangci/golangci-lint v1.22.2
github.com/lyft/flytestdlib v0.2.31
github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5
)

replace github.com/vektra/mockery => github.com/enghabu/mockery v0.0.0-20191009061720-9d0c8670c2f0
558 changes: 558 additions & 0 deletions flyteadmin/boilerplate/lyft/golang_support_tools/go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions flyteadmin/boilerplate/lyft/golang_support_tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build tools

package tools

import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/lyft/flytestdlib/cli/pflags"
_ "github.com/vektra/mockery/cmd/mockery"
_ "github.com/alvaroloes/enumer"
)
30 changes: 18 additions & 12 deletions flyteadmin/boilerplate/lyft/golang_test_targets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst


.PHONY: download_tooling
download_tooling: #download dependencies (including test deps) for the package
@boilerplate/lyft/golang_test_targets/download_tooling.sh

.PHONY: lint
lint: #lints the package for common code smells
which golangci-lint || GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
# Calling lint twice here is a hack. The first call seem to fail when internally calling `go list...`
# However, that call seem to have some effects (e.g. https://github.com/golang/go/issues/29452) which, for some
# reason, allows the subsequent calls to succeed.
# TODO: Evaluate whether this is still a problem after moving admin dependency system to go modules.
GO111MODULE=off golangci-lint run --exclude deprecated -v || true
GO111MODULE=off golangci-lint run --deadline=5m --exclude deprecated -v
lint: download_tooling #lints the package for common code smells
GL_DEBUG=linters_output,env golangci-lint run --deadline=5m --exclude deprecated -v

# If code is failing goimports linter, this will fix.
# skips 'vendor'
.PHONY: goimports
goimports:
@boilerplate/lyft/golang_test_targets/goimports

.PHONY: mod_download
mod_download: #download dependencies (including test deps) for the package
go mod download

.PHONY: install
install: #download dependencies (including test deps) for the package
which dep || (curl "https://raw.githubusercontent.com/golang/dep/master/install.sh" | sh)
dep ensure --vendor-only
install: download_tooling mod_download

.PHONY: show
show:
go list -m all

.PHONY: test_unit
test_unit:
Expand All @@ -38,4 +43,5 @@ test_unit_cover:

.PHONY: test_unit_visual
test_unit_visual:
go test ./... -coverprofile /tmp/cover.out -covermode=count; go tool cover -html=/tmp/cover.out
go test ./... -coverprofile /tmp/cover.out -covermode=count; go tool cover -html=/tmp/cover.out

4 changes: 2 additions & 2 deletions flyteadmin/boilerplate/lyft/golang_test_targets/Readme.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Golang Test Targets
~~~~~~~~~~~~~~~~~~~

Provides an ``install`` make target that uses ``dep`` install golang dependencies.
Provides an ``install`` make target that uses ``go mod`` to install golang dependencies.

Provides a ``lint`` make target that uses golangci to lint your code.

Expand All @@ -17,7 +17,7 @@ Provides a ``test_benchmark`` target for benchmark tests.

Add ``lyft/golang_test_targets`` to your ``boilerplate/update.cfg`` file.

Make sure you're using ``dep`` for dependency management.
Make sure you're using ``go mod`` for dependency management.

Provide a ``.golangci`` configuration (the lint target requires it).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Everything in this file needs to be installed outside of current module
# The reason we cannot turn off module entirely and install is that we need the replace statement in go.mod
# because we are installing a mockery fork. Turning it off would result installing the original not the fork.
# We also want to version all the other tools. We also want to be able to run go mod tidy without removing the version
# pins. To facilitate this, we're maintaining two sets of go.mod/sum files - the second one only for tooling. This is
# the same approach that go 1.14 will take as well.
# See:
# https://github.com/lyft/flyte/issues/129
# https://github.com/golang/go/issues/30515 for some background context
# https://github.com/go-modules-by-example/index/blob/5ec250b4b78114a55001bd7c9cb88f6e07270ea5/010_tools/README.md

set -e

# List of tools to go get
# In the format of "<cli>:<package>" or ":<package>" if no cli
tools=(
"github.com/vektra/mockery/cmd/mockery"
"github.com/lyft/flytestdlib/cli/pflags"
"github.com/golangci/golangci-lint/cmd/golangci-lint"
"github.com/alvaroloes/enumer"
)

tmp_dir=$(mktemp -d -t gotooling-XXX)
echo "Using temp directory ${tmp_dir}"
cp -R boilerplate/lyft/golang_support_tools/* $tmp_dir
pushd "$tmp_dir"

for tool in "${tools[@]}"
do
echo "Installing ${tool}"
GO111MODULE=on go install $tool
done

popd
1 change: 1 addition & 0 deletions flyteadmin/boilerplate/update.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lyft/docker_build
lyft/golang_test_targets
lyft/golang_dockerfile
lyft/golang_support_tools
1 change: 1 addition & 0 deletions flyteadmin/boilerplate/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if [ -z "$REPOSITORY" ]; then
fi

while read directory; do
# TODO: Skip empty lines, whitespace only lines, and comment lines
echo "***********************************************************************************"
echo "$directory is configured in update.cfg."
echo "-----------------------------------------------------------------------------------"
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/cmd/entrypoints/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"fmt"
"testing"

"github.com/grpc/grpc-go/credentials/oauth"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/service"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/oauth"
)

func TestClient(t *testing.T) {
Expand Down
56 changes: 56 additions & 0 deletions flyteadmin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module github.com/lyft/flyteadmin

go 1.13

require (
github.com/NYTimes/gizmo v0.4.3
github.com/Selvatico/go-mocket v1.0.7
github.com/aws/aws-sdk-go v1.28.9
github.com/benbjohnson/clock v1.0.0
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
github.com/coreos/go-oidc v2.1.0+incompatible
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/gogo/protobuf v1.3.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.3.2
github.com/gorilla/handlers v1.4.2
github.com/gorilla/securecookie v1.1.1
github.com/graymeta/stow v0.2.4
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.12.2
github.com/imdario/mergo v0.3.8 // indirect
github.com/jinzhu/gorm v1.9.12
github.com/json-iterator/go v1.1.9 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/lib/pq v1.3.0
github.com/lyft/flyteidl v0.17.0
github.com/lyft/flytepropeller v0.1.30
github.com/lyft/flytestdlib v0.3.0
github.com/magiconair/properties v1.8.1
github.com/mitchellh/mapstructure v1.1.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.3.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.15.1-0.20200117000758-b4cd77d6a56c // indirect
google.golang.org/grpc v1.26.0
gopkg.in/gormigrate.v1 v1.6.0
k8s.io/apimachinery v0.17.2
k8s.io/client-go v11.0.0+incompatible
k8s.io/utils v0.0.0-20200109141947-94aeca20bf09 // indirect
sigs.k8s.io/controller-runtime v0.3.1-0.20191029211253-40070e2a1958
)

// Pin the version of client-go to something that's compatible with katrogan's fork of api and apimachinery
// Type the following
// replace k8s.io/client-go => k8s.io/client-go kubernetes-1.16.2
// and it will be replaced with the 'sha' variant of the version

replace (
k8s.io/api => github.com/lyft/api v0.0.0-20191031200350-b49a72c274e0
k8s.io/apimachinery => github.com/lyft/apimachinery v0.0.0-20191031200210-047e3ea32d7f
k8s.io/client-go => k8s.io/client-go v0.0.0-20191016111102-bec269661e48
)
Loading

0 comments on commit 4e87c2c

Please sign in to comment.