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

chore: enable full ENV support and remove --sqlite option #6286

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ gokrazy::
go install github.com/gokrazy/tools/cmd/gokr-packer@main
mkdir -p flags/github.com/gokrazy/breakglass
echo "-forward=private-network" > flags/github.com/gokrazy/breakglass/flags.txt
mkdir -p flags/github.com/evcc-io/evcc
echo "--sqlite=/perm/evcc.db" > flags/github.com/evcc-io/evcc/flags.txt
mkdir -p env/github.com/evcc-io/evcc
echo "EVCC_NETWORK_PORT=80" > env/github.com/evcc-io/evcc/env.txt
echo "EVCC_DATABASE_DSN=/perm/evcc.db" >> env/github.com/evcc-io/evcc/env.txt
mkdir -p buildflags/github.com/evcc-io/evcc
echo "$(BUILD_TAGS),gokrazy" > buildflags/github.com/evcc-io/evcc/buildflags.txt
echo "-ldflags=$(LD_FLAGS)" >> buildflags/github.com/evcc-io/evcc/buildflags.txt
Expand Down
3 changes: 0 additions & 3 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
)

const (
flagSqlite = "sqlite"
flagSqliteDescription = "SQlite database file"

flagHeaders = "log-headers"
flagHeadersDescription = "Log headers"

Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ func init() {
rootCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)

// config file options
rootCmd.PersistentFlags().String(flagSqlite, conf.Database.Dsn, flagSqliteDescription)
bindP(rootCmd, "database.dsn", flagSqlite)

rootCmd.PersistentFlags().StringP("log", "l", "info", "Log level (fatal, error, warn, info, debug, trace)")
bindP(rootCmd, "log")

Expand Down Expand Up @@ -89,6 +86,7 @@ func initConfig() {
}

viper.SetEnvPrefix("evcc")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match

// print version
Expand Down
4 changes: 0 additions & 4 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ func configureEnvironment(cmd *cobra.Command, conf config) (err error) {

// setup persistence
if err == nil && conf.Database.Dsn != "" {
if flag := cmd.Flags().Lookup(flagSqlite); flag != nil && flag.Changed {
conf.Database.Type = "sqlite"
conf.Database.Dsn = flag.Value.String()
}
err = configureDatabase(conf.Database)
}

Expand Down
8 changes: 4 additions & 4 deletions docker/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ HASSIO_OPTIONSFILE=/data/options.json
if [ -f ${HASSIO_OPTIONSFILE} ]; then
CONFIG=$(grep -o '"config_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$')
echo "Using config file: ${CONFIG}"

SQLITE_FILE=$(grep -o '"sqlite_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$')

if [ ! -f "${CONFIG}" ]; then
echo "Config not found. Please create a config under ${CONFIG}."
echo "For details see evcc documentation at https://github.com/evcc-io/evcc#readme."
else
if [ "${SQLITE_FILE}" ]; then
echo "starting evcc: 'evcc --config ${CONFIG} --sqlite ${SQLITE_FILE}'"
exec evcc --config "${CONFIG}" --sqlite "${SQLITE_FILE}"
echo "starting evcc: 'EVCC_DATABASE_DSN=${SQLITE_FILE} evcc --config ${CONFIG}'"
exec EVCC_DATABASE_DSN="${SQLITE_FILE}" evcc --config "${CONFIG}"
else
echo "starting evcc: 'evcc --config ${CONFIG}'"
exec evcc --config "${CONFIG}"
Expand Down
2 changes: 1 addition & 1 deletion packaging/init/evcc.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ StartLimitIntervalSec=10
StartLimitBurst=10

[Service]
ExecStart=/usr/bin/evcc --sqlite /var/lib/evcc/evcc.db
ExecStart=EVCC_DATABASE_DSN=/var/lib/evcc/evcc.db /usr/bin/evcc
andig marked this conversation as resolved.
Show resolved Hide resolved
Restart=always
RestartSec=10

Expand Down