Skip to content

Commit

Permalink
build: improve local build experience, mage tasks, Tilt behavior, and…
Browse files Browse the repository at this point in the history
… more

- trunk upgrade
- aqua update
- build/mage improvements
- buildName addition to metadata.
  • Loading branch information
sheldonhull committed Jun 8, 2024
1 parent 56aca69 commit 0297bf9
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 63 deletions.
35 changes: 18 additions & 17 deletions .aqua/aqua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,42 @@ checksum:
require_checksum: false
registries:
- type: standard
ref: v4.118.0 # renovate: depName=aquaproj/aqua-registry
ref: v4.190.0 # renovate: depName=aquaproj/aqua-registry
- name: local
type: local
path: registry.yaml
packages:
- name: miniscruff/changie@v1.17.0
- name: miniscruff/changie@v1.19.0
tags: ['release']
- name: golang/go@go1.21.6
- name: golang/go@go1.22.4
tags: ['first', 'release', 'test', 'scan', 'lint']
- name: direnv/direnv@v2.33.0
- name: direnv/direnv@v2.34.0
- name: magefile/[email protected]
tags: ['release', 'test', 'scan', 'lint']
- name: charmbracelet/[email protected]
- name: goreleaser/goreleaser@v1.23.0
- name: goreleaser/goreleaser@v2.0.0
tags: ['release']
- name: mvdan/gofumpt@v0.5.0
- name: anchore/syft@v0.100.0
- name: mvdan/gofumpt@v0.6.0
- name: anchore/syft@v1.5.0
tags: ['release']
- name: norwoodj/helm-docs@v1.12.0
- name: gotestyourself/gotestsum@v1.11.0
- name: norwoodj/helm-docs@v1.13.1
- name: gotestyourself/gotestsum@v1.12.0
tags: ['test']
- name: c-bata/[email protected]
- name: kubernetes-sigs/kind@v0.20.0
- name: kubernetes-sigs/kind@v0.23.0
- name: kubernetes/kubectl
version: v1.25.2
- name: helm/helm@v3.13.3
- name: kubernetes/minikube@v1.32.0
- name: helm/helm@v3.15.1
- name: kubernetes/minikube@v1.33.1
tags: ['ci']
- name: stern/stern@v1.28.0
- name: tilt-dev/[email protected].10
- name: golangci/golangci-lint@v1.55.2
- name: stern/stern@v1.30.0
- name: tilt-dev/[email protected].16
- name: golangci/golangci-lint@v1.59.0
tags: ['lint']
- name: mage-select
version: v1.4.2
registry: local
tags: ['goinstall']
- name: DelineaXPM/[email protected]
- name: gitleaks/[email protected]
- name: DelineaXPM/[email protected]
- name: gitleaks/[email protected]
- name: charmbracelet/[email protected]
3 changes: 3 additions & 0 deletions .changes/unreleased/🤖 CI & Build-20240608-002754.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: "\U0001F916 CI & Build"
body: Add a buildName metadata to binary so easy to see if caching issue with container loading. Handle `dev.local/dsv-k8s` as standard image name to better reflect standard approach I've been using. Improve validation checks. Goreleaser upgrade schema and more. Lots of quality of life improvements for dev, and aqua updates.
time: 2024-06-08T00:27:54.636538807Z
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ packages-*

vendor/**/*.png

