Search code examples
dockergitlabsbtgitlab-cigitlab-ci-runner

Is there a way to run sbt-native-packager within Gitlab shared runner?


I've been trying to build docker images in Gitlab shared runner. I'm building my application using image: "hseeberger/scala-sbt:11.0.6_1.3.10_2.11.12" image normally and I locally build the docker image with sbt-native-packager which made me think that i need to use DiD service.

I'm currently having an issue which the sbt-native-packager cannot locate docker executable and fails to build the image. What I am missing here?

My script is as follows:

docker:
  stage: deploy
  image: "hseeberger/scala-sbt:11.0.6_1.3.10_2.11.12"
  services:
    - name: docker:dind
  script:
    - sbt docker:publishLocal
    - docker push registry.gitlab.com/groupName/moduleName

Solution

  • The following actually did the trick for me although it is quite heavy to install Docker in the runner every time, however, that's the only way I could make it work.

    docker:image:
      stage: release
      image: "hseeberger/scala-sbt:11.0.6_1.3.10_2.11.12"
      before_script:
        - apt-get update
        - apt-get install sudo
        - apt-get install apt-transport-https ca-certificates curl software-properties-common -y
        - curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
        - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
        - apt-get update
        - apt-get install docker-ce -y
        - sudo service docker start
        - docker login <to your account>
    
      script:
        - sbt docker:publishLocal
        - docker tag module:latest registry.gitlab.com/moduleGroup/module:0.1-SNAPSHOT
        - docker push registry.gitlab.com/moduleGroup/module