micahhausler / container-tx

container-transform in go
MIT License
11 stars 2 forks source link

Support a map for `networks` as well as `string[]` #5

Open TylerRick opened 6 years ago

TylerRick commented 6 years ago

Documented here: https://docs.docker.com/compose/compose-file/#aliases

Example:

⟫ cat docker-compose-network-map.yml
version: '2'
services:
  postgres:
    image: mdillon/postgis:9.5
    networks:
      default:
        aliases:
          - db

Current behavior:

⟫ ./container-tx < docker-compose-network-map.yml
Error ingesting file: yaml: unmarshal errors:
  line 6: cannot unmarshal !!map into []string 

Expected:

I'm guessing something like this (not 100% sure yet):

⟫ ./container-tx < docker-compose-network-map.yml
docker network create projectname_default

######## postgres ########
docker run \
    --name postgres \
    --network projectname_default \
    --network-alias db \
    mdillon/postgis:9.5
TylerRick commented 6 years ago

Looks like this is a problem if you use docker-compose config as the input as well, even if you listed as an array in your file.

If you have this in your file:

    networks:
      - default
      - public

, then docker-compose config apparently normalizes it to this:

    networks:
      default: null
      public: null
micahhausler commented 6 years ago

Yea this is another one of those cases where docker-compose keeps changing (improving?) their format, and it leaves everyone chasing their tail to keep up with it.

One bigger strategy for all this might be ingesting compose's openAPI schema definitions and searching for all the fields with a schema of oneOf, and then appropriately parsing each case