GoogleContainerTools / GoogleContainerTools/container-structure-test

Tests relying on .bashrc being loaded not working

Open
#275 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.5k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

Hi all.
First of all... great library, really like the simplicity of it.

We have a fairly rich docker container that makes heavy use of bash scripting to dynamically define env variables in the ~/,bashrc. After trying all kind of things for the last days I cannot get container structure tests to work in the context of the bashrc. Whatever I do, the env vars seem to be undefined.

Here's an example Dockerfile I wrote up:
```dockerfile
FROM debian:buster

RUN echo "export FOO=BAR" >> /root/.bashrc
RUN echo "echo 'bashrc loaded!'" >> ~/.bashrc

# this is strictly seen not necessary, but it forces the bashrc to be always loaded, not just in interactive mode and suppresses a related warning:
ENV BASH_ENV=/root/.bashrc
```

These are my example tests - they all fail.
The output indicates that the .bashrc is actually loaded, but the actual test seems to run separately under a different context - FOO seems never defined in the test context and the output of `$FOO` is always blank.

```yml
schemaVersion: 2.0.0

commandTests:
- name: "echo FOO"
command: echo
args: [ "$FOO" ]
expectedOutput: [ "BAR" ]
- name: "echo FOO using bash -c wrapper and enumerated args"
command: "bash"
args:
- -c
- "echo $FOO"
expectedOutput: [ "BAR" ]
- name: "echo FOO using bash -c wrapper and string array args"
command: "bash"
args: ["-c", "echo $FOO"]
expectedOutput: [ "BAR" ]
- name: "echo FOO using bash -c wrapper, pipe and source .bashrc"
command: "bash"
args:
- -c
- |
source ~/.bashrc &&
echo $FOO
expectedOutput: [ "BAR" ]
```
I also tried to specify a custom entry point using `setup: [["entrypoint.sh"]]` with the same result.
entrypoint.sh:
```bash
#!/bin/bash
source /root/.bashrc
```

Any help is greatly appreciated!
We already wrote fair a bit of non-bash tests, but cannot use this framework without proper bash support :(

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.