github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/testutil/docker.go (about)

     1  /*
     2   * Copyright 2019 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package testutil
    18  
    19  import (
    20  	"time"
    21  )
    22  
    23  // DockerStart starts the specified services.
    24  func DockerStart(services ...string) error {
    25  	argv := []string{"docker", "start"}
    26  	argv = append(argv, services...)
    27  	err := Exec(argv...)
    28  	time.Sleep(time.Second)
    29  	return err
    30  }
    31  
    32  // DockerStop stops the specified services.
    33  func DockerStop(services ...string) error {
    34  	argv := []string{"docker", "stop"}
    35  	argv = append(argv, services...)
    36  	return Exec(argv...)
    37  }
    38  
    39  // DockerPause pauses the specified services.
    40  func DockerPause(services ...string) error {
    41  	argv := []string{"docker", "pause"}
    42  	argv = append(argv, services...)
    43  	return Exec(argv...)
    44  }
    45  
    46  // DockerUnpause unpauses the specified services.
    47  func DockerUnpause(services ...string) error {
    48  	argv := []string{"docker", "unpause"}
    49  	argv = append(argv, services...)
    50  	err := Exec(argv...)
    51  	time.Sleep(time.Second)
    52  	return err
    53  }
    54  
    55  // DockerCp copies from/to a container. Paths inside a container have the format
    56  // container_name:path.
    57  func DockerCp(srcPath, dstPath string) error {
    58  	argv := []string{"docker", "cp"}
    59  	argv = append(argv, srcPath)
    60  	argv = append(argv, dstPath)
    61  	return Exec(argv...)
    62  }
    63  
    64  // DockerExec executes a command inside the given container.
    65  func DockerExec(container string, cmd ...string) error {
    66  	argv := []string{"docker", "exec", "--user", "root", container}
    67  	argv = append(argv, cmd...)
    68  	return Exec(argv...)
    69  }