github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/build/docker-compose-generator/main.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"strings"
    10  
    11  	"gopkg.in/yaml.v2"
    12  )
    13  
    14  type DockerCompose struct {
    15  	Version  string                `yaml:"version"`
    16  	Services map[string]*Container `yaml:"services"`
    17  }
    18  
    19  type Container struct {
    20  	Command   string   `yaml:"command,omitempty"`
    21  	Image     string   `yaml:"image,omitempty"`
    22  	Network   []string `yaml:"networks,omitempty"`
    23  	DependsOn []string `yaml:"depends_on,omitempty"`
    24  }
    25  
    26  func main() {
    27  	validServices := map[string]int{
    28  		"mysql":         3306,
    29  		"postgres":      5432,
    30  		"minio":         9000,
    31  		"inbucket":      10080,
    32  		"openldap":      389,
    33  		"elasticsearch": 9200,
    34  		"dejavu":        1358,
    35  		"keycloak":      8080,
    36  		"prometheus":    9090,
    37  		"grafana":       3000,
    38  	}
    39  	command := []string{}
    40  	for _, arg := range os.Args[1:] {
    41  		port, ok := validServices[arg]
    42  		if !ok {
    43  			panic(fmt.Sprintf("Unknown service %s", arg))
    44  		}
    45  		command = append(command, fmt.Sprintf("%s:%d", arg, port))
    46  	}
    47  
    48  	var dockerCompose DockerCompose
    49  	dockerCompose.Version = "2.4"
    50  	dockerCompose.Services = map[string]*Container{}
    51  	dockerCompose.Services["start_dependencies"] = &Container{
    52  		Image:     "mattermost/mattermost-wait-for-dep:latest",
    53  		Network:   []string{"mm-test"},
    54  		DependsOn: os.Args[1:],
    55  		Command:   strings.Join(command, " "),
    56  	}
    57  	resultData, err := yaml.Marshal(dockerCompose)
    58  	if err != nil {
    59  		panic(fmt.Sprintf("Unable to serialize the docker-compose file: %s.", err.Error()))
    60  	}
    61  	fmt.Println(string(resultData))
    62  }