Skip to content

Commit d1b2f53

Browse files
committed
allow config to be loaded from environment only
1 parent 4b05c44 commit d1b2f53

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git*
2+
docs
3+
screenshots
4+
example-config.yml
5+
docker-compose.yml
6+
mkdocs.yml
7+
README.md

.github/workflows/docker-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Install cosign
2727
if: github.event_name != 'pull_request'
28-
uses: sigstore/[email protected]
28+
uses: sigstore/[email protected]
2929
with:
3030
cosign-release: 'v2.2.3'
3131

@@ -42,13 +42,13 @@ jobs:
4242

4343
- name: Extract Docker metadata
4444
id: meta
45-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
45+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
4646
with:
4747
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4848

4949
- name: Build and push Docker image
5050
id: build-and-push
51-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
51+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
5252
with:
5353
context: .
5454
push: ${{ github.event_name != 'pull_request' }}

config/config.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"html/template"
78
"os"
@@ -182,15 +183,25 @@ func LoadConfig(configFile string) {
182183
}
183184

184185
// Load Config file
185-
log.Debug().Msgf("Loading config file: %v", configFile)
186+
log.Debug().Msgf("Attempting to load config file: %v", configFile)
186187

187188
err := fig.Load(&ConfigData, fig.File(filepath.Base(configFile)), fig.Dirs(filepath.Dir(configFile)), fig.UseEnv("FN"))
188189
if err != nil {
189-
log.Fatal().
190-
Err(err).
191-
Msg("Failed to load config file!")
190+
if errors.Is(err, fig.ErrFileNotFound) {
191+
log.Warn().Msg("Config file could not be read, attempting to load config from environment")
192+
err = fig.Load(&ConfigData, fig.IgnoreFile(), fig.UseEnv("FN"))
193+
if err != nil {
194+
log.Fatal().
195+
Err(err).
196+
Msg("Failed to load config from environment!")
197+
}
198+
} else {
199+
log.Fatal().
200+
Err(err).
201+
Msg("Failed to load config from file!")
202+
}
192203
}
193-
log.Info().Msg("Config file loaded.")
204+
log.Info().Msg("Config loaded.")
194205

195206
// Send config file to validation before completing
196207
validateConfig()

0 commit comments

Comments
 (0)