0

Any ideas why this isn't putting the file into the container?

k6:
    image: loadimpact/k6:0.32.0
    environment:
        - ENVIRONMENT=${ENVIRONMENT}
        - AMOUNT_OF_USERS=${AMOUNT_OF_USERS}
        - RUN_TIME=${RUN_TIME}
    command: run /test.mjs
    volumes:
        - ./load-test.mjs:/test.mjs # <-- this works
        - ./${USERS_FILE}:/users.csv # <-- this does not work

I'm running with the command:

ENVIRONMENT=bla AMOUNT_OF_USERS=5 RUN_TIME=1m USERS_FILE=users2.csv docker-compose up

I did a check inside the container:

console.log(exists('users.csv'))
console.log(exists('test.mjs'))

Results:

k6_1      | time="2021-05-24T11:31:51Z" level=info msg=false source=console
k6_1      | time="2021-05-24T11:31:51Z" level=info msg=true source=console

The USERS_FILE variable file exists in the same directory as the current working directory, i.e. users2.csv.

If I set the volume to the following it works:

- ./users2.csv:/users.csv
basickarl
  • 37,187
  • 64
  • 214
  • 335
  • Does this answer your question? [Using environment variable for volume name in docker compose](https://stackoverflow.com/questions/45103843/using-environment-variable-for-volume-name-in-docker-compose) – DannyB May 24 '21 at 12:09
  • @DannyB Unfortunately no, that is defining a volume name. I would like to name the file name which I want to pull into the container which is dynamic! – basickarl May 24 '21 at 12:34
  • I believe it suffers from the same problem no? It states that variables are not evaluated on the left-hand side (key) of anything. Did you see anywhere that states that variable names *can* be used? – DannyB May 24 '21 at 12:50
  • @DannyB I was able to answer my own question. Apparently you require the absolute path instead of a relative one, which is annoying! – basickarl May 24 '21 at 14:15

1 Answers1

0
volumes:
    - ./load-test.mjs:/test.mjs
    - ${PWD}/${USERS_FILE}:/users.csv
basickarl
  • 37,187
  • 64
  • 214
  • 335