Traefik version number not in binary

Hi all,

When I

brew install traefik

The binary reports the following version information

$ traefik version
Version:      dev
Codename:     cheddar
Go version:   go1.13.4
Built:        I don't remember exactly
OS/Arch:      darwin/amd64

But I know it should be Version 2.0.4 Codename montdor. Anyone else seeing this? I am on Mojave with latest patches. The src tarball is correctly referencing the 2.0.4 release.

I am not sure whether this is a reproducible issue so have not opened an issue on GitHub (I’m also happy to do the work to fix if it is, but I do not have any go experience to speak of).

I think it is not being built with quite the right environment: I found the following references to codename in the code:

pkg/version/version.go: Codename = "cheddar" // beta cheese
script/crossbinary-default:    CODENAME=cheddar
script/binary:    CODENAME=cheddar

Digging in suggested these should be set in the environment or something.

Thanks for reading and for the great tool!
Steven.

Something like this https://github.com/Homebrew/homebrew-core/blob/master/Formula/faas-cli.rb#L26 should be able to fix it

Thanks Sean — based on this I’ve got the values in the binary. Not sure if it’s neat enough but I’ll raise a PR as a next step. Here’s the formula in case anyone else is urgently interested:

class Traefik < Formula
  desc "Modern reverse proxy"
  homepage "https://traefik.io/"
  url "https://github.com/containous/traefik/releases/download/v2.0.4/traefik-v2.0.4.src.tar.gz"
  version "2.0.4"
  sha256 "bca78975d6a2b6a4683c65d957a5cbed031f34186ac3cc1ec3fbf5303448d2e8"
  head "https://github.com/containous/traefik.git"

  depends_on "go" => :build
  depends_on "go-bindata" => :build

  def install
    ENV["GOPATH"] = buildpath
    (buildpath/"src/github.com/containous/traefik").install buildpath.children
    project = "github.com/containous/traefik"
    codename = "montdor"
    now = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
    cd "src/#{project}" do
      system "go", "generate"
      system "go", "build", "-ldflags",
            "-s -w -X #{project}/v2/pkg/version.Version=#{version} -X #{project}/v2/pkg/version.Codename=#{codename} -X #{project}/v2/pkg/version.BuildDate=#{now}",
            "-o", bin/"traefik", "./cmd/traefik"
      prefix.install_metafiles
    end
  end

  plist_options :manual => "traefik"

  def plist
    <<~EOS
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
        <dict>
          <key>KeepAlive</key>
          <false/>
          <key>Label</key>
          <string>#{plist_name}</string>
          <key>ProgramArguments</key>
          <array>
            <string>#{opt_bin}/traefik</string>
            <string>--configfile=#{etc/"traefik/traefik.toml"}</string>
          </array>
          <key>EnvironmentVariables</key>
          <dict>
          </dict>
          <key>RunAtLoad</key>
          <true/>
          <key>WorkingDirectory</key>
          <string>#{var}</string>
          <key>StandardErrorPath</key>
          <string>#{var}/log/traefik.log</string>
          <key>StandardOutPath</key>
          <string>#{var}/log/traefik.log</string>
        </dict>
      </plist>
    EOS
  end

  test do
    require "socket"

    ui_server = TCPServer.new(0)
    http_server = TCPServer.new(0)
    ui_port = ui_server.addr[1]
    http_port = http_server.addr[1]
    ui_server.close
    http_server.close

    (testpath/"traefik.toml").write <<~EOS
      [global]
        checkNewVersion = false
        sendAnonymousUsage = false
      [serversTransport]
        insecureSkipVerify = true
      [entryPoints]
        [entryPoints.http]
          address = ":#{http_port}"
        [entryPoints.traefik]
          address = ":#{ui_port}"
      [log]
        level = "ERROR"
        format = "common"
      [accessLog]
        format = "common"
      [api]
        insecure = true
        dashboard = true
        debug = true
    EOS

    begin
      pid = fork do
        exec bin/"traefik", "--configfile=#{testpath}/traefik.toml"
      end
      sleep 5
      cmd_http = "curl -sIm3 -XGET http://localhost:#{http_port}/"
      assert_match /404 Not Found/m, shell_output(cmd_http)
      sleep 1
      cmd_ui = "curl -sIm3 -XGET http://localhost:#{ui_port}/dashboard/"
      assert_match /200 OK/m, shell_output(cmd_ui)
    ensure
      Process.kill("HUP", pid)
    end
  end
end

diff :

diff --git a/Formula/traefik.rb b/Formula/traefik.rb
index ff477b7a49..2a121b2ada 100644
--- a/Formula/traefik.rb
+++ b/Formula/traefik.rb
@@ -6,23 +6,20 @@ class Traefik < Formula
   sha256 "bca78975d6a2b6a4683c65d957a5cbed031f34186ac3cc1ec3fbf5303448d2e8"
   head "https://github.com/containous/traefik.git"
 
-  bottle do
-    cellar :any_skip_relocation
-    sha256 "c74bebf524f1b6e4e6b02c0ea237648e52ec5709efc1f7500d3a7e7b0fe03766" => :catalina
-    sha256 "dc5c7d9ab88dc3c361359cc7fdbe85977500ee872ce60418008136b61b4c34af" => :mojave
-    sha256 "d639fed102b251a131f5fb0b18d020b2c422cac77fc7faef5381bc8ce43adcda" => :high_sierra
-  end
-
   depends_on "go" => :build
   depends_on "go-bindata" => :build
 
   def install
     ENV["GOPATH"] = buildpath
     (buildpath/"src/github.com/containous/traefik").install buildpath.children
-
-    cd "src/github.com/containous/traefik" do
+    project = "github.com/containous/traefik"
+    codename = "montdor"
+    now = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
+    cd "src/#{project}" do
       system "go", "generate"
-      system "go", "build", "-o", bin/"traefik", "./cmd/traefik"
+      system "go", "build", "-ldflags",
+            "-s -w -X #{project}/v2/pkg/version.Version=#{version} -X #{project}/v2/pkg/version.Codename=#{codename} -X #{project}/v2/pkg/version.BuildDate=#{now}",
+            "-o", bin/"traefik", "./cmd/traefik"
       prefix.install_metafiles
     end
   end