error when trying to run docker container from gitlab repository

Viewed 109

i am new to docker and i am trying to run a python scripts in a container from gitlab. the python scripts consist of many files in many folders, but only one file will be called during pipeline runtime.

to achieve that, i build a docker image from python:3.9-alpine with a dummy script (for testing purpose)

here is my dockerfile content:

# syntax=docker/dockerfile:1
FROM python:3.9-alpine

ENV USER=0
ENV GROUP=0
ENV USERNAME=root
ENV GROUPNAME=root

# directory to bind mount on the host
RUN mkdir -p /autom
WORKDIR /autom

COPY . /autom

RUN pip install -r requirements.txt

RUN if [ ${USER:-0} -ne 0 ] && [ ${GROUP:-0} -ne 0 ]; then \
    USERNAME=$(id -un ${USER}); \
    [ $? -ne 0 ] && USERNAME="pythondocker" || userdel -f ${USERNAME}; \
    GROUPNAME=$(id -gn ${GROUP}); \
    [ $? -ne 0 ] && GROUPNAME="pythondocker" || groupdel ${GROUPNAME}; \
    groupadd -g ${GROUP} ${GROUPNAME} &&\
    useradd -l -u ${USER} -g ${GROUP} -s /bin/bash ${USERNAME} &&\
    install -d -m 0755 -o ${USERNAME} -g ${GROUP} /home/${USERNAME} &&\
    chown --changes --silent --no-dereference --recursive \
    --from=33:33 ${USER}:${GROUP} \
    /home/${USERNAME} \
    /autom ; \
    fi

USER ${USERNAME}

ENTRYPOINT ["python"]

the dummy script file is created near the Dockerfile in: scripts/iYamlGenerator/exec/test.py which actually content:

#!/usr/bin/env python

import os

print(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

Note that i didn't include the real scripts. But also i didn't specify the CMD entry in the Dockerfile so that i can play any python scripts (tell me if i am wrong please) after building the docker image with python39-yaml tag and running it from docker host, it walk well as you see bellow:

[root@testcentos23 Docker]# docker run --rm -e USER=$(id -u) -e GROUP=$(id -g) -v $(pwd):/autom:z python39-yaml  scripts/iYamlGenerator/exec/test.py
/autom/scripts/iYamlGenerator
[root@testcentos23 Docker]

in The next step, i builded and pushed my image to our private container registry:

docker login registry.gitlab.<domain.tld>
docker build  -t registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml:latest .
docker push registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml:latest

and then test it once more from docker host:

[root@testcentos23 Docker]# docker run --rm -e USER=$(id -u) -e GROUP=$(id -g) -v $(pwd):/autom:z registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml  scripts/iYamlGenerator/exec/test.py
Unable to find image 'registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml:latest' locally
latest: Pulling from <team>/<project>/python39-yaml
97518928ae5f: Already exists
2a8c531cb7db: Already exists
09868036f38a: Already exists
7e06c97b0c13: Already exists
6a2a7d23cbfc: Already exists
961f6740f879: Pull complete
3d65b05bdb03: Pull complete
00dc69bb2647: Pull complete
Digest: sha256:14ac0ae210b1dfadeb7076fda1876235bf6tr715aaa39fa71b4c01e37a351413
Status: Downloaded newer image for registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml:latest
/autom/scripts/iYamlGenerator
[root@testcentos23 Docker]# 

Now when i try run the same container from my gitlab project, the executable path is not found!

here is my .gitlab-ci.yml content:

variables:
  SCRIPTS_REPO: 'scripts'
  PROJECT_REPO: database/my_project
  GENERATOR_SCRIPTS_DIR: ${SCRIPTS_REPO}/iYamlGenerator
  GENERATOR_OUTPUT_REPO: ${PROJECT_REPO}/.hidden.d
  GENERATOR_INPUTS_REPO: ${PROJECT_REPO}/Inputs.d

stages:
  - refactoring
  - build
  - packages
  - push
  - cleanup

.format_commit_message:
  before_script:
    - export CI_COMMIT_MESSAGE="${CI_COMMIT_MESSAGE} $(git show -s --format=%ci $CI_COMMIT_SHA)"

.pipeline_conditions:
  rules:
    - changes:
      - .gitlab-ci.yml
      - ${PROJECT_REPO}/*.yml
      - ${PROJECT_REPO}/*/*.yml

generate-dev-repo:
  stage: refactoring
  extends:
    - .pipeline_conditions
    - .format_commit_message
  script:
    - docker run --rm -e USER=$(id -u) -e GROUP=$(id -g) -v $(pwd):/autom:z registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml ${GENERATOR_SCRIPTS_DIR}/exec/generate.py
  artifacts:
    paths:
      - ${SCRIPTS_REPO}
      - ${GENERATOR_SCRIPTS_DIR}
  tags:
    - testcentos23

when running the gitlab-ci pipeline, it fail with the following error message:

$ docker run --rm -e USER=$(id -u) -e GROUP=$(id -g) -v $(pwd):/autom:z registry.gitlab.<domain.tld>/<team>/<project>/python39-yaml ${GENERATOR_SCRIPTS_DIR}/exec/generate.py
python: can't open file '/autom/scripts/iYamlGenerator/exec/generate.py': [Errno 2] No such file or directory
ERROR: Job failed: exit status 1

Note that i am now trying to run the real scripts (not a dummy) and that script run very well if executed manually

tanks for your help

0 Answers
Related