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

DockerComposeCompositeService.ExtractNames fails for container names with other format #94

Closed
msdeibel opened this issue Aug 7, 2019 · 5 comments
Assignees
Labels
bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.
Milestone

Comments

@msdeibel
Copy link

msdeibel commented Aug 7, 2019

private static string ExtractNames(Container container, out string project, out string instanceId) fails when called with a container name like kafka.

The result is a ArrayIndexOutOfBoundsException in line 155.

It expects a structure like project_component1_instanceId as name.
Why this structure is expected is not clear from looking at the method itself.
Also this is not a naming convention from Docker.

I do not have a patch since I don't know what the expected behaviour should be in case of a name that deviates from the structure currently expected by the method.

@mariotoffia
Copy link
Owner

mariotoffia commented Aug 7, 2019

Hi what name does docker-compose give your containers?

For example, given this docker-compose.yaml file

version: "3"
services:
    wordpress:
        image: visiblevc/wordpress
        cap_add:
            - SYS_ADMIN
        devices:
            - /dev/fuse
        security_opt:
            - apparmor:unconfined
        ports:
            - 8080:80
            - 443:443
        volumes:
            - ./data:/data
            - ./scripts:/docker-entrypoint-initwp.d
            - ./plugins/skelleftetekniken-contest:/app/wp-content/plugins/skelleftetekniken-contest
        depends_on:
            - db
        links:
            - db
        environment:
            DB_NAME: wordpress
            DB_PASS: root
            PLUGINS: >-
                academic-bloggers-toolkit
                co-authors-plus
                wp-file-manager
                [WP-API]https://github.com/WP-API/WP-API/archive/master.zip
            URL_REPLACE: localhost:8080
            WP_DEBUG: 'true'
            WP_DEBUG_DISPLAY: 'true'
            WP_DEBUG_LOG: 'true'
    db:
        image: mysql:5.7
        volumes:
            - data:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: root
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - 22222:80
volumes:
    data:

docker-compose gives me the following names on the containers.

C:\progs\wordpress\skelleftetekniken>docker-compose up
Creating network "skelleftetekniken_default" with the default driver
Creating skelleftetekniken_phpmyadmin_1 ... done
Creating skelleftetekniken_db_1         ... done
Creating skelleftetekniken_wordpress_1  ... done

where

  • project: skelleftetekniken
  • component: phpadmin, db, wordpress
  • instance: 1,1,1

How are you firing up the containers and what names do they get?

Cheers,
Mario

@mariotoffia mariotoffia self-assigned this Aug 7, 2019
@mariotoffia mariotoffia added bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. labels Aug 7, 2019
@mariotoffia mariotoffia added this to the 3.0.0 milestone Aug 7, 2019
@msdeibel
Copy link
Author

msdeibel commented Aug 7, 2019

With docker-compose.yml

version: '3.5'

services:
  
  # building up the message queue system (zookeeper + kafka)
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    networks:
      - messageBus
    ports:
        - "2181:2181"
    restart: always

  kafkaserver:
    image: wurstmeister/kafka
    container_name: kafka
    networks:
      - messageBus
    ports:
        - 9092:9092
        - 29092:29092
        - 29093:29093
        
    restart: always
    
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181    
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST_DEMOSRV:PLAINTEXT,PLAINTEXT_LOCALHOST:PLAINTEXT
      KAFKA_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_HOST_DEMOSRV://:29092,PLAINTEXT_LOCALHOST://:29093
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST_DEMOSRV://demo01:29092,PLAINTEXT_LOCALHOST://localhost:29093
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
      # overrides the default separator ',' for creating topics
      KAFKA_CREATE_TOPICS_SEPARATOR: "$$'\n'"
      # create topic "Values" that will use log compaction to get rid of older value messages
      KAFKA_CREATE_TOPICS: |
        Values:1:1:compact --config=min.compaction.lag.ms=250 --config=segment.bytes=536870912 --config=segment.ms=10000 --config=retention.ms=10000 --config=min.cleanable.dirty.ratio=0.25 --config=file.delete.delay.ms=0
        Configuration:1:1:delete --config=file.delete.delay.ms=0 --config=retention.bytes=-1 --config=retention.ms=-1
        ProjectDefinition:1:1:delete --config=file.delete.delay.ms=0 --config=retention.bytes=-1 --config=retention.ms=-1
        SetValues:1:1:delete --config=retention.ms=1000 --config=segment.ms=1000 --config=segment.bytes=268435456 --config=min.cleanable.dirty.ratio=0.1 --config=file.delete.delay.ms=0
        Devices:1:1:delete --config=file.delete.delay.ms=0 --config=retention.bytes=-1 --config=retention.ms=-1
        ReadHistoryValues:1:1:delete --config=retention.ms=1000 --config=segment.ms=1000 --config=segment.bytes=268435456 --config=min.cleanable.dirty.ratio=0.1 --config=file.delete.delay.ms=0 
      
      # Enables/disables the possibility to delete a topic (if set to false, the topic will only be marked for deletion but not deleted actually)
      KAFKA_DELETE_TOPIC_ENABLE: "true"

networks:
  default:
    external:
      name: nat
  
  # create network for messaging
  messageBus:
    name: message-bus

and starting up with docker-compose:

PS C:\path\to\docker-compose.yml> docker-compose up
Creating zookeeper ... done
Creating kafka     ... done
Attaching to kafka, zookeeper

I guess the container_name directive overrides the defaults that docker-compose would otherwise give to the containers as in your case.

@mariotoffia mariotoffia added under-development Denotes that a issue is under development but not yet released. bug and removed bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. labels Aug 7, 2019
mariotoffia pushed a commit that referenced this issue Aug 7, 2019
This fix is when the docker-compose specifies a container name explicit and thus do not use the project_service_instanceId pattern. It will use the label instead to dig out the project and instance id (the name will be the set container name).
@mariotoffia
Copy link
Owner

@msdeibel I've fixed the issue using the labels on the containers as fallback when container name is set explicitly. The following unittest now works (with your docker-compose file).

      var file = Path.Combine(Directory.GetCurrentDirectory(),
        (TemplateString) "Resources/ComposeTests/KafkaAndZookeeper/docker-compose.yaml");

      using (var svc = Fd.UseContainer()
        .UseCompose()
        .FromFile(file)
        .Build()
        .Start())
      {
        var kafka = svc.Services.OfType<IContainerService>().Single(x => x.Name == "kafka");
        var zookeeper = svc.Services.OfType<IContainerService>().Single(x => x.Name == "zookeeper");
        Assert.AreEqual("kafkaandzookeeper",kafka.Service);
        Assert.AreEqual("kafkaandzookeeper",zookeeper.Service);
        Assert.AreEqual("1",kafka.InstanceId);
        Assert.AreEqual("1",zookeeper.InstanceId);
      }

Cheers,
Mario

@mariotoffia mariotoffia added waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. and removed under-development Denotes that a issue is under development but not yet released. labels Aug 7, 2019
@mariotoffia
Copy link
Owner

Pushed to nuget 2.7.1 (it will take a while before the packages get indexed).

@msdeibel
Copy link
Author

msdeibel commented Aug 8, 2019

Works like charm with the NuGet 2.7.1 package. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.
Projects
None yet
Development

No branches or pull requests

2 participants