3

So I am trying to do docker-compose build from my GitLab CI/CD pipeline by using a docker-compose file but it fails. Trying the same on my PC locally through Windows PowerShell works just fine.

Error in GitLab pipeline

Building spotforus-server
Step 1/4 : FROM openjdk:17
 ---> 5e28ba2b4cdb
Step 2/4 : WORKDIR /spotforus
 ---> Using cache
 ---> 795b15010444
Step 3/4 : COPY build/libs/spotforus-0.0.1-SNAPSHOT.jar /spotforus/spotforus.jar
Service 'spotforus-server' failed to build: COPY failed: file not found in build context or excluded by .dockerignore: stat build/libs/spotforus-0.0.1-SNAPSHOT.jar: file does not exist

Docker-compose file

version: '3.8'

services:
    db:
      image: mysql:latest
      container_name: mysql-db
      ports:
        - "3306:3306"
      restart: always

    spotforus-client:
      build:
        context: ./spotforus-client
        dockerfile: Dockerfile
      container_name: "spotforus-client"
      ports:
        - "80:80"
      depends_on:
        - spotforus-server
    
    spotforus-server:                      
      build: ./spotforus            
      container_name: spotforus-server
      ports:
        - "8080:8080"                       
      restart: always
      depends_on:

Dockerfile

FROM openjdk:17
WORKDIR /spotforus
COPY build/libs/spotforus-0.0.1-SNAPSHOT.jar /spotforus/spotforus.jar
ENTRYPOINT ["java","-jar","spotforus.jar"]

Gitlab yml file

stages:
  - docker

docker:
  image:
    name: docker/compose:latest
  services:
    - docker:dind
  stage: docker
  script:
    - docker-compose build

GitLab runner config

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Runner"
  url = "https://somedomain.gitlab/"
  id = 7341
  token = "BeNAc2f9gFW-sWX6pewA"
  token_obtained_at = 2022-11-08T09:36:30Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "gradle:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

I have been reading similar posts here and it seems that the issue is caused by Docker context so I tried tweaking this in my dockerfile and docker-compose but no luck so far.

z3r0-21
  • 51
  • 5

1 Answers1

0

The issue turned out to be caused by the .gitignore file which was set to exclude .jar and /build. That's why docker-compose build worked just fine locally but failed in the Gitlab pipeline. This comment really helped me to understand how to create exceptions in .gitignore.

z3r0-21
  • 51
  • 5