Answer the question
In order to leave comments, you need to log in
Explain on your fingers how to prepare CI using GitLab, GitLab runner, docker, php?
I study continuous integration. I'm trying to figure out the basic processes and I can't get a picture in my head.
Given:
1. The server where GitLab is installed, there is a PHP project. The index.php file with the content . phpinfo();
2. Virtual machine with CentOS 7.
2.1. Installed docer on it.
docker -v
Docker version 19.03.7, build 7141c199a2
docker run -d --name gitlab-runner --restart always \
-v /docker/gitlab-runner/volumes/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
docker run --rm -t -i -v /docker/gitlab-runner/volumes/config:/etc/gitlab-runner gitlab/gitlab-runner register
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
name = "xxxRunner"
url = "http://_xxx_/gitlab/"
token = "_xxx_"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.docker]
tls_verify = false
image = "alpine:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
job1:
script:
- php -v
job2:
script:
- php -v
Running with gitlab-runner 12.8.0 (1b659122)
on _xxx_Runner 50b311ce
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a for alpine:latest ...
Running on runner-50b311ce-project-8-concurrent-0 via 2333629aca2f...
Fetching changes...
Reinitialized existing Git repository in /builds/gitlab/_xxx_/_xxx_/.git/
From _xxx_
2c41219..48aa22e master -> origin/master
Checking out 48aa22eb as master...
Skipping Git submodules setup
/bin/sh: eval: line 56: php: not found
$ php -v
ERROR: Job failed: exit code 127
Answer the question
In order to leave comments, you need to log in
Firstly, I advise you to take the same alpine or any other docker image,
1. run it on your computer
docker run -it *IMAGE* sh
or
docker run -it *IMAGE* bash
and install everything you need to build. php, curl, composer.. depending on the project.
2. Next, based on your actions, create a dockerfile
FROM image
RUN apk update && apk add php7-fpm curl...
3. Use COPY/ADD to copy the project to the container (to simulate the process). And execute the necessary in the container to build the project.
4. Copy the necessary commands to gitlab-ci.yaml
Note that if you want to package your project in docker, for example to run in k8s, you need to use dind (docker in docker) or gitlab runner should work directly, not in docker. Because otherwise you won't be able to run docker build ... in the CI/CD process
If the commands are executed inside a runner container, how do I checkout the project from git and put it on the host?
Reinitialized existing Git repository in /builds/gitlab/_xxx_/_xxx_/.git/
From _xxx_
2c41219..48aa22e master -> origin/master
Checking out 48aa22eb as master...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question