Skip to content

Commit

Permalink
update config and docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
kubemq committed Aug 24, 2020
1 parent 8a6e28f commit 6b01816
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ WORKDIR $GOPATH/github.com/kubemq-hub/kubemq-bridges
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -mod=vendor -installsuffix cgo -ldflags="-w -s -X main.version=$VERSION" -o kubemq-bridges-run .
FROM registry.access.redhat.com/ubi8/ubi-minimal
MAINTAINER KubeMQ [email protected]
LABEL name="KubeMQ Target Connectors" \
LABEL name="KubeMQ Bridges Connectors" \
maintainer="[email protected]" \
vendor="" \
vendor="kubemq.io" \
version="" \
release="" \
summary="" \
summary="KubeMQ Bridges bridge, replicate, aggregate, and transform messages between KubeMQ clusters no matter where they are, allowing to build a true cloud-native messaging single network running globally." \
description=""
COPY licenses /licenses
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH
RUN mkdir /kubemq-bridges
COPY --from=builder $GOPATH/github.com/kubemq-hub/kubemq-bridges/kubemq-bridges-run ./kubemq-bridges
RUN chown -R 1001:root /kubemq-bridges && chmod g+rwX /kubemq-bridges
WORKDIR kubemq-bridges
RUN mkdir /kubemq-connector
COPY --from=builder $GOPATH/github.com/kubemq-hub/kubemq-bridges/kubemq-bridges-run ./kubemq-connector
RUN chown -R 1001:root /kubemq-connector && chmod g+rwX /kubemq-connector
WORKDIR kubemq-connector
USER 1001
CMD ["./kubemq-bridges-run"]
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '2'

vars:
BINARY_NAME: kubemq-bridges
VERSION: v0.1.0
VERSION: v0.1.1

tasks:
check_update:
Expand Down
28 changes: 14 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ func (c *Config) Validate() error {
}
return nil
}
func getConfigFormat(in []byte) string {
func getConfigFormat(in []byte) (string, error) {
c := &Config{}
err := yaml.Unmarshal(in, c)
if err == nil {
return "yaml"
yamlErr := yaml.Unmarshal(in, c)
if yamlErr == nil {
return "yaml", nil
}
err = json.Unmarshal(in, c)
if err == nil {
return "json"
jsonErr := json.Unmarshal(in, c)
if jsonErr == nil {
return "json", nil
}
return ""

return "", fmt.Errorf("yaml parsing error: %s, json parsing error: %s", yamlErr.Error(), jsonErr.Error())
}
func decodeBase64(in string) string {
// base64 string cannot contain space so this is indication of base64 string
Expand All @@ -65,9 +66,9 @@ func getConfigDataFromLocalFile(filename string) (string, error) {
if err != nil {
return "", err
}
fileExt := getConfigFormat(data)
fileExt, err := getConfigFormat(data)
if fileExt == "" {
return "", fmt.Errorf("invalid file format")
return "", err
}
if strings.HasSuffix(filename, "."+fileExt) {
return filename, nil
Expand All @@ -79,12 +80,12 @@ func getConfigDataFromEnv() (string, error) {
envConfigData, ok := os.LookupEnv("CONFIG")
envConfigData = decodeBase64(envConfigData)
if ok {
fileExt := getConfigFormat([]byte(envConfigData))
fileExt, err := getConfigFormat([]byte(envConfigData))
if fileExt == "" {
return "", fmt.Errorf("invalid environment config format")
return "", err
}
/* #nosec */
err := ioutil.WriteFile("./config."+fileExt, []byte(envConfigData), 0644)
err = ioutil.WriteFile("./config."+fileExt, []byte(envConfigData), 0644)
if err != nil {
return "", fmt.Errorf("cannot save environment config file")
}
Expand All @@ -111,7 +112,6 @@ func getConfigFile() (string, error) {
func Load() (*Config, error) {
pflag.Parse()
viper.AddConfigPath("./")
viper.AddConfigPath("./config")
loadedConfigFile, err := getConfigFile()
if err != nil {
return nil, fmt.Errorf("error loading configuration, %w", err)
Expand Down

0 comments on commit 6b01816

Please sign in to comment.