2

I would like to have all my dockerfiles in one repository, instead of having them in the seperate projects. Therefore I have created the project "conductor". All my .gitlab-ci stages are also specified in "conductor". In the actual project I only use the include command.

My current code:

docker build -f dockerfile .

Problem is that "dockerfile" isn't in the project where the pipeline gets executed but is in the "conductor" project.

How can i modify the -f parameter to take the dockerfile from another gitlab project?

1
  • 1
    ? Clone the repository and -f /path/to/dockerfile ? Commented Dec 20, 2020 at 12:01

3 Answers 3

1

You can use

git clone https://gitlab.example.com/tanuki/awesome_project.git

to clone the remote repo. If the repo is not publicly accessible, you can create a deploy token to do this and use git clone with the deploy token.

git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git

see: https://docs.gitlab.com/ce/user/project/deploy_tokens/#git-clone-a-repository

Sign up to request clarification or add additional context in comments.

Comments

1

I would like to have all my dockerfiles in one repository, instead of having them in the seperate projects. Therefore I have created the project "conductor". All my .gitlab-ci stages are also specified in "conductor". In the actual project I only use the include command.

It looks like a good usecase to define the generic stage/template in the common repository and to to include them in the users repositories via the include keyword.
Look at the include documentation :

include Use the include keyword to include external YAML files in your CI/CD configuration. You can break down one long gitlab-ci.yml into multiple files to increase readability, or reduce duplication of the same configuration in multiple places.

From user git repositories you could include the common template in the .gitlab-ci.yml such as :

include:
  - project: 'my-group/my-common-project'
    file: '/templates/.gitlab-ci-docker-build-template.yml'

And of course, reference the common stage(s) you need to use in it.
Note that the common templates are not ridid. User/consummer repositories may override some things. For example variables are overridable.

Comments

0

The actual project could add conductor as a Git submodule (git submodule add.
In conductor, you would store your Dockerfile, one per actual project.

That way, your actual project can use

docker build -f conductor/dockerfile.actual

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.