Answer the question
In order to leave comments, you need to log in
Should I store docker-compose in VCS?
Previously, I used OpenServer to develop on a local computer.
In git, he kept only the sources of the project being developed.
Simplified structure:
+-- .git
| deploy.sh
| index.php
| deploy.php
On gitlab, a webhook was configured to push to a specific branch, which called deploy.php on the desired server, which in turn launched deploy.sh. In deploy.sh, roughly speaking, git pull was called.
I recently got acquainted with docker and now I'm trying to transfer all development to it.
I describe the stack I need in docker-compose. I forward the folder with the project code (src) to the container via volume.
Now I have not only sources stored in git, but also a config for deploying docker containers.
Simplified structure:
+-- .git
+-- src
|---\ index.php
|---\ deploy.php
|-- docker-compose.yml
|-- deploy.sh
When it comes to automatic code updates, I ran into a problem:
the webhook calls the deploy.php script, which runs inside the virtual machine and does not have access to the external folder with the deploy.sh script.
Tried forwarding the entire external folder to the container, not just the src folder. In this case, the script sees deploy.sh but cannot git pull because it is being run as a user without permission to do so.
How to properly store a project developed using docker?
And what is the best way to set up auto-deploy?
Answer the question
In order to leave comments, you need to log in
And what are deploy.php and deploy.sh for?
For similar projects, I place the steps for deploy in CI (.gitlab-ci.yml), which does everything that is needed for deployment.
Here is an example of my Laravel PHP project in which CI does these steps as part of the deployment:
- generates a config from secret environment variables
- installs dependencies
- copies (mv) sources and dependencies to the web server folder
- runs DB migration
- flushes the cache
https://gitlab.com/SlavikCA/donors-crm/blob/master...
I don't have docker in this project.
But even if it was, I don't think it would change anything.
With Docker, they usually do a slightly different scenario: if a complex application has a lot of dependencies, some unusual web config, etc., then when pushing to the turnip, CI is launched, which builds a new docker image from these files and other dependencies (and not just forwards PHP files to the standard container).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question