Exemple #1
0
func upLocalDockerPg() error {
	conn := createPgConn()
	containerName := flagUpContainerName

	if err := lib.EnsureDockerWorking(); err != nil {
		return err
	}

	if !lib.IsContainerExist(containerName) {
		if err := lib.RunContainer(containerName, []string{
			"-e", fmt.Sprintf("POSTGRES_USER=%s", conn.Username),
			"-e", fmt.Sprintf("POSTGRES_PASSWORD=%s", conn.Password),
			"-p", fmt.Sprintf("%d:5432", conn.Port),
			"-d",
		}, flagImageName); err != nil {
			return err
		}
		fmt.Println("Running container " + containerName)
	} else {
		fmt.Println("Container " + containerName + " is already running.")
	}

	if err := lib.TryPgConnection(conn, flagPollDbAttempt); err != nil {
		return err
	}

	fmt.Println(fmt.Sprintf("%s:%d is ready to use!", conn.Host, conn.Port))

	return nil
}
Exemple #2
0
func downLocalDockerPg() error {
	containerName := flagDownContainerName

	if err := lib.EnsureDockerWorking(); err != nil {
		return err
	}

	if lib.IsContainerExist(containerName) {
		if err := lib.RemoveContainer(containerName); err != nil {
			return err
		}
		fmt.Println("Removed container " + containerName)
	} else {
		fmt.Println("Container " + containerName + " is not running. No action required.")
	}

	return nil
}