Docker workflow won't pass the inputs as arguments but environnment variables

I’m running a workflow who looks like that:

jobs:
run-docker-tests:
runs-on: ubuntu-latest
name: docker tests
steps:
# To use this repository's private action, you must check out the repository  
-name: Checkout
uses: actions/checkout@v2

# run the tests  
-name: test
uses: ./# Uses an action in the root directory  
with:
foo: bar

And this my action file:

name:'test'  
description:'docker container running some tests'  
inputs:
foo:
description:'foo bar'  
required: true
runs:
using:'docker'  
image:'Dockerfile'  
args:
- ${{ inputs.foo }}

The issue for me is that the inputs are passed as environment variables to the docker container instead of arguments. Is it normal ? How can I pass the inputs as arguments to the container ?

@legraina ,

The issue for me is that the inputs are passed as environment variables to the docker container instead of arguments. Is it normal ? How can I pass the inputs as arguments to the container ?

How do you confirm the inputs are passed as environment variables?

If possible, please share the related  Dockerfile and  ENTRYPOINT with us, so that we can check more detailed configurations of your action to analyze the root cause.

I will provide both files if needed (but I cannot put them here, as too big. A slightly different version can be find here: https://github.com/wssuite/NurseScheduler). However, I do not see why they will be part of the problem as I can see the command run by actions where I can see that inputs are passed as environment variables and not inputs in the log:

/usr/bin/docker run --name c1aa7a27dea60905de2c7298d3bc89dd8d1_c74883 --label 430c1a --workdir /github/workspace --rm -e INPUT_FOO -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v “/var/run/docker.sock”:"/var/run/docker.sock" -v “/home/runner/work/_temp/_github_home”:"/github/home" -v “/home/runner/work/_temp/_github_workflow”:"/github/workflow" -v “/home/runner/work/pNurseScheduler/pNurseScheduler”:"/github/workspace" 430c1a:a7a27dea60905de2c7298d3bc89dd8d

@legraina ,

Yeah, I see it.

However, actually this does not mean the inputs are passed as environment variables.
By default, GitHub will try to map all the provided inputs of an action as environment variables on the runner (other CI/CD services, such as Azure Pipelines, also are similar).

When run the Docker container actions, it also will try to map the related environment variables from the the runner into the container. But for some reasons, the inputs of the Docker container actions actually are not mapped as environment variables on the runner. So the nonexistent environment variables will not be mapped into the container, although they are set in the docker run command.

Currently, only the inputs of the JavaScript actions have been mapped as environment variables on the runner.

I guess, the environment variables for the inputs is designed to store the information (<key>:<value>) of the inputs, so that the scripts executed in the action can use these information to do some things (for example, using in the if statement).

Because the inputs of the Docker container actions have not been mapped as environment variables, currently the environment variables for the inputs you see in the docker run command are not sense. These names of environment variables may currently only be set as backup so that can be used in the future.

If you execute the command “printenv” in the Docker container action, you can see these environment variables actually is not existing in the container (here is an example).

Hope my above explanations can help you understand.

1 Like

Thanks for you answer. I have forked the repo you referenced and it works correctly: https://github.com/legraina/hello-world-docker-action

However, when I’m doing exactly the same steps, I’m not able to get the inputs in the docker run. I really do not understand what happened. I can give you access to the repo or attach all the files here.

@legraina ,

However, when I’m doing exactly the same steps, I’m not able to get the inputs in the docker run. I really do not understand what happened.

Can you provide an example on your side to show this problem? Share your repository with us to analyze the root cause.

@brightranI would prefer to give access to a team or someone. I could also make it public temporally. What is the best option ?

@legraina ,

You can create a temporary public repository, and share a demo that can reproduce the problem you are facing in the public repository. Please provide the configurations as detailed a as possible in your repository.

Then share the link of the public repository with us, so that we can check the detailed configurations of the workflow in the repository to analyze the root cause.

@legraina,
I can see the below warning message from your workflow run:

Unexpected input 'ns-args', valid inputs are ['']

This warning is returned generally when you are using an undefined input on the action in the workflow. And in the warning message, it also will list all the defined valid input (if any) on the action.

I checked the repository of your action, and found the defect is that no required metadata file ( action.yml or action.yaml) in the repository.

According to the description from the docs about creating actions (see here):

Docker and JavaScript actions require a metadata file. The metadata filename must be either action.yml or action.yaml . The data in the metadata file defines the inputs, outputs and main entrypoint for your action.

So, you should add the required metadata file ( action.yml or action.yaml) at the root of your action repository, and define all the possible inputs (required and optional) in the metadata file.

More details about creating actions, you can reference here: https://help.github.com/en/actions/creating-actions

@brightran I have followed exactly these steps and use the example as a base. the .action.yml is there, but not in the master, in the action branch.

Please be careful:
The metadata file should be named “action.yml” or “action.yaml”, NOT “.action.yml” or “.action.yaml”.
You have added an extra dot (.) at the start of the name.

Thanks it works. Sorry for this silly mistake

@legraina,
You’re welcome, and glad that I can help you solve the problems.
If you have any questions about this ticket, feel free to contact me.