I use DevSpace tool to deploy my services into minikube local cluster.
I have two services to deploy: auth-handler and mysql;
auth-handler has the dependency of my-sql in devspace.xml. So it can't start till mysql hasn't been deployed.
auth-handler
dependencies:
- source:
path: ../mysql
namespace: databases
mysql has the image stage. Where in Dockerfile I perform logic to initiate DB by some data.
images:
backend:
image: registry.kube-system.svc.cluster.local/mysql
tags:
- local
dockerfile: ./mysql/Dockerfile
The first time, it works fine. But for example when I redeploy services the second time mysql image stage for mysql is skipped because DevSpace caches the image stage if it's already been successfully built. So my DB isn't initialized at this time because image stage skipped.
I can manually deploy mysql with -b / --force-build
to deploy mysql with the forcing launching of image stage but I don't need to manually deploy mysql. I need to initiate deployment of auth-handler and it will initiate deploying mysql in -b / --force-build``-b / --force-build
mode.
Instead of populating your database within the Dockerfile, I would recommend adding a hook in the hooks
section of devspace.yaml which could run devspace enter -c [mysql] -- command-to-populate-db
or alternatively, adding an init container to populate the database. This will be a lot more flexible.
For more details on hooks, have a look at the DevSpace docs: https://devspace.sh/cli/docs/configuration/hooks/basics