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

caddy --version unknown #2875

Closed
greenpau opened this issue Nov 11, 2019 · 5 comments
Closed

caddy --version unknown #2875

greenpau opened this issue Nov 11, 2019 · 5 comments

Comments

@greenpau
Copy link

greenpau commented Nov 11, 2019

1. Which version of Caddy are you using (caddy -version)?

$ caddy --version
unknown
$ git describe
v1.0.3-14-gcc63eca

2. What are you trying to do?

I am building a server and want to receive caddy --version other than unknown.

I used to set it via -X github.com/mholt/caddy/caddy/caddymain.gitTag=${PROJECT_VERSION}". Now, the project migrated to caddyserver and it does not work.

go get github.com/caddyserver/caddy
cd $GOPATH/src/github.com/caddyserver/caddy
PROJECT="github.com/caddyserver/caddy"
PROJECT_VERSION=`git describe`
mkdir -p ./bin
CGO_ENABLED=0 go build -v -o ./bin/caddy \
    -ldflags="-w -s \
    -X github.com/caddyserver/caddy/caddy.gitTag=${PROJECT_VERSION}" \
    -gcflags="all=-trimpath=${GOPATH}/src" \
    -asmflags="all=-trimpath=${GOPATH}/src" \
    ./caddy/main.go

3. What is your Caddyfile?

N/A.

4. How did you run Caddy (give the full command and describe the execution environment)?

N/A.

5. Please paste any relevant HTTP request(s) here.

N/A.

6. What did you expect to see?

Previously, my compiled binary output was:

# caddy.old --version
Caddy 0.11.4-6-g8a51198 (unofficial)

7. What did you see instead (give full error messages and/or log)?

# caddy --version
unknown

8. Why is this a bug, and how do you think this should be fixed?

I don't know whether it is a bug. I think it might be a good idea to spell out how to set it up.

9. What are you doing to work around the problem in the meantime?

N/A.

10. Please link to any related issues, pull requests, and/or discussion.

N/A.

Bonus: What do you use Caddy for? Why did you choose Caddy?

Why do I use caddy:

  • It is written in Go and the code is easily readable
  • The community is great
  • The project's contributors and the maintainer are responsible and promptly answer questions
  • The documentation is all in Github (I don't like JIRA based systems)
@mohammed90
Copy link
Member

The variable gitTag went away as Caddy moved into Go's module way. What you can do now is to create a new Go module, have Caddy dependency, then delegate to caddymain.Run in your main func. That shall preserve the correct module version.

// getBuildModule returns the build info of Caddy
// from debug.BuildInfo (requires Go modules). If
// no version information is available, a non-nil
// value will still be returned, but with an
// unknown version.
func getBuildModule() *debug.Module {
bi, ok := debug.ReadBuildInfo()
if ok {
// The recommended way to build Caddy involves
// creating a separate main module, which
// preserves caddy a read-only dependency
// TODO: track related Go issue: https://github.com/golang/go/issues/29228
for _, mod := range bi.Deps {
if mod.Path == "github.com/caddyserver/caddy" {
return mod
}
}
}
return &debug.Module{Version: "unknown"}
}

@mholt
Copy link
Member

mholt commented Nov 11, 2019

Yeah, and the step-by-step instructions (there are only like 3 steps) to build Caddy with version information are in the readme: https://github.com/caddyserver/caddy#build

@mholt mholt closed this as completed Nov 11, 2019
@iddq
Copy link

iddq commented Jan 27, 2020

caddy_v1.0.4_linux_386.tar.gz is still affected

@samuller
Copy link

samuller commented Sep 23, 2023

Same issue seems to be happening with the current alpine package of Caddy. If you have this Dockerfile:

FROM python:3.8.18-alpine3.18

RUN apk update && apk add caddy

Build it with docker build -t test-caddy:0.0.1 . and then run and check the version - then it does the same:

$ docker run --rm test-caddy:0.0.1 caddy version
unknown

(although the version can still be figured out from the package with apk info caddy )

@mohammed90
Copy link
Member

Same issue seems to be happening with the current alpine package of Caddy. If you have this Dockerfile:

FROM python:3.8.18-alpine3.18

RUN apk update && apk add caddy

Build it with docker build -t test-caddy:0.0.1 . and then run and check the version - then it does the same:

$ docker run --rm test-caddy:0.0.1 caddy version
unknown

(although the version can still be figured out from the package with apk info caddy )

This issue is 4 years old and isn't applicable anymore. It was reported for Caddy v1. The Alpine distribution of Caddy reports the version as unknown due to how Alpine builds the packages and not an issue with Caddy itself, see here for brief explanation by the maintainer of Caddy package on Alpine.

FYI, there's a caddy Docker image with Alpine base.

@caddyserver caddyserver locked and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants