docker: avoid rebuilding CSS/JS assets on every commit.
Restructure the Dockerfile and the CSS/JS files so that we only rebuild the CSS and JS when they change, not on every commit. Before it took several minutes to rebuild the Docker image after every commit, even when the JS/CSS files didn't change. This also made pulling images slower. This requires refactoring the CSS and JS to not use embedded Ruby (ERB) templates, since this made the CSS and JS dependent on the Ruby codebase, which is why we had to rebuild the assets after every Ruby change.
This commit is contained in:
@@ -35,32 +35,37 @@ RUN \
|
||||
rm -rf "$(gem environment gemdir)/cache" && \
|
||||
find "$(gem environment gemdir)" -name "*.o" -delete
|
||||
|
||||
COPY .yarn package.json yarn.lock ./
|
||||
COPY .yarnrc.yml package.json yarn.lock ./
|
||||
COPY .yarn/ ./.yarn/
|
||||
RUN yarn install
|
||||
|
||||
COPY . .
|
||||
|
||||
ARG SOURCE_COMMIT
|
||||
RUN echo "$SOURCE_COMMIT" > REVISION
|
||||
|
||||
|
||||
|
||||
FROM development AS assets
|
||||
COPY postcss.config.js Rakefile ./
|
||||
COPY bin/rails bin/webpack ./bin/
|
||||
COPY config/application.rb config/boot.rb config/danbooru_default_config.rb config/webpacker.yml ./config/
|
||||
COPY config/webpack/ ./config/webpack/
|
||||
COPY public/images ./public/images
|
||||
COPY public/fonts ./public/fonts
|
||||
COPY app/components/ ./app/components/
|
||||
COPY app/javascript/ ./app/javascript/
|
||||
|
||||
RUN \
|
||||
bin/rails assets:precompile && \
|
||||
rm -rf \
|
||||
node_modules .yarn/cache tmp /usr/local/share/.cache/yarn \
|
||||
/root/.yarn/berry/cache /root/.bundle/cache /root/.npm && \
|
||||
asdf uninstall nodejs && \
|
||||
ln -s /tmp tmp
|
||||
ln -s /tmp tmp && \
|
||||
ln -s packs public/packs-test
|
||||
|
||||
|
||||
|
||||
FROM base as production
|
||||
|
||||
COPY --from=development /root /root
|
||||
COPY --from=assets /danbooru /danbooru
|
||||
COPY --from=development /danbooru /danbooru
|
||||
|
||||
COPY . .
|
||||
ARG SOURCE_COMMIT
|
||||
RUN echo "$SOURCE_COMMIT" > REVISION
|
||||
|
||||
USER danbooru
|
||||
ENTRYPOINT ["tini", "--"]
|
||||
|
||||
Reference in New Issue
Block a user