Env variables break docker build cache with setup_remote_docker

docker
caching
cache
cci-20

#1

I am building a docker service in the CircleCI 2.0 remote Docker environment. Here is my config.yml:

version: 2
jobs:
  build:
    docker:
      - image: diverse/docker-compose-aws
      - image: circleci/python:3.6
    steps:
      - checkout
      - setup_remote_docker:
          reusable: true # I have asked CircleCI to turn on this feature for me
      - run: docker-compose build my-service

Here is my DockerFile:

FROM python:3

# Setup environment.
EXPOSE 80
WORKDIR /work
ENTRYPOINT ["./entrypoint.sh"]
CMD ["uwsgi", "--protocol=http", "--socket", "0.0.0.0:80", "-w", "bob_emploi.frontend.server:app"]
ARG GIT_SHA1=non-git
ENV PROTOBUF_VERSION=3.2.0 \
  BIND_HOST=0.0.0.0 \
  PYTHONPATH='/work'

RUN apt-get update -qqy
RUN apt-get install -qqy --no-install-recommends wget unzip
RUN pip install python-emploi-store flask mailjet_rest mongo oauth2client pyfarmhash unidecode uwsgi xmltodict
etc...

All the steps in docker-compose build my-service are correctly cached until I set the ENV vars, but it breaks after:

Step 7/21 : ENV PROTOBUF_VERSION 3.2.0 BIND_HOST 0.0.0.0 PYTHONPATH /work
 ---> Using cache
 ---> a0923d88cf85
Step 8/21 : RUN apt-get update -qqy
 ---> Running in c6f86d432cd2
 ---> ee3f1177e0ee
Removing intermediate container c6f86d432cd2

However this building step is correctly cached when I run it on my mac:

Step 7/21 : ENV PROTOBUF_VERSION 3.2.0 BIND_HOST 0.0.0.0 PYTHONPATH /work
 ---> Using cache
 ---> 7c7c8fa1cbf4
Step 8/21 : RUN apt-get update -qqy
 ---> Using cache
 ---> 001fc53b9267

How can I fix this?


#2

I’m facing the same issue on Circle 2.0, my cache stops being used after line ENV INSTALL_PATH /api. The problem does not seem to come from ENV since I tried to hardcode the ENV variable (/api path) into the dockerfile. Any ideas where this might come from ?

FROM ruby:2.4.2

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

# wkhtmltox installation
RUN apt-get install -y wget libfontenc1 libxfont1 xfonts-75dpi xfonts-base xfonts-encodings xfonts-utils rsync
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN tar xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
RUN rsync -a wkhtmltox/ /usr/local/

ENV INSTALL_PATH /api

RUN mkdir $INSTALL_PATH
WORKDIR $INSTALL_PATH

COPY Gemfile* $INSTALL_PATH/
RUN bundle install

etc...

#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.