Skip to content

feat: improve binary size with build tags#976

Merged
steveiliop56 merged 3 commits into
mainfrom
feat/improve-bin-size
Jul 6, 2026
Merged

feat: improve binary size with build tags#976
steveiliop56 merged 3 commits into
mainfrom
feat/improve-bin-size

Conversation

@steveiliop56

@steveiliop56 steveiliop56 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Release/nightly pipelines now generate a shared BUILD_TAGS set and apply it to Go binary builds and Docker image builds.
    • Docker builds receive the same feature tags via build arguments for both amd64 and arm64 (including distroless and alpine flows).
  • Bug Fixes
    • Renamed Alpine digest artifacts and tightened the image-merge matching to ensure the correct digests are merged.
  • Chores
    • Makefile now derives tags dynamically for local builds; minor dependency and formatting updates were applied.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR computes a shared BUILD_TAGS value and threads it through local builds, Dockerfiles, and nightly/release workflows. It also renames Alpine digest artifacts, narrows merge globs, promotes two dependencies in go.mod, and makes one controller variable explicitly typed.

Changes

Build tags propagation

Layer / File(s) Summary
Local build tooling
Makefile, Dockerfile, Dockerfile.distroless
Computes BUILD_TAGS from Tailscale feature tags and GIN_BUILD_TAGS=nomsgpack, then passes it into go build through Makefile and Docker build args.
Nightly workflow
.github/workflows/nightly.yml
Generates and exports BUILD_TAGS, uses it for Go and Docker builds, renames Alpine digest artifacts, and narrows the merge download pattern.
Release workflow
.github/workflows/release.yml
Generates and exports BUILD_TAGS, uses it for Go and Docker builds, renames Alpine digest artifacts, and narrows the merge download pattern.

Unrelated dependency and controller edits

Layer / File(s) Summary
go.mod direct dependency promotion
go.mod
charm.land/lipgloss/v2 and gopkg.in/yaml.v3 move from indirect to direct require entries.
OIDC controller bind type declaration
internal/controller/oidc_controller.go
resolveNormalParams now declares bind with an explicit binding.Binding type.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: scottmckendry

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: using build tags to reduce binary size.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/improve-bin-size

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 6, 2026
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/release.yml:
- Around line 29-37: The Generate metadata step is interpolating github.ref_name
directly inside the run script, which creates a template-injection risk; move
VERSION into an env variable for that step and reference it as a shell variable
in the metadata script instead. Update the Generate metadata block to avoid
literal ${ { } } expansion in the shell, and keep the existing outputs like
COMMIT_HASH, BUILD_TIMESTAMP, and BUILD_TAGS unchanged while using VERSION
safely via the step environment.

In `@Dockerfile`:
- Line 31: The Dockerfile build command is using BUILD_TAGS without protection,
so an unset arg can shift tokens and break the go build invocation. Update the
Dockerfile’s go build step that uses BUILD_TAGS to match the Makefile behavior
by passing the tags value in a way that preserves an empty or missing value, and
verify the related build arguments around the go build command keep -tags and
-ldflags from consuming each other.

In `@Dockerfile.distroless`:
- Line 31: The build command still expands BUILD_TAGS unquoted in the distroless
Dockerfile, so an empty or unset value can cause -tags to consume the following
-ldflags argument. Update the build step that uses BUILD_TAGS to quote the
expansion, matching the safer pattern already used in the Makefile, and apply
the same fix anywhere else in the Dockerfile distroless build flow that
references BUILD_TAGS.

In `@Makefile`:
- Around line 12-16: The BUILD_TAGS setup eagerly runs featuretags during
Makefile parsing because TAILSCALE_BUILD_TAGS and BUILD_TAGS are currently
simply expanded, so switch the related variables to recursive expansion in the
Makefile so the go run invocation only happens for the binary target. Also pin
tailscale.com/cmd/featuretags to a fixed release instead of `@latest`, and apply
the same deferred lookup and version pinning in the duplicated featuretags
command used by the nightly and release GitHub workflow files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2894cf88-09ab-464c-8084-207ff687402d

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab9c0a and 4423053.

📒 Files selected for processing (7)
  • .github/workflows/nightly.yml
  • .github/workflows/release.yml
  • Dockerfile
  • Dockerfile.distroless
  • Makefile
  • go.mod
  • internal/controller/oidc_controller.go

Comment thread .github/workflows/release.yml
Comment thread Dockerfile
Comment thread Dockerfile.distroless
Comment thread Makefile Outdated
scottmckendry
scottmckendry previously approved these changes Jul 6, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2026
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Makefile (1)

104-119: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract shared --build-arg list to cut duplication (and satisfy checkmake).

docker and docker-distroless repeat identical VERSION/COMMIT_HASH/BUILD_TIMESTAMP/BUILD_TAGS build-args, differing only in tag name and Dockerfile. Factoring these into a shared variable also brings docker-distroless's body under the checkmake 5-line limit.

♻️ Proposed refactor
+DOCKER_BUILD_ARGS := --build-arg=VERSION=$(TAG_NAME) \
+	--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
+	--build-arg=BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
+	--build-arg=BUILD_TAGS=$(BUILD_TAGS)
+
 docker:
-	docker buildx build -t tinyauthapp/tinyauth:dev \
-		--build-arg=VERSION=$(TAG_NAME) \
-		--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
-		--build-arg=BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
-		--build-arg=BUILD_TAGS=$(BUILD_TAGS) \
-		-f Dockerfile .
+	docker buildx build -t tinyauthapp/tinyauth:dev $(DOCKER_BUILD_ARGS) -f Dockerfile .

 # Docker image distroless
 docker-distroless:
-	docker buildx build -t tinyauthapp/tinyauth:dev-distroless \
-		--build-arg=VERSION=$(TAG_NAME) \
-		--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
-		--build-arg=BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
-		--build-arg=BUILD_TAGS=$(BUILD_TAGS) \
-		-f Dockerfile.distroless .
+	docker buildx build -t tinyauthapp/tinyauth:dev-distroless $(DOCKER_BUILD_ARGS) -f Dockerfile.distroless .
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 104 - 119, The docker and docker-distroless targets
duplicate the same set of build arguments, which also makes docker-distroless
exceed the checkmake line limit. Extract the repeated VERSION, COMMIT_HASH,
BUILD_TIMESTAMP, and BUILD_TAGS flags into a shared Makefile variable, then
reuse it in both targets while keeping each target focused on its unique tag
name and Dockerfile in the docker and docker-distroless rules.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Makefile`:
- Around line 104-119: The docker and docker-distroless targets duplicate the
same set of build arguments, which also makes docker-distroless exceed the
checkmake line limit. Extract the repeated VERSION, COMMIT_HASH,
BUILD_TIMESTAMP, and BUILD_TAGS flags into a shared Makefile variable, then
reuse it in both targets while keeping each target focused on its unique tag
name and Dockerfile in the docker and docker-distroless rules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e292f12-d7bc-44be-ad14-753e4365c177

📥 Commits

Reviewing files that changed from the base of the PR and between 1973c7a and 1f9ca00.

📒 Files selected for processing (1)
  • Makefile

@steveiliop56 steveiliop56 merged commit 73cc480 into main Jul 6, 2026
5 checks passed
@steveiliop56 steveiliop56 deleted the feat/improve-bin-size branch July 6, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants