mesg-foundation / engine

Build apps or autonomous workflows with reusable, shareable integrations connecting any service, app, blockchain or decentralized network.
https://mesg.com/
Apache License 2.0
130 stars 13 forks source link

Generate better tag for service build #180

Closed NicolasMahe closed 6 years ago

NicolasMahe commented 6 years ago

Proposal

When building service image with the cmd, we should generate a unique tag that include a hash of the service, the mesg/service- prefix and the name of the service. Then this tag should be either injected in the mesg.yml or at least in the struct of the service before starting it. Maybe this tag can be inject in a .mesg file and in the mesg.yml add a reference. We should also manage the version of the tag.

Solution

Inject image tag in a .mesg file. Use a special variable/keywork to reference the tag in the mesg.yml Automatic 'replacement' when reading the mesg.yml with the value in the .mesg.

mesg.yml:

name: function
description: execute a function
tasks:
....
dependencies:
  function:
    image: MESG_IMAGE
    volumeFrom: ethereum
  ethereum:
    image: geth/geth

.mesg

MESG_IMAGE: mesg/service-function-5c7f199c-6547-11e8-adc0-fa7ae01bbebc

Service struct after reading the mesg.yml and .mesg:

service.Dependencies = map[string]*s.Dependency{
    "function": &s.Dependency{
        Image: "mesg/service-function-5c7f199c-6547-11e8-adc0-fa7ae01bbebc",
        VolumeFrom: "ethereum",
    "ethereum": &s.Dependency{
        Image: "geth/geth",
    },
}
NicolasMahe commented 6 years ago

@antho1404 We should prioritize this issue as its a breaking change for services. Once done, I think we could release the v1.0.0

NicolasMahe commented 6 years ago

I think we could use directly the id of the image to start the service:

sha256:aeec6785cdcbf58c637b8381b291abdd103f015ecc54bba8bc5ffb393fabba62

So we don't even have to tag image.

NicolasMahe commented 6 years ago

Maybe we don't even need to store the tag of the image in the .mesg. If the image is the same, docker should build with the same image id.

antho1404 commented 6 years ago

My idea was really to inject this directly and the user don't have to put anything in the mesg.yml. Of course we still need to be able to add extra dependencies or be able to customize the service dependency so i was thinking of something like that

name: 'xxx'
configuration:
  volumesfrom:
      - ethereum
dependencies:
  ethereum:
    image: ethereum/client-go
    volumes:
      - /root/.ethereum
    command: --syncmode=light

and this will generate a service with the equivalent details

name: 'xxx'
dependencies:
  service:
    image: sha256:....
    volumesfrom:
      - ethereum
  ethereum:
    image: ethereum/client-go
    volumes:
      - /root/.ethereum
    command: --syncmode=light

like that we keep the dependencies and we can inject the image but still have the possibility to customize everything if we want to but if it's a simple service we have nothing to do about dependencies or configurations

The only problem with this solution is that it is not a direct binding between the data in the database and the service file but for now we don't even plan to go from the database to a yml file so I don't think it's a problem and if it is there is simple ways to fix that.