Skip to content

Conversation

@Meoop
Copy link
Contributor

@Meoop Meoop commented Sep 10, 2019

What this PR does / why we need it:

在新版本的 Golang 中,GOPATH 环境变量可以不设置,当系统未设置 GOPATH 环境变量时,golangci-lint 将安装到 /bin 目录下,安装错位置。使用 go env GOPATH 命令获取 GOPATH 路径可以应对所有的场景。

参考 golangci-lint 将 GOPATH 换成 go env GOPATHgolangci/golangci-lint#319

Which issue(s) this PR is related to (optional, link to 3rd issue(s)):

Fixes #

Reference to #

Special notes for your reviewer:

/cc @bbbmj

Release note:

NONE

@caicloud-bot caicloud-bot added release-note-none Denotes a PR that doesn't merit a release note. caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 10, 2019
@Meoop
Copy link
Contributor Author

Meoop commented Sep 10, 2019

/cc @bbbmj

@caicloud-bot caicloud-bot requested a review from bbbmj September 10, 2019 11:58
DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --tags --always --dirty)"

# Golang standard bin directory.
GOPATH ?= $(shell go env GOPATH)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about including this in #5? @Meoop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在流水线执行的时候,代码构建阶段的环境没有装 go,而是通过启 go 容器运行的,会有问题。
之前将 PKGS 变量去掉,就是基于这个原因

@zhujian7 确认一下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有装 go 的话,GOPATH 也是另外设置的好像?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或许安装到项目的 bin 目录也是个不错的选择?

# install it into ./bin/
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile 不兼容本地环境么?新安装的 golang 本地是不一定会设置 GOPATH 环境变量的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用 GOPATH:

  • 基础镜像不需要装 go
  • 流水线需要额外设置 GOPATH
  • 每个研发自己的电脑,需要装 go 并设置 GOPATH

使用 go env GOPATH:

  • 基础镜像需要装 go
  • 流水线不需要额外设置 GOPATH
  • 每个研发自己的电脑,只需要装 go,不需要设置 GOPATH

综合看,我觉得设置成 go env GOPATH 可能好一点?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用纠结吧,加个判断,存在 go 就 go env GOPATH,不存在就按照之前的

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Meoop 乐乐说的这种方式可以吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en,和上面写法比较类似吧,GOPATH ?= $(shell go env GOPATH),如果有 GOPATH 这个环境变量,就不会执行 shell 了,也就不检测 go 存不存在,只有不存在 GOPATH 的时候才去调用 go 命令。

@zhujian7
Copy link
Contributor

/hold

@caicloud-bot caicloud-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 11, 2019
@supereagle
Copy link
Member

流水线上肯定不存在这个问题,本地开发环境的话,建议手动设置 GOPATH(一次性操作)。因此,没有必要通过 go env GOPATH 自动获取,建议 close 这个 PR。@Meoop WDYT?

@Meoop
Copy link
Contributor Author

Meoop commented Sep 11, 2019

说实话,我并不认为 “本地开发环境的话,建议手动设置 GOPATH(一次性操作)” 是一个好的方案...

如果远程是通过启动一个 Golang 镜像去跑 lint ,那还不如直接用 golangci-lint 镜像呢,还少一次 curl。

@lsytj0413
Copy link

我们不是准备切换到 go module 了么,到时候 GOPATH 直接基本就没用了;那么这段过渡时间是否值得改这个?
然后基础镜像为啥要装 go 啊......

@Meoop
Copy link
Contributor Author

Meoop commented Sep 11, 2019

我们不是准备切换到 go module 了么,到时候 GOPATH 直接基本就没用了;那么这段过渡时间是否值得改这个?

@lsytj0413 这个改动就是由于系统不设置 GOPATH 这个环境变量导致的,切换到 go module,GOPATH 这个环境变量估计也没有人会去设置了,到时候根据 $GOPATH 环境变量去保存 golangci-lint 二进制就会出现问题($GOPATH 为空,下载到 /bin 下,普通用户是没有权限的)。

@zhujian7
Copy link
Contributor

image

验证完了,对 build-linux 没有影响,可以加 go env GOPATH
/hold cancel

/cc @Meoop @supereagle @bbbmj

@caicloud-bot caicloud-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 11, 2019
@caicloud-bot
Copy link

@zhujian7: GitHub didn't allow me to request PR reviews from the following users: Meoop.

Note that only caicloud members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

image

验证完了,对 build-linux 没有影响,可以加 go env GOPATH
/hold cancel

/cc @Meoop @supereagle @bbbmj

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the caicloud/tools repository.

@caicloud-bot caicloud-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 11, 2019
@bbbmj
Copy link
Member

bbbmj commented Sep 11, 2019

/lgtm

@caicloud-bot caicloud-bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 11, 2019
@caicloud-bot caicloud-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 11, 2019
GOPATH environment variable may be empty, go env GOPATH will work for all cases.
@Meoop
Copy link
Contributor Author

Meoop commented Sep 11, 2019

/reopen

@caicloud-bot caicloud-bot reopened this Sep 11, 2019
@caicloud-bot caicloud-bot reopened this Sep 11, 2019
@caicloud-bot caicloud-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 11, 2019
@supereagle
Copy link
Member

/lgtm

@caicloud-bot caicloud-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 11, 2019
@caicloud-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bbbmj, supereagle

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caicloud-bot caicloud-bot merged commit ea379e5 into caicloud:master Sep 11, 2019
@bbbmj
Copy link
Member

bbbmj commented Sep 11, 2019

@Meoop please cherry-pick to https://github.com/caicloud/nirvana-template-project

@supereagle
Copy link
Member

@Meoop please cherry-pick to https://github.com/caicloud/nirvana-template-project

I will update Makefile for this project including my changes.

@supereagle
Copy link
Member

Cherry pick to caicloud/nirvana-template-project by caicloud/nirvana-template-project#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants