deck-chores icon indicating copy to clipboard operation
deck-chores copied to clipboard

Use Environment variables from the running container

Open psyciknz opened this issue 3 years ago • 4 comments

With the command parameter, is there a way I can access an enviroment variable that is already inside the container?

For example I'm using mazzolino/restic It defines a number of environment variables for restic that include some backup args - eg $RESTIC_BACKUP_ARGS - as these are already defined, and in the container, and useful, I was hoping if I run a command in this container I can access this variable.

I've tried:

deck-chores.daily-job.command: bash -c "restic backup /data/Documents $RESTIC_BACKUP_ARGS $RESTIC_FORGET_ARGS &> /proc/1/fd/1"
       deck-chores.daily-job.cron: "* * * 7 32 * "

and

deck-chores.daily-job.command: bash -c "restic backup /data/Documents ${RESTIC_BACKUP_ARGS} ${RESTIC_FORGET_ARGS} &> /proc/1/fd/1"
       deck-chores.daily-job.cron: "* * * 7 32 * "

to no effect. Any way I can access these variablres?

psyciknz avatar Jul 27 '22 19:07 psyciknz

i guess that bash isn't passing the environment variables to the command. if you figure out that this is the case and how it can be tackled, i'd be interested in a note for the docs.

another way is to place/mount an executable script in the container filesystem and call that directly.

funkyfuture avatar Jul 28 '22 10:07 funkyfuture

I think I did work it out.

deck-chores.job-documents.command: bash -c "restic backup /data/Documents --tag Documents --verbose $$RESTIC_BACKUP_ARGS --exclude-file=/config/exclude.file &> /proc/1/fd/1

I’ll try to confirm that again, as I didn’t end up using it.

running it a restic docker container, that knows about the repository and password already.

psyciknz avatar Jul 28 '22 10:07 psyciknz

could you come to a final conclusion?

funkyfuture avatar Aug 23 '22 15:08 funkyfuture

Sorry for the delay. Yes the command above the variable $$RESTIC_BACKUP_ARGS is resvolved.

I tested it with an echo command of the same variable and I can see them being output.

deck-chores.job-pictures-test.command: bash -c "echo $$RESTIC_BACKUP_ARGS &> /proc/1/fd/1"

and the log output from the container:

--tag ChangingData --tag CameraVideos --tag eBooks --tag OldCameraVideos --tag Music --tag Documents --tag Pictures --exclude-file=/config/exclude.file --exclude='*.tmp' --verbose

psyciknz avatar Aug 31 '22 03:08 psyciknz