diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c830c1e..11d80ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,11 @@ jobs: - uses: actions/checkout@master with: ref: ${{ github.ref }} + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build env: VERSION: ${{ github.run_number }} @@ -34,7 +39,6 @@ jobs: echo "Start CI build" docker run --privileged --rm tonistiigi/binfmt --install all podman manifest create build - podman build --format docker --platform linux/amd64,linux/arm64,linux/arm/v7 -t bbernhard/signal-cli-rest-api:${EPOCHSECONDS}-ci --manifest localhost/build . - podman images - podman push bbernhard/signal-cli-rest-api:${EPOCHSECONDS}-ci docker://docker.io/bbernhard/signal-cli-rest-api:${EPOCHSECONDS}-ci + podman build --format docker --platform linux/amd64,linux/arm64,linux/arm/v7 --manifest localhost/build . + podman manifest push localhost/build docker://docker.io/bbernhard/signal-cli-rest-api:${EPOCHSECONDS}-ci diff --git a/.github/workflows/release-dev-version.yml b/.github/workflows/release-dev-version.yml index 9c63f48..6dd7eca 100644 --- a/.github/workflows/release-dev-version.yml +++ b/.github/workflows/release-dev-version.yml @@ -39,4 +39,6 @@ jobs: echo "Start dev build" docker run --privileged --rm tonistiigi/binfmt --install all podman manifest create build - podman build --format docker --build-arg BUILD_VERSION_ARG=${VERSION} --manifest localhost/build --platform linux/amd64,linux/arm64,linux/arm/v7 -t bbernhard/signal-cli-rest-api:${VERSION}-dev -t bbernhard/signal-cli-rest-api:latest-dev . --push + podman build --format docker --build-arg BUILD_VERSION_ARG=${VERSION} --manifest localhost/build --platform linux/amd64,linux/arm64,linux/arm/v7 . + podman manifest push localhost/build docker://docker.io/bbernhard/signal-cli-rest-api:${VERSION}-dev + podman manifest push localhost/build docker://docker.io/bbernhard/signal-cli-rest-api:latest-dev diff --git a/.github/workflows/release-productive-version.yml b/.github/workflows/release-productive-version.yml index 0fc8584..5d24bfd 100644 --- a/.github/workflows/release-productive-version.yml +++ b/.github/workflows/release-productive-version.yml @@ -39,4 +39,6 @@ jobs: echo "Start productive build" docker run --privileged --rm tonistiigi/binfmt --install all podman manifest create build - podman build --build-arg BUILD_VERSION_ARG=${VERSION} --manifest localhost/build --platform linux/amd64,linux/arm64,linux/arm/v7 -t bbernhard/signal-cli-rest-api:${VERSION} -t bbernhard/signal-cli-rest-api:latest . --push + podman build --format docker --build-arg BUILD_VERSION_ARG=${VERSION} --manifest localhost/build --platform linux/amd64,linux/arm64,linux/arm/v7 . + podman manifest push localhost/build docker://docker.io/bbernhard/signal-cli-rest-api:${VERSION} + podman manifest push localhost/build docker://docker.io/bbernhard/signal-cli-rest-api:latest diff --git a/README.md b/README.md index c0e2e34..cb948a4 100644 --- a/README.md +++ b/README.md @@ -147,3 +147,5 @@ There are a bunch of environmental variables that can be set inside the docker c * `PORT`: Defaults to port `8080` unless this env var is set to tell it otherwise. * `DEFAULT_SIGNAL_TEXT_MODE`: Allows to set the default text mode that should be used when sending a message (supported values: `normal`, `styled`). The setting is only used in case the `text_mode` is not explicitly set in the payload of the `send` method. + +* `LOG_LEVEL`: Allows to set the log level. Supported values: `debug`, `info`, `warn`, `error`. If nothing is specified, it defaults to `info`. diff --git a/src/api/api.go b/src/api/api.go index 4bb63ce..af114dd 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -1308,14 +1308,9 @@ func (a *Api) SetConfiguration(c *gin.Context) { } if req.Logging.Level != "" { - if req.Logging.Level == "debug" { - log.SetLevel(log.DebugLevel) - } else if req.Logging.Level == "info" { - log.SetLevel(log.InfoLevel) - } else if req.Logging.Level == "warn" { - log.SetLevel(log.WarnLevel) - } else { - c.JSON(400, Error{Msg: "Couldn't set log level - invalid log level"}) + err = utils.SetLogLevel(req.Logging.Level) + if err != nil { + c.JSON(400, Error{Msg: err.Error()}) return } } diff --git a/src/main.go b/src/main.go index 57f85a1..2c327b2 100644 --- a/src/main.go +++ b/src/main.go @@ -69,6 +69,16 @@ func main() { avatarTmpDir := flag.String("avatar-tmp-dir", "/tmp/", "Avatar tmp directory") flag.Parse() + + logLevel := utils.GetEnv("LOG_LEVEL", "") + if logLevel != "" { + err := utils.SetLogLevel(logLevel) + if err != nil { + log.Error("Couldn't set log level to '", logLevel, "'. Falling back to the info log level") + utils.SetLogLevel("info") + } + } + if utils.GetEnv("SWAGGER_USE_HTTPS_AS_PREFERRED_SCHEME", "false") == "false" { docs.SwaggerInfo.Schemes = []string{"http", "https"} } else { diff --git a/src/utils/utils.go b/src/utils/utils.go index f0e87c2..deec1e7 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -3,6 +3,8 @@ package utils import ( "os" "strconv" + "errors" + log "github.com/sirupsen/logrus" ) func GetEnv(key string, defaultVal string) string { @@ -46,3 +48,18 @@ func IsPhoneNumber(s string) bool { } return true } + +func SetLogLevel(logLevel string) error { + if logLevel == "debug" { + log.SetLevel(log.DebugLevel) + } else if logLevel == "info" { + log.SetLevel(log.InfoLevel) + } else if logLevel == "error" { + log.SetLevel(log.ErrorLevel) + } else if logLevel == "warn" { + log.SetLevel(log.WarnLevel) + } else { + return errors.New("Couldn't set log level - invalid log level") + } + return nil +}