Skip to content

Environment variables from files aren't included when using helper functions #57

@jeliebig

Description

@jeliebig

To explain this issue I'll be using the following riptide project setup:

Riptide setup
  • riptide.yml:

    project:
      name: example
      src: .
      env_files:
        - ./.env
      app:
        name: example-app
    
        services:
          nginx:
            $ref: /service/nginx/latest
            read_env_file: true
            environment:
              first_test: "my first value"
            config:
              nginx_conf:
                from: assets/example.conf
                to: '/etc/nginx/conf.d/default.conf'
  • assets/example.conf:

    server {
        listen 80;
    
        server_name {{ domain() }};
    
        set $FIRST_TEST "{{ environment.first_test }}";
        set $SECOND_TEST "{{ environment.second_test }}";
    
        include {{ get_working_directory() }}/nginx.conf.riptide;
        # The [.] turns it into a glob pattern and makes the include optional essentially.
        include {{ get_working_directory() }}/nginx.conf[.]project;
    
        client_max_body_size 100G;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    
    
        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
    }
    
  • .env:

    second_test="my second value"
    

Now when I start this project the config file will be processed like this:

Processed config
server {
      listen 80;
  
      server_name example.riptide.local;

      set $FIRST_TEST "my first value";
      set $SECOND_TEST "";

      include src/nginx.conf.riptide;
      # The [.] turns it into a glob pattern and makes the include optional essentially.
      include src/nginx.conf[.]project;
  
      client_max_body_size 100G;
      fastcgi_buffers 16 16k;
      fastcgi_buffer_size 32k;
  
  
      access_log  /var/log/nginx/access.log;
      error_log   /var/log/nginx/error.log;
  }

So as you can see the value of second_test is empty even though it's included in .env and the service is configured to read the file.

Now if you query the environment of the service using riptide config-get "project.app.services.nginx.environment" you'll also see the key for second_test is missing.

But I can confirm the container knows about this variable if I execute riptide exec --command "printenv second_test" nginx which returns with my second value as expected.

Is this supposed to work like this?

It would be nice to allow helper functions to have access to env files (using the environment key) as well if that's configured for the service.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions