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

ci: inject app version during Docker build and set default config #21

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-docker-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
with:
push: true
tags: hilkopterbob/packagelock:latest
build-args: |
APP_VERSION=${{ github.event.release.tag_name }}
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ RUN go mod download


# Build

RUN CGO_ENABLED=0 GOOS=linux go build -o /packagelock
ARG APP_VERSION="v0.1.0+hotfixes"
RUN \
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X 'main.AppVersion=$APP_VERSION'" -o /packagelock

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
Expand Down
1 change: 1 addition & 0 deletions config/conf-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ConfigProvider interface {
ReadConfig(in io.Reader) error
AllSettings() map[string]any
GetString(string string) string
SetDefault(key string, value any)
}

// TODO: How to test?
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ import (
"github.com/spf13/viper"
)

// Data structs
// Linker Injections
// Version injection with Docker Build & ldflags
// Do not modify, init or change in code!
var AppVersion string

// TODO: support for multiple network adapters.

func main() {
Config := config.StartViper(viper.New())

if AppVersion != "" {
Config.SetDefault("general.app-version", AppVersion)
}

fmt.Println(Config.AllSettings())

// Channel to signal the restart
Expand Down
Loading