Tiltfile.local
Tiltfile.local
.env
10 changes: 6 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
version: 2
project_name: dsv-k8s
dist: .artifacts/goreleaser
env:
Expand All @@ -7,6 +8,7 @@ env:
- GITEA_TOKEN=''
- LOCAL_DEBUGGING=false # set to make this quick and bypass extra effort builds like archiving zip
- CGO_ENABLED=0
- BUILD_NAME='{{ if index .Env "BUILD_NAME" }}{{ .Env.BUILD_NAME }}{{else}}""{{end}}'
before:
hooks:
- go mod download
Expand All @@ -22,6 +24,7 @@ builds:
- -X main.commit={{ .FullCommit }}
- -X main.date={{ .Now.Format "2006-01-02T15:04:05Z07:00" }} #RFC3339
- -X main.builtBy=goreleaser
- -X main.buildName={{ .Env.BUILD_NAME }}
goos: [linux]
goarch:
- amd64
Expand Down Expand Up @@ -49,7 +52,7 @@ checksum:
snapshot:
name_template: '{{ incpatch .Version }}-next'
changelog:
skip: false
disable: true
sort: asc
use: github
groups:
Expand Down Expand Up @@ -97,8 +100,8 @@ dockers:
- id: local-docker-images
goos: linux
image_templates:
- '{{ .ProjectName }}:{{ .Tag }}'
- '{{ .ProjectName }}:latest' # This one is for dev usage so latest version, no tagged semver required in docker compose or local testing
- 'dev.local/{{ .ProjectName }}:{{ .Tag }}'
- 'dev.local/{{ .ProjectName }}:latest' # This one is for dev usage so latest version, no tagged semver required in docker compose or local testing
skip_push: true
dockerfile: ./docker/Dockerfile.distroless
use: buildx
Expand All @@ -108,7 +111,6 @@ dockers:
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.version="{{ .Tag }}"
announce:
slack:
enabled: true
Expand Down
36 changes: 18 additions & 18 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 0.1
plugins:
sources:
- id: trunk
ref: v1.4.2
ref: v1.5.0
uri: https://github.com/trunk-io/plugins
actions:
enabled:
Expand Down Expand Up @@ -39,7 +39,7 @@ runtimes:
- [email protected]
- [email protected]
cli:
version: 1.19.0
version: 1.22.1
lint:
threshold:
- linters: [gitleaks]
Expand All @@ -48,35 +48,35 @@ lint:
- cspell
- gofmt
enabled:
- [email protected].19
- [email protected].128
- [email protected]
- osv-scanner@1.6.2
- terrascan@1.18.11
- trivy@0.49.1
- trufflehog@3.67.5
- osv-scanner@1.7.4
- terrascan@1.19.1
- trivy@0.52.0
- trufflehog@3.78.0
- [email protected]
- renovate@37.180.0
- renovate@37.396.1
- golangci-lint@SYSTEM
- git-diff-check
- [email protected]
- markdownlint@0.39.0
- prettier@3.2.5
- actionlint@1.6.26
- markdownlint@0.41.0
- prettier@3.3.1
- actionlint@1.7.1
- [email protected]
- [email protected].2
- shellcheck@0.9.0
- [email protected].3
- shellcheck@0.10.0
- [email protected]
- yamllint@1.34.0
- svgo@3.2.0
- yamllint@1.35.1
- svgo@3.3.2
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- actionlint@1.6.26
- actionlint@1.7.1
- [email protected]
- [email protected]
- markdownlint@0.39.0
- shellcheck@0.9.0
- markdownlint@0.41.0
- shellcheck@0.10.0
- [email protected]

