I’m starting the development of a new app, that will run in an instance for each of my customers. Up to now, I’ve allways developed “one instance” apps, because those are taylor made for each customer. But this new one will be a standard product.
So, I’m thinking about how to automate the new instance setup:
Create site in Apache
Clone the GIT repository - Install dependencies with composer
Create the database
Associate the database to the instance
After step 5, I should have the instance ready for first use.
Have anyone worked on something like this? If yes, what is the best approach?
Talking to a fellow PHP developer with no CakePHP background, he suggested using Docker.
Yes docker is the way to go. Using docker you can have consistent configuration of your apache, php, mysql. So you don’t have to worry about managing the configuration and versions for each of them. You can specify the default skeleton cakephp app to fetch the project and then simply use CakePHP migrations to migrate the database structure.
You can find reference for docker with cakephp using below links:
Yes docker will make the project super portable. Try to use docker-compose to set it up and use an .env file to configure database, smtp, error reporting, etc.
I have a docker image that adds a simply run.sh that does:
Waits for mysql to be ready (if it does not connect in 30 seconds it fails, restarting the container)
Run migrations and plugins migrations
(Add extra steps like creating upload folder structure in docker volume)
that way when you want to deploy a new client. You have to copy only docker-compose.yml, the env file (configure it), call docker-compose up -d and you are ready.
When there is an update, simple make docker-compose pull, docker-compose up -d (assuming you setup your public/private docker registry).
You can setup other services like mariadb, redis, etc. in the same docker-compose file. If you have a cron, when you build the docker image with apache/nginx and cron. Set up as 2 identical services, but only one command: cron -f -l 8 for example.
Hi Bizdev, Raul, seems clear that Docker is the way to go then. I’ll research how it works, since I have never used it. I have one question, can you deploy multiple dockers in one server? Does it have a significative performance penalty?
So, I watched the video and the GitHub posted by BizDev. In order to clarify my understanding of the subject, Stefan shows how to:
Create a Docker container for MySQL
Create a Docker container for a fresh app, attached to the MySQL container and the database there created
He states that containers are stateless. Does that mean that the if the MySQL Docker container stops, the database is lost? I understand that it can be persisted, as it says in the MySQL Docker page linked by Stefan.
Anyway, if I have a Linux server, one strategy might be to containerize only CakePHP, and use connection strings pointing to the server’s MySQL? The Docker instance can see the hypervisor?
As you guys can see, I have more questions than answers with this subject.
Docker defines volumes, everything that is not in a mounted volume is lost on container deletion/upgrade.
For example, MySQL/MariaDB container you should mount the volume /var/lib/mysql to /var/clients/client1/db.
Yes, you can have multiples instances of the same image in the same host:
I could define another db instance only for testing without volume, so that when redeploying testing, it would run migrations again from empty database.
Of course you would want every client to access the app via app.client-domain.com:80, for that you have to use a load balancer like traefik, nginx or caddy
Traefik use the same docker socket to discover every container, but you have to pass it as a volume.
If you refer to other hypervisrors (virtualbox, vmware, etc) then no, other solutions like kubernetes/docker-machine can create and use other hosts, although that is more advanced (you would have to centralize volumes, logs, or fix instances to hosts, etc)
Its a whole new topic. But gives you more control/scalability than classic vms/vps for each client.