diff --git a/.github/workflows/build-docker-container.yml b/.github/workflows/build-docker-container.yml index 1d306db..52f4967 100644 --- a/.github/workflows/build-docker-container.yml +++ b/.github/workflows/build-docker-container.yml @@ -1,8 +1,8 @@ -name: ci +name: docker-build on: - push: - branches: ["binary-release", "master", "devel"] + release: + types: [published] jobs: docker: @@ -20,3 +20,5 @@ jobs: with: push: true tags: hilkopterbob/packagelock:latest + build-args: | + APP_VERSION=${{ github.event.release.tag_name }} diff --git a/.github/workflows/unstable-build-docker-container.yml b/.github/workflows/unstable-build-docker-container.yml new file mode 100644 index 0000000..368beb2 --- /dev/null +++ b/.github/workflows/unstable-build-docker-container.yml @@ -0,0 +1,21 @@ +name: unstable-docker-build + +on: + push: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: hilkopterbob/packagelock:unstable-${{ github.head_ref || github.ref_name }} diff --git a/Dockerfile b/Dockerfile index 0fbe7c2..a725d4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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. diff --git a/config/conf-init.go b/config/conf-init.go index a521c19..a18ee5c 100644 --- a/config/conf-init.go +++ b/config/conf-init.go @@ -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? diff --git a/main.go b/main.go index 419126f..279ad9a 100644 --- a/main.go +++ b/main.go @@ -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