As a developer not in a startup, we do not have any proxy to setup. So we use to develop as usual in a beautiful world! But, when deploying for the first time in a particular production environment, we can often have some surprise!
Here my surprise was the squid proxy! Our API is behind a squid proxy…
But how to recreate the environment when coding/testing? Docker-compose is the solution!
Let’s create the docker-compose
version: '2' services: api: container_name: 'my-api' extends: file: ./docker-compose.dev.yml service: api volumes: - ../reports:/app/reports - ../mocks:/app/mocks command: "npm run test" ports: - "3000:3000" environment: NODE_ENV: test http_proxy: http://squid:3128 https_proxy: http://squid:3128 no_proxy: localhost, 127.0.0.1, elasticsearch depends_on: - mongo - elasticsearch - squid networks: - api-network mongo: container_name: 'mongo-test' image: mongo:3.6.4 ports: - "27017:27017" networks: - api-network elasticsearch: container_name: 'es-test' image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0 expose: - "9200" - "9300" networks: - api-network squid: container_name: 'squid-test' image: datadog/squid expose: - 3128 networks: - api-network networks: api-network:
Running this compose file, now I run my tests without changing my env var..