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

The PATH environment variable does not contain the path to ghc when using docker-compose #63

Closed
mrcjkb opened this issue Jan 25, 2022 · 3 comments

Comments

@mrcjkb
Copy link

mrcjkb commented Jan 25, 2022

How to reproduce

Given the following compose file

version: '2.3'

services:
  build:
    image: haskell:9.2.1
    volumes:
      - .:/usr/app
    command: bash -lc "printenv && cd /usr/app && cabal init"

When I run

COMPOSE_FILE=<name-of-compose-file>.yml docker-compose run --rm build

Epected

Then cabal initialises a project and /opt/ghc/9.2.1/bin is in the PATH environment variable that is printed

Actual

Then cabal fails with The program 'ghc' version >=7.0.1 is required but it could not be found.
And the PATH is printed as PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

@mrcjkb
Copy link
Author

mrcjkb commented Jan 25, 2022

This could probably be solved by adding the PATH to ~/.bashrc:

RUN echo "export PATH=${PATH}" >> /root/.bashrc

I will test this later.

@AlistairB
Copy link
Contributor

Thanks for the issue!

I'm interested to know the motivation for using a login shell? (the -l flag to bash).

https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html suggests different files that could be used to add GHC to the PATH.

I've done some testing on other official images and about 50% will work with a login shell. They seem to work because they happen to copy executables into /usr/local/bin (like we do with cabal + stack) rather than doing anything with .bash_profile etc.

I've been using docker run haskell:9.2.1 bash -lc "ghc --version" as a minimal repro BTW.

@mrcjkb
Copy link
Author

mrcjkb commented Jan 25, 2022

Thanks for the hint. I ended up not needing the login shell for my project (I had copied over and modified the compose file from another project that was running end-to-end tests).

I'll close this issue, as I don't think there is a use case for building Haskell projects in a login shell.

@mrcjkb mrcjkb closed this as completed Jan 25, 2022
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

No branches or pull requests

2 participants