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

Forward ENV to the sub-container #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
- name: Checkout
uses: actions/checkout@v2 # Required to mount the Github Workspace to a volume
- uses: addnab/docker-run-action@v3
env:
ABC: 123
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: gcr.io
image: private-image:latest
options: -v ${{ github.workspace }}:/work -e ABC=123
options: -v ${{ github.workspace }}:/work
run: |
echo "Running Script"
/work/run-script
Expand Down
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

env | grep -v '^#' | xargs > docker-run-action.env
Copy link

@Dexus Dexus Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work as you may expect.
Your "fix multi line ENV" will here not work.
Please have a look to Dexus-Forks@dc7d5ec

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A other thing is what I forgot about to tell:

  • DOCKER_VERSION -> both container the first one has this ENV and the second the one in the SMOKE test, has the same, but via this ENV forward you overwrite the second container ENV to be generated and shadow it with the ENV that is forwarded.
  • PATH you copy the PATH form container 1 to container 2 >>> very bad and brings problems to find shell and other stuff.
  • what do we need to forward?
    • I think it would enough to forward all ENV with PREFIX and 2 more (that are exposed also to the second container)
      • CI (this is the only exception form PREFIX -> this is "CI=TRUE" if you check for it.)
      • HOME (this is exposed to docker 1 which is starting docker-container and also exposed there)
      • INPUT_*
      • GITHUB_*
      • ACTIONS_*
      • RUNNER_*

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using env | egrep -v "^(#|;| |INPUT_*|PATH|HOME)" | awk '$1 ~ /^\w+=/' | xargs -0 > docker-run-action.env in various workflows without any issues so far :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you not forward the INPUT_* ENVs?
This will result in a problem if you run via workflow_dispatcher your input will not reach the container.

Copy link

@Fuseteam Fuseteam Oct 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i took a look at the contents of docker-run-action.env and it appears the current revision also forwarded HOSTNAME, SHLVL and DOCKER_VERSION (among other DOCKER_* variables 🤔

given the list above would it perhaps better to do env | egrep -v "^(#|;| |PATH|SHLVL|HOSTNAME|DOCKER_*)" | awk '$1 ~ /^\w+=/' | xargs -0 > docker-run-action.env?


if [ ! -z $INPUT_USERNAME ];
then echo $INPUT_PASSWORD | docker login $INPUT_REGISTRY -u $INPUT_USERNAME --password-stdin
fi
Expand All @@ -8,4 +10,4 @@ if [ ! -z $INPUT_DOCKER_NETWORK ];
then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK"
fi

exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "${INPUT_RUN//$'\n'/;}"
exec docker run --env-file docker-run-action.env -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "${INPUT_RUN//$'\n'/;}"