Hi all,
I’m using circleci with docker-compose to run integration tests between several services. We use environment variables for configuration, which works great with the hosted version of circleci. We’re using the setup_remote_docker option and then using docker-compose to launch all of the project’s services.
The problem is that with the circleci CLI the containers for our services can’t access the environment variables, causing them to crash before any tests run. I’ve tried using the -e ENV=ENV
flag with the CLI, but even those environment variables aren’t passed to the containers running the service. Using the -e
flag also isn’t a great option since we have half a dozen variables that need to be set, but I suppose we could write a script as a workaround if need be.
Using the CLI, how can I pass environment variables into docker containers launched within circleci’s base container? This works fine with the online version, but I’m not having any luck with the local version.
Here’s a copy of my config file in case that’s useful
version: 2 # CircleCI version
jobs:
build-and-test:
docker:
- image: circleci/python:3.7.3
working_directory: ~/my_project
steps:
- setup_remote_docker
- checkout
- run:
name: Workaround for circleci CLI on macOS / linux
command: |
if [[ $CIRCLE_SHELL_ENV == *"localbuild"* ]]; then
echo "This is a local build. Enabling sudo for docker."
echo sudo > ~/sudo
else
echo "This is not a local build. Disabling sudo for docker."
touch ~/sudo
fi
- run:
name: Run service_a, service_b, and service_c using docker-compose
command: |
eval `cat ~/sudo` docker-compose -f docker-compose-circleci.yml \
up -d --build service_a service_b service_c
- run:
name: Run Tests
command: |
eval `cat ~/sudo` docker exec -it \
service_a_container pytest -v my_project
workflows:
version: 2
run-tests:
jobs:
- build-and-test