Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable buildvcs #20056

Closed
wants to merge 2 commits into from
Closed

Disable buildvcs #20056

wants to merge 2 commits into from

Conversation

AbdulrhmnGhanem
Copy link
Contributor

@a1012112796 a1012112796 added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Jun 20, 2022
Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

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

You can achieve this with goflags env var, or extra goflags. This also disables it for all builds, not just your specific use case.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 20, 2022
@wxiaoguang
Copy link
Contributor

I think Golang's buildvcs=true/auto is not ideal.

By default, version control information is stamped into a binary if the main package and the main module containing it are in the repository containing the current directory (if there is a repository)

It doesn't help Gitea's build, and may break reproducible build (even the code the exactly the same, the output differs due to different repository information).

@42wim
Copy link
Member

42wim commented Jun 21, 2022

A bit off topic, but about reproducible builds:

If we want those we should at least do:

  • vendor code (was removed a few months ago)
  • use -trimpath
  • -ldflags=-buildid=
  • -buildvcs=false

But as I read the pages above because we're using CGO it's going to be tricky anyway to have reproducible builds.

@AbdulrhmnGhanem
Copy link
Contributor Author

You can achieve this with goflags env var, or extra goflags. This also disables it for all builds, not just your specific use case.

You are right, though does it make sense the docker build should fail depending on the VCS status? Failing when building inside a submodule is just a symptom I am sure there are other cases where it would fail too.

@techknowlogick
Copy link
Member

Yeah, what @42wim said has changed my pov. I'll drop my review, although I'll suggest adding the flag into the existing goflag env var instead of hardcoding it directly.

Makefile Outdated
@@ -602,7 +602,7 @@ generate: $(TAGS_PREREQ)
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)

$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -buildvcs=false $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
Copy link
Contributor

@zeripath zeripath Jun 26, 2022

Choose a reason for hiding this comment

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

Why aren't you just setting EXTRA_GOFLAGS to use this flag for your specific need. Most people building Gitea do not need this flag and will not need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if the reasons above don't justify the use of this flag, what value does this flag remove from other users? It just resets the build to behave as pre-1.18.

@AbdulrhmnGhanem
Copy link
Contributor Author

I'll suggest adding the flag into the existing goflag env var instead of hardcoding it directly.

Adding

GOFLAGS += -buildvcs=false

the build fails with the same error, is this wrong?

@techknowlogick
Copy link
Member

what about just adding it as EXTRA_GOFLAGS ?= -buildvcs=false to

gitea/Makefile

Line 68 in 389496b

EXTRA_GOFLAGS ?=
?

It'll be overwritten if someone tries to add their own extra goflags, but I think that something that can be dealt with in a later PR.

@AbdulrhmnGhanem
Copy link
Contributor Author

what about just adding it as EXTRA_GOFLAGS ?= -buildvcs=false to

gitea/Makefile

Line 68 in 389496b

EXTRA_GOFLAGS ?=

?
It'll be overwritten if someone tries to add their own extra goflags, but I think that something that can be dealt with in a later PR.

It doesn't work!

@Gusted
Copy link
Contributor

Gusted commented Jul 4, 2022

Why modifying the makefile? Using env variables is just easier:

EXTRA_GOFLAGS="-buildvcs=false" TAGS="sqlite sqlite_unlock_notify" make build

Which passes the go flag correctly:

CGO_CFLAGS="-g -O2 -DSQLITE_MAX_VARIABLE_NUMBER=32766" go build -v -buildvcs=false -tags 'sqlite sqlite_unlock_notify' -ldflags '-s -w  -X "main.MakeVersion=GNU Make 4.3" -X "main.Version=1.18.0+dev-58-g9d9bf66c3" -X "main.Tags=sqlite sqlite_unlock_notify"' -o gitea

@AbdulrhmnGhanem
Copy link
Contributor Author

This doesn't resolve the issue addressed by this PR. Running the repro steps in the issue and adding ENV EXTRA_GOFLAGS "-buildvcs=false" to the docker file, it still fails. Also, in all previous trials above the flag gets passed correctly but it still fails.

@Gusted
Copy link
Contributor

Gusted commented Jul 4, 2022

From my point of view, it's clear that we(the Gitea maintainers) don't see the benefit of adding this flag globally, as it doesn't provide any benefits to any other use-case.

You can configure build flags like that via environments, there's no need to hard-code them. You mention that the flag is passed along with the build command, but it still fails, at that point it's out of Gitea's hand and likely a Go/Docker bug. The current PR doesn't fix the issue it still results into the same error. Unless this PR is to fix of why the error still exists even with -buildvcs=false passed, I don't see a reason to hold this PR open.

Also as mentioned on the original issue, Go1.19 won't have this issue anymore.

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker build fails if gitea is a git submodule
8 participants