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

Viper does not properly read environment variables #31

Closed
gadgethm opened this issue May 31, 2022 · 3 comments · Fixed by #32
Closed

Viper does not properly read environment variables #31

gadgethm opened this issue May 31, 2022 · 3 comments · Fixed by #32
Labels

Comments

@gadgethm
Copy link
Contributor

I've been having trouble getting environment variables to work for passing the api token to ddns. I've tried both within an arm64 docker container (built using the repo's dockerfile + arm64 release binary, v4.0.3) and also with direct execution of the ddns binary on my arm64 machine. In both cases, the environment variable "DDNS_TOKEN" is not recognized, and ddns simply reports that a token is required. I also tried with different environment variables as specified in the README, but none of those seem to work either.

Perhaps this is related to this stack overflow issue? https://stackoverflow.com/questions/67608629/viper-automatic-environment-does-not-read-from-environment

@skibish
Copy link
Owner

skibish commented Jun 1, 2022

Hi @gadgethm ,

thanks for reporting this! will try to take a look into this at the end of this week

@skibish
Copy link
Owner

skibish commented Jun 1, 2022

May I ask you to share an example of how do you set the environment variables?

@gadgethm
Copy link
Contributor Author

gadgethm commented Jun 4, 2022

@skibish, sure thing! I use ansible for my deployment, here's the ansible docker-container invocation I'm using:

- name: Start/update ddns container
  community.docker.docker_container:
    name: ddns
    image: skibish/ddns:latest
    env:
      DDNS_TOKEN: "{{ digital_ocean_api_token }}"
    volumes:
      - "/srv/docker/ddns/ddns.yml:/ddns.yml"
    restart_policy: unless-stopped

And here's the contents of /srv/docker/ddns/ddns.yml:

# DDNS configuration file.

checkPeriod: "5m"
requestTimeout: "10s"
ipv6: true

# List of domains and their records to update.
domains:
  "hollandmoritz.net":
  - type: "A"
    name: "@"
  - type: "A"
    name: "*"
  - type: "AAAA"
    name: "@"
  - type: "AAAA"
    name: "*"

The log messages from the ddns container are the following:

time="2022-05-31T23:33:29Z" level=debug msg="using the following configuration file: /ddns.yml"
time="2022-05-31T23:33:29Z" level=fatal msg="token can't be empty"

I was also able to confirm using docker inspect that the container has the environment variable 'DDNS_TOKEN` set to my digital ocean api key.

skibish added a commit that referenced this issue Jun 5, 2022
Added default value to `DDNS_TOKEN` so that Viper would be able
to find the key and matching env.

More details can be found in spf13/viper#761.

Closes #31
@skibish skibish added the bug label Jun 5, 2022
gadgethm pushed a commit to gadgethm/ddns that referenced this issue Jun 5, 2022
Added default value to `DDNS_TOKEN` so that Viper would be able
to find the key and matching env.

More details can be found in spf13/viper#761.

Closes skibish#31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants