Skip to content

Commit

Permalink
Save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Jul 22, 2024
1 parent 93e5f5b commit fe4c8c3
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions testcontainers-c/testcontainers-c-compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,50 @@ import "C"
import (
"context"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"sync"

"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"

uuid "github.com/google/uuid"
"github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/client"
compose "github.com/testcontainers/testcontainers-go/modules/compose"
"github.com/testcontainers/testcontainers-go/wait"
)

var composeGroups []compose.ComposeStack
var composeGroups []*DockerComposeRequest

// FIXME: Copy of compose_api: dockerCompose. Export to public
type DockerComposeContext struct {
stack ComposeStack *
terminator func() error
}

//export tc_new_docker_compose
func tc_new_docker_compose(path *C.cchar_t) (id int, ok bool, errstr *C.char) {
func tc_run_docker_compose(path *C.cchar_t) (id int, ok bool, errstr *C.char) {
composePath := C.GoString(path)
composeInstance, err := compose.NewDockerComposeWith(compose.WithStackFiles(composePath))
if err != nil {
return -1, false, C.CString(fmt.Errorf("Cannot initialize Docker Compose for %q: %w", path, err).Error())
}

composeId := -1
request := DockerComposeContext()
if composeInstance != nil {
terminator := func() error {
return composeInstance.Down(context.Background(), compose.RemoveOrphans(true), compose.RemoveImagesLocal)
}

request.terminator = terminator
stack := composeInstance.Up(ctx, tc.WithRecreate(api.RecreateNever), tc.Wait(true))
composeInstance.stack = &stack;

// We register the container even if the run failed
composeGroups = append(composeGroups, &composeInstance)
composeGroups = append(composeGroups, request)
composeId = len(containers) - 1
}

return composeId, true, nil
}

Expand Down

0 comments on commit fe4c8c3

Please sign in to comment.