Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom services #415

Open
uwej711 opened this issue Feb 21, 2023 · 7 comments
Open

Adding custom services #415

uwej711 opened this issue Feb 21, 2023 · 7 comments

Comments

@uwej711
Copy link

uwej711 commented Feb 21, 2023

What is the problem you are trying to solve by the feature?

For our local development I would like to have the possibility to add custom services to simplify development. These are basically mocks for real services used in other environments. Adding them to the docker environment would allow us to easily make this available to all developers on the team.

What is the solution do you propose?

You should be able to add new services to the deploy.*.yml files and docker/sdk boot should be able to add them to the deployment. From what I've seen so far, the main change would be to add not only the deploy.yml from the project directory but also the needed templates. For our concrete case that would be a "mockservice.yml.twig" (for docker-compose.yml) and a "mockservice.server.conf.twig" for the gateway configuration.

These files could be placed in some folder at the project level, copied to the generator temp dir and this path added to the twig environment.

What changes in deploy.yml format do you propose?

No extra changes to the format necessary.

What changes in command line interface do you propose?

No changes for the cli necessary

What alternatives have you considered?

I added the files locally to the docker-sdk src and it works.

PR

If there is a change for this change to be accepted as a PR I can try to prepare one.

@alexanderM91
Copy link
Collaborator

Hi @uwej711,

I believe Docker/SDK provides required feature OOTB.
You could extend the default functionality via custom docker-compose file:

Like an example:
deploy.yml

docker:
  compose:
    yamls:
      - docker-compose.custom.yml

docker-compose.custom.yml

version: 3.7

services:

  my-custom-service:
      image:....

https://docs.docker.com/compose/extends/

I hope it will be helpful and have a great evening.

@uwej711
Copy link
Author

uwej711 commented Feb 22, 2023

@alexanderM91 I tried what you suggested but it does not work. See the linked PR for a solution that allows what I want to achieve.

@alexanderM91
Copy link
Collaborator

alexanderM91 commented Feb 23, 2023

Hi @uwej711, could you please answer for several small questions?
How we fix an issue just with a new folder?
Why cannot we reuse deploy-templates for storing necessary service templates?

@uwej711
Copy link
Author

uwej711 commented Feb 23, 2023

Of course those can be placed in the same folder. But we still have to add the folder to the Twig ChainLoader, see my PR. I can easily adjust that.

@uwej711
Copy link
Author

uwej711 commented Feb 23, 2023

PR updated

@alexanderM91
Copy link
Collaborator

Hi @uwej711, thanks a lot for your contribution.
It would be great if you could provide us the examples of the configuration you did.

Thank you.

@uwej711
Copy link
Author

uwej711 commented Feb 27, 2023

No problem. I added the following content to config/deploy-templates/service/mockservices/default/mockservices.yml.twig:

  {{ serviceName }}:
    build:
      context: ./mockservices
    networks:
      - private
      - public
    labels:
      'spryker.app.name': mockservices
      'spryker.app.type': hidden
      'spryker.project': ${SPRYKER_DOCKER_PREFIX}:${SPRYKER_DOCKER_TAG}
    healthcheck:
      test: [ "CMD", "nc", "-z", "localhost", "8008" ]
      interval: 5s
      timeout: 5s
      retries: 5
    volumes:
{% include "application-volumes.yml.twig" with project %}

and the following to config/deploy-templates/nginx/http/gateway/mockservices.server.conf.twig:

{% extends "nginx/http/gateway/server.conf.twig" %}
{% block upstream %}{{ upstream }}:8008{% endblock upstream %}

Finally the following was added to deploy.yml:

services:
    mockservices:
        engine: mockservices
        endpoints:
          services.spryker.local:

There is a Dockerfile in the mockservices directory that builds a tiny flask app for developing locally ...

Now after docker/sdk boot and docker/sdk up I have my flask app running and available at services.spryker.local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants