I
I
Iceforest2021-12-12 20:34:05
GitLab
Iceforest, 2021-12-12 20:34:05

How to fix gitlab pipeline?

I'm trying to make a gitlab pipeline. so that with each push, the repository is checked for the validity of the
pipeline code:

image: docker:dind

stages:
  - test
test:
  stage: test
  script:
    - cp -r ./ /golang_app/
    - cd /golang_app/
    - chmod +x /golang_app/run-tests.sh /golang_app/scripts/test_in_docker.sh
    - chdir /golang_app/  
    - /bin/sh ./run-tests.sh
  tags:
    - docker


in run-tests.sh:
#!/bin/bash

docker run \
    -v $(pwd):/tests \
    golang:1.16.6-alpine3.14 \
    /tests/scripts/test_in_docker.sh


in the repository itself:
total 68
drwxrwxrwx    5 root     root          4096 Dec 12 16:26 .
drwxrwxrwx    4 root     root          4096 Dec 12 14:22 ..
drwxrwxrwx    6 root     root          4096 Dec 12 16:26 .git
-rw-rw-rw-    1 root     root            77 Dec 12 14:22 .gitignore
-rw-rw-rw-    1 root     root           171 Dec 12 16:26 .gitlab-ci.yml
-rw-rw-rw-    1 root     root           267 Dec 12 14:22 Dockerfile
-rw-rw-rw-    1 root     root          1071 Dec 12 14:22 LICENSE
-rw-rw-rw-    1 root     root          1630 Dec 12 14:22 README.md
drwxrwxrwx    3 root     root          4096 Dec 12 14:22 cmd
-rw-rw-rw-    1 root     root           190 Dec 12 14:22 docker-compose.yaml
-rw-rw-rw-    1 root     root           107 Dec 12 14:22 go.mod
-rw-rw-rw-    1 root     root         13518 Dec 12 14:22 go.sum
-rwxrwxrwx    1 root     root           117 Dec 12 14:22 run-tests.sh
drwxrwxrwx    2 root     root          4096 Dec 12 14:22 scripts

I get this in the gitlab-runner log, as soon as I didn’t try to launch it, I don’t want to
$ cp -r ./ /golang_app/
$ cd /golang_app/
$ chmod +x /golang_app/run-tests.sh /golang_app/scripts/test_in_docker.sh
$ chdir /golang_app/
$ /bin/sh ./run-tests.sh
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/tests/scripts/test_in_docker.sh": stat /tests/scripts/test_in_docker.sh: no such file or directory: unknown.
time="2021-12-12T17:24:22Z" level=error msg="error waiting for container: context canceled"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Iceforest, 2021-12-12
@Iceforest

I decided with a regular runner, not Docker and without image
stages:
- test
test:
stage: test
script:
- /bin/sh ./run-tests.sh
tags:
- shell-runner

S
stitrace, 2021-12-12
@stitrace

To run the script in docker, you need to add the -it flag

docker run -it -v $(pwd):/tests golang:1.16.6-alpine3.14 — /bin/bash -c “tests/scripts/test_in_docker.sh”

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question