Menu

GitLab CI: How to Use a Dockerfile from Remote Repository
πŸ“°
0

GitLab CI: How to Use a Dockerfile from Remote Repository

DEV Community: gitlabΒ·Kelvyn ThaiΒ·about 1 month ago
#RkvBYrLp
#dev#repositories#class#code#highlight#strong
Reading 0:00
15s threshold

🧩 The Problem You have multiple (group) projects (frontend, backend, etc.) and you want: A single Dockerfile in a central repo ( cicd-template/frontend/gitlab-template.yml ) All group app repos reuse it No duplication, no drift, better control You try: include : - project : " kelvyn-labs/cicd-template" ref : master file : " /frontend/gitlab-ci.yml" But during the pipeline: docker build -f frontend/Dockerfile . πŸ‘‰ ❌ It fails β€” file not found 🧠 Why This Happens In GitLab: include:project only imports CI YAML , not repository files Your pipeline still runs inside: nextjs-cicd-template So it cannot access files from: cicd-template ❌ Common (Wrong) Solutions Copy Dockerfile into every repo ❌ Use Git submodules ❌ (heavy, messy) Assume include gives file access ❌ βœ… The Correct Solution Use: CI_JOB_TOKEN + GitLab Repository Files API When a CI/CD pipeline job is about to run, GitLab generates a unique token and makes it available to the job as the CI_JOB_TOKEN predefined variable.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More