2
votes

Currently I have a project (repo) in Gitlab which is an angular app. I'm using Gitlab CI/CD to build, test, release and deploy. Releasing will build a new docker image pushing it to the Gitlab registry and after deploying it on NGinx in a docker container on my Digital Ocean droplet. This works fine.

Let's say I want to add a backend to it like the MEAN stack so I would have 2 containers running using a docker-compose file.

  • container 1 - Angular
  • container 2 - Node.js, Express.js and MongoDB

The 2 gitlab projects (repo's) will have to be build separately when a change occurs (own Dockerfile and gitlab-ci.yml file) but deployed together using the docker-compose file.

Where do I manage/put the docker-compose file?

I hope my explanation is clear and if I'm assuming correctly.

Thanks in advance.

1
In CI/CD how to manage dependency between frontend and backend? is maybe not an exact duplicate question, but the overall idea seems to apply in your use case as well: you could add a docker-compose.yml file with dedicated integration tests in a third repository and rely on a tags naming convention to pull the proper backend / frontend versions, or maybe just have 2 repos with the docker-compose.yml file in the frontend repo. Otherwise, follow a so-called monorepo setup, that is a single repo with several folders and a single CI.ErikMD
Hi, thanks for your reply. Monorepos have some great advantages especially in this case but I don't think Gitlab CI is possible with a monorepo that's why I assumed to create 2 repos. This is my first project using Gitlab CI/CD. I'll try to look further.Sven
If you start with GitLab CI, I'd first recommend bookmarking the .gitlab-ci.yml YAML reference manual (docs.gitlab.com/ee/ci/yaml). Next, GitLab CI indeed supports monorepo workflows, cf. this doc page which gives an example of use of the changes: key; see also e.g. this article relying on Docker or that article taking advantage of the needs: key.ErikMD

1 Answers

1
votes

According to your comment I understand you'd be interested in adopting a monorepo configuration.

In this case, for the question

Where do I manage/put the docker-compose file?

you could just put the docker-compose.yml file at the root of your GitLab CI project, which would lead to a directory structure like this:

monorepo-project/
├── backend/
│   ├── Dockerfile
│   ├── .dockerignore
│   └── src/
├── frontend/
│   ├── Dockerfile
│   ├── .dockerignore
│   └── src/
├── docker-compose.yml
├── .git/
├── .gitignore
└── .gitlab-ci.yml

As pointed out in https://docs.gitlab.com/ee/user/packages/workflows/monorepo.html (the original version of this page, deleted by this commit, is still available at this URL), you can tweak your configuration using the changes: key, so that if just one part of the project changes (e.g., the frontend), then the CI behaves accordingly.

Further pointers

For more examples, see e.g. this article in Medium which specifically relies on Docker, or that blog article which takes advantage of the needs: key.

Finally, the semantics of the GitLab CI YAML conf file is well-documented in https://docs.gitlab.com/ee/ci/yaml/ (to be bookmarked!).