For some integration tests that I'm implementing for a project, I need to pass a location of a file to the Dockerfile, so that I can reuse the same Dockerfile, docker-compose and other build artifacts for several tests. I'm executing the docker command from golang.
func StartContainers(composePath string) error {
cmd := exec.Command("docker-compose", "-f", composePath, "up", "--build", "-d")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
return nil
}
In the Dockerfile, I need to access some value passed by golang command to change the value of ${ENVOY} to use it as the source file.
FROM envoyproxy/envoy:v1.18.3
COPY ${ENVOY} /etc/envoy/envoy.yaml
COPY ./artifacts/cache_filter.wasm /usr/local/bin/cache_filter.wasm
COPY ./artifacts/singleton_service.wasm /usr/local/bin/singleton_service.wasm
COPY ./artifacts/threescale_wasm_auth.wasm /usr/local/bin/threescale_wasm_auth.wasm
RUN chmod go+r /etc/envoy/envoy.yaml /usr/local/bin/cache_filter.wasm /usr/local/bin/singleton_service.wasm
CMD /usr/local/bin/envoy -c /etc/envoy/envoy.yaml -l trace
My docker-compose looks like below.
version: '3.7'
services:
proxy:
build:
context: .
dockerfile: Dockerfile
depends_on:
- backend_service
networks:
- envoymesh
ports:
- "9095:9095"
- "9000:9000"
backend_service:
image: solsson/http-echo
networks:
- envoymesh
environment:
- PORT=8000
networks:
envoymesh: {}
How to pass values from golang command? I referred to several answers on Stackoverflow, but none of them worked for me.