Network between two cloud build builder containers

287 views
Skip to first unread message

Mark Petronic

unread,
Oct 29, 2021, 4:09:29 PM10/29/21
to Google Cloud Developers
I am trying to run my Go app's integration test in cloudbuild. Part of this testing requires my app-under-test to write to and read from Redis. My approach to do this was to start up a custom-build container in STEP-1 that runs redis-server in the foreground using this for the step args with a bash entrypoint:

"docker run -d -e ENV_A=123 -e ENV_b=456 my-custom-redis-image"

Using -d ensures it runs detached allowing that build step to complete but leaving Redis up and listening for connection. Redis is configured to listen on 0.0.0.0:6379. Then, in say STEP-2, I want to compile my Go app integration tests and run them as follows using the golang:1.16.4 builder container:

go test -tags=integration ./...

When that test runs, it will create a Redis client that want to connect to the running Redis instance from STEP-1. However, I do not know what IP to configure in my client that can reach the Redis instance running in the STEP-1. I understand that there is a "cloudbuild" network that is used in cloudbuild for all the docker instances. My confusion is how to configure my client to talk to Redis in another running container. It is even possible? 

If not, how do you handle test dependencies like this where tests needs N external services to work. I have unit tests and they work fine because, unit tests do not have any external dependencies. However, my integration test needs to not only use Redis, but also have to connect to GCS, Pub/Sub, and BQ to complete various test scenarios and these test are much more black box like as compared to unit tests. So, they want to talk to the real services and not mocks or fakes.

Appreciate any guidance on this.


gorbov

unread,
Oct 29, 2021, 7:03:12 PM10/29/21
to Google Cloud Developers
Hi Mark,

From my understanding, you are trying to run integration tests with your Go application and a Redis instance, and you want the different contains in each build steps to talk to each other.

I found this SO article from the community, that you might find helpful [1] . As mentioned in that article you can add the following to your docker-compose.yaml:

networks: 
    default: 
        external: 
            name: cloudbuild

According to the documentation [2], the IP address of the Redis instance will be on the local docket network, so it would be '127.0.0.1' and the port is the one you defined in your `docker-compose.yaml` . (Example port: 6379). Once you have the IP and host of the Redis instance, it's just a matter of making putting them into your client application environment variables and retrieving them to make calls.

You can check out and base yourself off of this GitHub repository which has code that seems to be very similar to what you are trying to achieve [3] . Please checkout the 'docker-compose.yaml' , 'cloudbuild.yaml' and 'main.js' files. Perhaps you can adapt the code to Go . I hope you find these suggestions helpful.


Reply all
Reply to author
Forward
0 new messages