diff --git a/.dockerignore b/.dockerignore index 988ad1273..8d0b3809a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -20,3 +20,7 @@ node_modules/ docker/ coverage/ pkg/ + +# Allow v1.0.0 files from tmp in docker +!tmp/Gemfile_v1.lock +!tmp/version_v1.rb diff --git a/docker/Dockerfile b/docker/Dockerfile index ce05e5e3b..5a94eedc5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -26,12 +26,16 @@ ENV BUNDLE_WITHOUT=development:test WORKDIR /avo/ -# gems -COPY Gemfile* /avo/ +# Install gems +COPY Gemfile /avo/Gemfile COPY Rakefile /avo/ COPY avo.gemspec /avo/ COPY ./lib/avo.rb /avo/lib/avo.rb -COPY ./lib/avo/version.rb /avo/lib/avo/version.rb +RUN mkdir /avo/lib/avo + +# Cache the bundle install command with a fake version +COPY ./tmp/Gemfile_v1.lock /avo/Gemfile.lock +COPY ./tmp/version_v1.rb /avo/lib/avo/version.rb RUN bundle install --jobs 4 --retry 3 COPY package.json /avo/ @@ -40,6 +44,10 @@ COPY yarn.lock /avo/ RUN yarn install RUN yarn check --integrity +# re-run bundle install with the appropriate version number +COPY ./lib/avo/version.rb /avo/lib/avo/version.rb +RUN bundle install --jobs 4 --retry 3 + COPY ./bin/ /avo/bin/ COPY ./app/packs/ /avo/app/packs/ COPY ./config/ /avo/config/ @@ -50,7 +58,7 @@ COPY ./tailwind.config.js /avo/tailwind.config.js COPY ./babel.config.js /avo/babel.config.js # Copy the files needed by PurgeCSS -COPY . /avo/ +COPY . /avo # Remove webpacker.yml config files RUN rm /avo/config/webpacker.yml diff --git a/scripts/build.sh b/scripts/build.sh index f65b26549..f798330b5 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,6 +4,13 @@ set -e VERSION=$(bundle exec rails runner 'puts Avo::VERSION') +# Create v1.0.0 versions of the Gemfile and version file for better caching on the docker layer +cp ./Gemfile.lock ./tmp/Gemfile_v1.lock +sed -i '' 's/avo \(.*\)/avo (1.0.0)/' ./tmp/Gemfile_v1.lock +cp ./lib/avo/version.rb ./tmp/version_v1.rb +sed -i '' 's/VERSION = ".*"/VERSION = "1.0.0"/' ./tmp/version_v1.rb + + docker build -t avo-build -f docker/Dockerfile . IMAGE_ID=$(docker create avo-build) rm -f ./pkg/latest-avo.gem