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

Service Templating #761

Closed
gak opened this issue Dec 30, 2014 · 5 comments
Closed

Service Templating #761

gak opened this issue Dec 30, 2014 · 5 comments

Comments

@gak
Copy link

gak commented Dec 30, 2014

I need a feature where you can override a service with another. I've started the implementation and will create a pull request once I have a good set of tests done.

Here are the details:

Allows the ability to have templates, where your fig.yml can override another
service, optionally in another file (e.g. template.yml).

template can either be a string or dictionary.

When template is a string, it specifies the path to the template, where the
same service name will be used.

When template is a dictionary, you may specify path and service as the
keys. path is the path to the template and service is the name of the
service to override in the specified template. path or service may be
omitted defaulting to the same template file, or same service name.

For example, this would use busybox:latest with the command /bin/bash (same as the other examples below):

fig.yml

myservice:
  template: template.yml
  command: /bin/bash

template.yml

myservice:
  image: busybox:latest
  command: /bin/sleep 10

Another example, this one runs in a single file:

fig.yml

template_service:
  image: busybox:latest
  command: /bin/sleep 10
myservice:
  command: /bin/bash
  template:
    service: template_service

A final example, referencing another file and service:

fig.yml

myservice:
  template:
    path: template.yml
    service: template_service
  command: /bin/bash

template.yml

template_service:
  image: busybox:latest
  command: /bin/sleep 10

I made a choice to have the "string" point to a template file rather than a service name (in the same file), only because that's how I plan to structure my fig files, so it was more appropriate as a default for my project.

@dnephin
Copy link

dnephin commented Dec 30, 2014

Could you provide some more context about the problem this is solving? Why would this template be used?

@gak
Copy link
Author

gak commented Dec 30, 2014

My initial problem was that I needed a set of docker instances that are used for integration testing, development, and production. They are identical, except the integration testing configuration has docker links to each other, development has ports exposed, and the production configuration has ports exposed plus volumes configured.

I had three fig.yml files that were mostly the same to achieve this and wasn't very happy with the set of non DRY yml files. I started writing code to generate the yml files based on a template, then realised changing fig itself is probably a better solution.

Since then I realised that I've seen and had this problem before with fig (albeit on a smaller scale). e.g. devops creating nearly identical fig.yml files for staging and production, where the base image and hostnames were different, although #76 can solve that using environment variables, a templating system seems like a nicer solution to me since it is more explicit and doesn't need makefiles, etc. to set environment variables for fig.

@gak gak mentioned this issue Jan 1, 2015
@aanand
Copy link

aanand commented Jan 6, 2015

Have you looked at #318 and #758? There seems to be a lot of overlap. How does your proposed solution compare?

@funkyfuture
Copy link

-> #988 may solve your issue.

@gak
Copy link
Author

gak commented Mar 4, 2015

I guess this is a common feature request. :)

I'm not bothering to pursue my patch since my implementation is a very small change, and there are more well thought out variations to it, especially #988. Closing.

@gak gak closed this as completed Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants