skip to Main Content

I’m quite new to ArangoDB and I have a requirement to spin off a docker container for ArangoDB, while executing a GO code. The limitation is that the module that enables the spin-off (testcontainers) takes in some parameters for the env settings of the docker container, maybe for the optimal utilisation of resources (For Ex. 1gb for JVM in the case of "ES_JAVA_OPTS" to spin off an Elasticsearch container).

Please let me know what these env settings could be for an Arango docker container (possibly standalone image instead of a cluster one), and how to go about setting them optimally for the spin off to actually happen at run time.

2

Answers


  1. I would suggest to use docker compose and setup different containers for running Arango and another one for running the GO code. That way you can have different env settings for each of them. Below you can see a sample docker-compose.yml file that has Arano, GO and redis. I am adding Redis to show you that you can add even more services there if needed

    version: '3.9'
    
    # Define services
    services:
    
      arangodb:
          image: arangodb/arangodb:latest
          ports:      
            - 8529:8529
          volumes:
            - /my/database/copy/for/arango/data:/var/lib/arangodb3
          environment:
            - ARANGODB_USERNAME=myuser
            - ARANGODB_PASSWORD=mypassword
            - ARANGODB_DBNAME=graphdb
            - ARANGO_ROOT_PASSWORD=myrootpassword
          container_name: "arango_docker_compose"
          mem_limit: 2048m
          networks:
          - backend
    
       # Golang Service
      app:
        # Building the docker image for the service based on a Dockerfile of your choice
        build:
          context: . # Use an image built from the specified dockerfile in the current directory.
          dockerfile: Dockerfile
        ports:
          - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine, if needed
        restart: unless-stopped
        depends_on: 
          - redis # This service depends on redis and arangodb. Start them first.
          - arangodb
        environment: # Pass environment variables to the service
          - REDIS_URL: redis:6379    
          - ARANGO_PORT: 8529
        networks: # Networks to join (Services on the same network can communicate with each other using their name)
          - backend
    
      # Redis Service   
      redis:
        image: "redis:alpine" # Use a public Redis image to build the redis service    
        restart: unless-stopped
        networks:
          - backend
    
    networks:
      backend:  
    

    For more information about the parameters allowed on ArangoDB docker image please see ArangoDB docker hub

    A sample Dockerfile for GO container can be found at here. Please bare in mind that these files are mere samples and you will need to add/replace your required configuration on them. As you want to use testcontainers you can also use the Dockerfile here

    Please let me know whether that helps

    Thank you!

    Login or Signup to reply.
  2. I was able to reproduce your use case using testcontainers-go. Here you have an snippet bootstrapping the runtime dependencies for your app programatically next to the tests, which imho is closer to the developer than externalizing it to a call to docker-compose, possibly called in a Makefile or similar.

    You would need to add your own app container to the game 😉

    package arangodb
    
    import (
        "context"
        "testing"
    
        "github.com/docker/docker/api/types/container"
        "github.com/stretchr/testify/require"
        "github.com/testcontainers/testcontainers-go"
        "github.com/testcontainers/testcontainers-go/wait"
    )
    
    func TestArangoDB(t *testing.T) {
        ctx := context.Background()
    
        networkName := "backend"
    
        newNetwork, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{
            NetworkRequest: testcontainers.NetworkRequest{
                Name:           networkName,
                CheckDuplicate: true,
            },
        })
        if err != nil {
            t.Fatal(err)
        }
        t.Cleanup(func() {
            require.NoError(t, newNetwork.Remove(ctx))
        })
    
        arangodb, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
            ContainerRequest: testcontainers.ContainerRequest{
                Image: "arangodb/arangodb:latest",
                Env: map[string]string{
                    "ARANGODB_USERNAME":    "myuser",
                    "ARANGODB_PASSWORD":    "mypassword",
                    "ARANGODB_DBNAME":      "graphdb",
                    "ARANGO_ROOT_PASSWORD": "myrootpassword",
                },
                Networks: []string{networkName},
                Resources: container.Resources{
                    Memory: 2048 * 1024 * 1024, // 2048 MB
                },
                WaitingFor: wait.ForLog("is ready for business"),
                Mounts: testcontainers.ContainerMounts{
                    testcontainers.BindMount("/my/database/copy/for/arango/data", "/var/lib/arangodb3"),
                },
            },
            Started: true,
        })
        require.NoError(t, err)
        defer arangodb.Terminate(ctx)
    
        redis, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
            ContainerRequest: testcontainers.ContainerRequest{
                Image:    "redis:alpine",
                Networks: []string{networkName},
            },
            Started: true,
        })
        require.NoError(t, err)
        defer redis.Terminate(ctx)
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search