Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pauldruce
Copy link
Contributor

@pauldruce pauldruce commented Aug 2, 2024

Fixes #958

Problem outline

As it currently stands, you can not test source files which have #!/bin/bash at the top of them inside the bats docker image. This is because bash is not located here.

I am aware that it is better practice to have #!/usr/bin/env bash as the shebang at the top of bash scripts - to make them more portable.
However, the vast majority of bash code on GitHub uses /bin/bash (~8 million files). Which means, at them moment, they can't be tested inside the docker image provided by bats without changing their source code.

Summary of change

My proposed change is to symlink bash to the /bin/bash location - which means bats can be used (specifically the docker container running of the tests) can be used by a much wider group of source files.

Testing done

I've done some minimal testing. I've built the docker image using docker build --build-arg bashver="5" --tag bats/bats:bash-pdruce . and then I tested that I could access /bin/bash with the command docker run -it --rm --entrypoint /bin/bash bats/bats:bash-pdruce.

This currently doesn't work for bats/bats:latest - docker run -it --rm --entrypoint /bin/bash bats/bats:latest

@pauldruce pauldruce requested a review from a team as a code owner August 2, 2024 13:24
martin-schulze-vireso added a commit to pauldruce/bats-core that referenced this pull request Sep 13, 2024
@martin-schulze-vireso martin-schulze-vireso force-pushed the pauldruce/dockerfile-bin-bash branch from 535bf8b to fcaaef8 Compare September 13, 2024 13:14
Copy link
Member

@martin-schulze-vireso martin-schulze-vireso left a comment

Choose a reason for hiding this comment

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

I still believe the correct way should be to use #!/usr/bin/env bash. However, we can't ignore a large body of work that might by out of reach for test authors. This is still a single decision and hopefully will not lead to more requests in this vein.

As always: Thanks for your contribution!

@martin-schulze-vireso martin-schulze-vireso force-pushed the pauldruce/dockerfile-bin-bash branch from fcaaef8 to 10c83bc Compare September 13, 2024 13:34
@martin-schulze-vireso martin-schulze-vireso merged commit 07a4297 into bats-core:master Sep 13, 2024
54 checks passed
@pauldruce pauldruce deleted the pauldruce/dockerfile-bin-bash branch September 13, 2024 15:27
tomowatt added a commit to buildkite-plugins/buildkite-plugin-tester that referenced this pull request Jul 4, 2025
* /bin/bash has been symlinked from v1.11.1 - bats-core/bats-core#967

Signed-off-by: Tom Watt <[email protected]>
tomowatt added a commit to buildkite-plugins/buildkite-plugin-tester that referenced this pull request Jul 7, 2025
* chore(deps): update bats/bats docker tag to v1.12.0

* fix: removing check as no longer required
* /bin/bash has been symlinked from v1.11.1 - bats-core/bats-core#967

Signed-off-by: Tom Watt <[email protected]>

---------

Signed-off-by: Tom Watt <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tom Watt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add bash to bats Dockerfile.

2 participants