Debian Packaging: From Source to Repository

Packaging Go Applications

A practical Debian packaging course lesson covering packaging go applications.

Packaging Go Applications

Go applications are often distributed as compiled binaries, but Debian packaging should start from source code and use declared build dependencies.

In this lesson, we will examine the details that matter when packaging Go software and refine our Syspeek build.

Learning Objectives

  • Understand how Go modules relate to Debian packages.
  • Build Go software from source during package creation.
  • Avoid relying on precompiled local binaries.
  • Understand the role of golang-any and dh-golang.
  • Review architecture and reproducibility considerations.

1. Source Code, Not a Prebuilt Binary

A Debian source package should contain the source needed to build the application.

Do not copy a binary built on your workstation into the package and treat it as the package’s source.

Instead, the build process should compile the application using the declared Go toolchain.

Our debian/rules already does this:

1
2
override_dh_auto_build:
	CGO_ENABLED=0 go build -trimpath -buildvcs=false -o syspeek .

This makes the build process explicit.

2. Go Modules and Debian Build Dependencies

The go.mod file identifies the Go module and its module dependencies.

Our current application uses only the Go standard library, so it has no third-party module requirements.

The Debian control file declares:

1
2
3
Build-Depends:
 debhelper-compat (= 13),
 golang-any

golang-any allows the build system to select an appropriate Go compiler package for the target architecture.

For packages with third-party Go dependencies, Debian packaging requires additional care. Dependencies should be available through Debian’s packaging ecosystem rather than downloaded unpredictably from the network during a package build.

3. Why Network Access During Builds Is a Problem

A reliable package build should not fetch arbitrary source dependencies from the internet.

Network-dependent builds can fail when a remote service is unavailable, when a dependency changes, or when the downloaded content cannot be verified.

For a package with external Go modules, maintainers need to arrange for dependencies to be available in a controlled and policy-compliant way, commonly through Debian-packaged Go libraries or an appropriately prepared vendor directory.

Syspeek deliberately avoids this complexity in its first version.

4. Review the Build Command

From the project root:

1
cd ~/packaging-lab/syspeek

Inspect the Go module:

1
cat go.mod

Build the application manually:

1
CGO_ENABLED=0 go build -trimpath -buildvcs=false -o /tmp/syspeek-test .

Run it:

1
/tmp/syspeek-test

Remove the temporary executable:

1
rm -f /tmp/syspeek-test

5. Architecture Considerations

Our package uses:

1
Architecture: any

The executable is compiled for the architecture on which the package is built.

Go exposes architecture names such as amd64 and arm64. Debian uses architecture names such as amd64 and arm64 as well, though architecture naming should always be taken from Debian tooling rather than guessed from uname.

Check the current Debian architecture:

1
dpkg --print-architecture

6. Should We Use dh-golang?

dh-golang provides debhelper integration for Go packaging, particularly useful in Debian’s ecosystem of Go libraries and applications.

It is not necessary to use every helper package in every Go package. For our deliberately small, standard-library-only application, an explicit go build override keeps the mechanics visible for teaching.

For larger projects, follow the current Debian Go packaging guidance and use the helpers appropriate to the package’s structure and dependency model.

7. What We Learned

We confirmed that Syspeek is built from source during package creation. We also examined Go modules, Debian build dependencies, network-independent builds, and architecture metadata.

Exercises

  1. Run go list -m all and inspect the module graph.
  2. Confirm that the current project has no third-party Go module dependencies.
  3. Build with CGO_ENABLED=0 and compare the result with a normal build.
  4. Explain why a package build should not silently download dependencies.

What’s Next?

A package’s dependencies and build environment must be described accurately. Next, we will examine dependency handling and build-system details in more depth.

Next: Dependencies and Build Systems