How to add Stack and GHC on GitLab's Continuous Integration?

Viewed 226

My CI cant find stack and I don't know why. I'm using the following .gitlab-ci.yml file for setting up gitlab-CI for a Haskell Stack project. I took it from this other question that claims it worked.

image: haskell:8.6.5

cache:
  paths:
    - .stack
    - .stack-work
    - target

test:
  stage: test
  script:
    - ghc --version
    - stack --system-ghc build
    - stack test

However it fails and reports (full output below):

bash: line 96: ghc: command not found
ERROR: Job failed: exit status 1

Clearly, ghc is missing, but I though that came on the image haskell:8.6.5 doesn't it?

I have tried alternative images such as image: fpco/stack-build:lts-11.15 without any luck (reports bash: line 96: stack: command not found).

My best guess is that I'm missing a crucial step to make sure ghc and stack are on the image I'm using, but I can't figure out what it is. So, what am I missing?

Edit: full error output

Running with gitlab-runner 13.2.2 (a998cacd)
  on karson: Ubuntu 20.04 LTS Shared q_B8_V-j
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on karson...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Initialized empty Git repository in /var/lib/gitlab-runner/builds/q_B8_V-j/0/fromager/cheesecloth/MicroRAM/.git/
Created fresh repository.
Checking out 4d7e065d as 39-continuous-integration...
Skipping Git submodules setup
Restoring cache
00:00
Checking cache for default...
Runtime platform                                    arch=amd64 os=linux pid=4053876 revision=a998cacd version=13.2.2
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:00
$ ghc --version
bash: line 96: ghc: command not found
ERROR: Job failed: exit status 1
1 Answers

From the output log, you are using the shell executor rather than the docker executor, which is why the image tag is having no effect here.


Options to resolve is to either:

  • If you have access to the runner's server, re-install the runner as a docker executor (https://docs.gitlab.com/runner/install/docker.html), and ensure you use tags to specify which runner to use for the job. (You might not necessarily need to re-install the runner, but to just install the runner alongside the shell runner, but you need to make sure to use tags correctly as to whether or not you want to use the shell runner or docker runner).

  • Run the docker commands manually as shell (although this one is less ideal).


Update: for ensuring you pick the correct runner for the job:

When registering the runner, at step 5, you can provide tags associated with the runner. You can also change the tags in the GitLab UI if you have sufficient permissions in:

gitlab.com -> group -> settings -> CI/CD -> runner settings

Note, the runner tags are not changeable in the config.toml file.

You can now, for example, tag your runner with docker-internal, and then to run jobs only on this runner, add tags: - docker-internal in your gitlab-ci.yml file:

test:
  stage: test
  script:
    - ghc --version
    - stack --system-ghc build
    - stack test
  tags:
    - docker-internal
Related