Hello,
I would be grateful if someone could clarify something for me. I have two servers:
GitLab Server: Repositories
GitLab Runner: Runner + Docker
On my GitLab server I have created a project with some code. In the root directory of my project, I have placed two files, .gitlab-ci.yml and Dockerfile.
The content of the .gitlab-ci.yml file is as follows:
stages:
- build
- deploy
before_script:
- mkdir -p node_modules/
cache:
paths:
- node_modules/
build:
stage: build
only:
- main
script:
- mkdir -p node_modules/
- cd /data/containers/SOURCE/
- git clone http://IP/project/test.git
deploy:
stage: deploy
only:
- main
script:
- cd /data/YAML
The docker-compose.yml
file is located at /data/YAML directory on the GitLab runner server. If I add the following lines to the .gitlab-ci.yml file, then will this cause docker compose to use the docker-compose.yml
file located in the /data/YAML directory?
deploy:
stage: deploy
only:
- main
script:
- cd /data/YAML
- docker compose build --no-cache
- docker compose up -d
Any idea welcomed.
Cheers.
Hello,
Is my question clear? Are these commands executed on GitLab server or GitLab Runner server?
Thank you.
Hi,
All commands that are in script
section are executed on the machine where is GitLab Runner, but details depends on your runner executor. It is all explained in the documentation: Get started with GitLab CI/CD | GitLab
If the executor is docker
, Runner will create a container from the docker image specified in the job description (or by default the one that is in config.toml
file of the runner).
If the executor is shell
, it will be executed directly on the VM where the Runner is installed.
If you want to execute a job on some other machine, then you can either use ssh
executor, or configure docker executor to scp (copy files) and ssh into another machine and execute commands. You can google around, or visit previous topics on the forum about this, e.g. Question on Deploy phase of gitlab-ci.yaml - #2 by paula.kokic
Example with docker executor (extension of the config I linked above):
script:
- scp docker-compose.yml user@target-host:~/my-project/docker-compose.yml
- ssh user@target-host "cd my-project && docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD && docker compose pull && docker compose up -d"
1 Like
Hi,
Thank you so much.
I can’t run the Runner. my problem is GitLab Runner cannot see the updated file.