How do I ensure my Docker Compose services are deployed before the other deploy commands run

If I have a mixed deployment mechanism of Docker-Compose plus additional commands (i.e. helm command, kubectl commands, etc.).

Based on the Okteto Manifest documentation here, the deployment process of my setup below always performs the deploy.commands first, and then deploys the Docker-Compose file second, no matter what order I put them under the deploy section:

deploy:
  compose: docker-compose.yml
  commands:
    - helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}

How can I ensure the Docker-Compose file gets deployed first?

There are two approaches that could help in this scenario:

1. Turn the deploy.compose into a custom command under deploy.commands.
For the manifest setup shown above, you can turn the deploy.compose into a command with the --wait flag. Make sure the command is specified first before the helm upgrade command, as shown below:

deploy:
  commands:
    - okteto deploy -f docker-compose.yml --wait
    - helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}

2. Add the docker-compose service as a dependency
This approach requires a bit more effort, and the creation of an additional okteto manifest in the same repository. You can follow these steps to set it up:

  • Create an additional okteto manifest in the same repository, compose-okteto.yml, pointing to the docker compose on the deploy.compose configuration as shown below:
deploy:
  compose: docker-compose.yml
  • On your original okteto manifest, okteto.yml, refer to this docker-compose service/s as a dependency pointing to the compose-okteto.yml file and remove its reference under the deploy section, as shown below:
dependencies:
  compose-service:
    repository: <git url>
    manifest: compose-okteto.yaml
    wait: true
deploy:
  commands:
    - helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
1 Like