ignore:
Expand Down
26 changes: 25 additions & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ local_resource(
cmd="zsh -l -c \"mage -f -l\"",
trigger_mode=TRIGGER_MODE_AUTO,
auto_init=True,
deps=['magefiles/*.go'],
deps=['magefiles/**/*.go'],
labels=["startup"]
)
local_resource(
Expand Down Expand Up @@ -216,5 +216,29 @@ local_resource(
auto_init=False,
labels=["setup"],
)
local_resource(
"minikube:listimages",
cmd="mage minikube:listimages",
trigger_mode=TRIGGER_MODE_MANUAL,
deps=[],
auto_init=False,
labels=["setup"],
)
local_resource(
"minikube:removeimages",
cmd="mage minikube:removeimages",
trigger_mode=TRIGGER_MODE_MANUAL,
deps=[],
auto_init=False,
labels=["setup"],
)
local_resource(
"minikube:loadimages",
cmd="mage minikube:loadimages",
trigger_mode=TRIGGER_MODE_MANUAL,
deps=[],
auto_init=False,
labels=["setup"],
)

# k8s_resource('injector', resource_deps='minikube:init', pod_readiness='ignore')
5 changes: 4 additions & 1 deletion cmd/injector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ var (
commit = "none"
// Date is the date the binary was produced.
date = "unknown"
// buildName is the build name for easier confirmation on local builds that a build has changed.
buildName = "unknown"
)

// main is the entry point for the injector; creates an HTTPS listener and listing for v1.AdmissionReview requests
// main is the entry point for the injector. It creates an HTTPS listener and listing for v1.AdmissionReview requests
func main() {
if err := Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
Expand All @@ -56,6 +58,7 @@ func Run(args []string) error { //nolint:funlen,cyclop // ok for Run
Str("version", version).
Str("commit", commit).
Str("date", date).
Str("buildName", buildName).
Msg("injector version information")

// Config is the configuration for the injector.
Expand Down
3 changes: 3 additions & 0 deletions cmd/syncer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
commit = "none"
// Date is the date the binary was produced.
date = "unknown"
// buildName is the build name for easier confirmation on local builds that a build has changed.
buildName = "unknown"
)

// Run contains the actual invocation code for the syncer and is public to allow running integration tests with it.
Expand All @@ -50,6 +52,7 @@ func Run(args []string) error { //nolint:funlen // ok for Run
Str("version", version).
Str("commit", commit).
Str("date", date).
Str("buildName", buildName).
Msg("syncer version information")

// Config is the configuration for the syncer.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/aws/aws-sdk-go v1.44.119 // indirect
github.com/brianvoe/gofakeit/v6 v6.28.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/aws/aws-sdk-go v1.44.119 h1:TPkpDsanBMcZaF5wHwpKhjkapRV/b7d2qdC+a+IPb
github.com/aws/aws-sdk-go v1.44.119/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/bitfield/script v0.22.0 h1:LA7QHuEsXMPD52YLtxWrlqCCy+9FOpzNYfsRHC5Gsrc=
github.com/bitfield/script v0.22.0/go.mod h1:ms4w+9B8f2/W0mbsgWDVTtl7K94bYuZc3AunnJC4Ebs=
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II=
github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
Expand Down
2 changes: 1 addition & 1 deletion magefiles/constants/constants.mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
// DockerImageQualified is the qualified path of the image in Docker Hub.
DockerImageQualified = "docker.io/delineaxpm/dsv-k8s"
// DockerImageNameLocal is the name of the built image to run locally and load with minikube/kind.
DockerImageNameLocal = "dsv-k8s"
DockerImageNameLocal = "dev.local/dsv-k8s"
)

const (
Expand Down
53 changes: 47 additions & 6 deletions magefiles/goreleaser.mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,47 @@ package main

import (
"fmt"
"hash"
"hash/fnv"
"os"
"path/filepath"
"strings"
"time"

"github.com/brianvoe/gofakeit/v6"
"github.com/magefile/mage/sh"
"github.com/pterm/pterm"
"github.com/sheldonhull/magetools/pkg/magetoolsutils"
"github.com/sheldonhull/magetools/pkg/req"
)

// FNV64a hashes using fnv64a algorithm
//
// Sourced from: https://github.com/shomali11/util/blob/master/xhashes/xhashes.go
func FNV64a(text string) uint64 {
algorithm := fnv.New64a()
return uint64Hasher(algorithm, text)
}

// uint64Hasher returns a uint64
//
// Sourced from: https://github.com/shomali11/util/blob/master/xhashes/xhashes.go
func uint64Hasher(algorithm hash.Hash64, text string) uint64 {
algorithm.Write([]byte(text))
return algorithm.Sum64()
}

func randomBuildName() (petname string) {
v := time.Now().Unix()
gofakeit.Seed(v)
animal := gofakeit.Animal()
adjective := gofakeit.AdjectiveDescriptive()
petname = strings.ToLower(strings.Join([]string{adjective, animal}, "-"))
pterm.Info.Printfln("Random Pet Calculated at Runtime: %s\n", petname)

return petname
}

func checkEnvVar(envVar string, required bool) (string, error) {
envVarValue := os.Getenv(envVar)
if envVarValue == "" && required {
Expand Down Expand Up @@ -47,7 +78,11 @@ func Build() error {
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)

return sh.RunV(binary, releaserArgs...) // "--skip-announce",.
return sh.RunWithV(
map[string]string{
"BUILD_NAME": randomBuildName(),
},
binary, releaserArgs...) // "--skip-announce",.
}

// 🔨 BuildAll builds all the binaries defined in the project, for all platforms. This includes Docker image generation but skips publish.
Expand All @@ -63,10 +98,14 @@ func BuildAll() error {
"release",
"--snapshot",
"--clean",
"--skip-publish",
"--skip", "publish,sbom",
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)
return sh.RunV(binary, releaserArgs...)
_ = os.Setenv("BUILD_NAME", randomBuildName())
return sh.RunWithV(
map[string]string{
"BUILD_NAME": randomBuildName(),
}, binary, releaserArgs...)
// To pass in explicit version mapping, you can do this. I'm not using at this time.
// Return sh.RunWithV(map[string]string{
// "GORELEASER_CURRENT_TAG": "latest",
Expand Down Expand Up @@ -108,9 +147,11 @@ func Release() error {
}
pterm.Debug.Printfln("goreleaser: %+v", releaserArgs)

return sh.RunWithV(map[string]string{
"GORELEASER_CURRENT_TAG": cleanVersion,
},
return sh.RunWithV(
map[string]string{
"GORELEASER_CURRENT_TAG": cleanVersion,
"BUILD_NAME": randomBuildName(),
},
binary,
releaserArgs...,
)
Expand Down
Loading

0 comments on commit 0297bf9

Please sign in to comment.