[Docker] Miscellaneous improvements

* Install exact versions of redis/memcached/node
* Use multistage for js packages/ruby gems
* Replace shoreman with foreman
This commit is contained in:
Earlopain 2022-12-13 15:50:37 +01:00
parent 34bcb27482
commit 057a67a168
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
3 changed files with 43 additions and 25 deletions

View File

@ -1,9 +1,29 @@
FROM ruby:3.1.3-alpine3.17 as ruby-builder
RUN apk --no-cache add build-base git glib-dev postgresql12-dev
COPY Gemfile Gemfile.lock ./
RUN gem i bundler:2.3.12 foreman && BUNDLE_IGNORE_CONFIG=true bundle install -j$(nproc) \
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete
ARG COMPOSE_PROFILES
RUN if [[ $COMPOSE_PROFILES == *"solargraph"* ]]; then \
solargraph download-core && bundle exec yard gems && solargraph bundle; \
fi
FROM node:14-alpine3.17 as node-builder
RUN apk --no-cache add git
WORKDIR /app
COPY package.json yarn.lock ./
RUN corepack enable && corepack prepare --activate && yarn install
FROM ruby:3.1.3-alpine3.17
# Dependencies for setup and runtime
RUN apk --no-cache add nodejs yarn ffmpeg vips \
postgresql12-client postgresql12-dev \
bash build-base git glib-dev jemalloc tzdata
RUN apk --no-cache add ffmpeg vips \
postgresql12-client \
git jemalloc tzdata
WORKDIR /app
@ -11,26 +31,23 @@ RUN git config --global --add safe.directory $(pwd)
ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
# Install js packages and gems
COPY package.json yarn.lock ./
RUN yarn install
# Setup node and yarn
COPY --from=node-builder /usr/lib /usr/lib
COPY --from=node-builder /usr/local/share /usr/local/share
COPY --from=node-builder /usr/local/lib /usr/local/lib
COPY --from=node-builder /usr/local/include /usr/local/include
COPY --from=node-builder /usr/local/bin /usr/local/bin
COPY --from=node-builder /root/.cache/node /root/.cache/node
COPY Gemfile Gemfile.lock ./
RUN gem install bundler:2.3.12 && \
bundle install -j$(nproc)
# Copy gems and js packages
COPY --from=node-builder /app/node_modules node_modules
COPY --from=ruby-builder /usr/local/bundle /usr/local/bundle
# shoreman
RUN wget -O /usr/bin/shoreman https://github.com/chrismytton/shoreman/raw/master/shoreman.sh \
&& chmod +x /usr/bin/shoreman
# Only setup solargraph stuff when the profile is selected
ARG COMPOSE_PROFILES
RUN if [[ $COMPOSE_PROFILES == *"solargraph"* ]]; then \
solargraph download-core && bundle exec yard gems && solargraph bundle; \
fi
# Solargraph
COPY --from=ruby-builder /usr/local/lib/ruby/gems/3.1.0/doc /usr/local/lib/ruby/gems/3.1.0/doc
COPY --from=ruby-builder /root/.solargrap[h] /root/.solargraph
# Stop bin/rails console from offering autocomplete
RUN echo "IRB.conf[:USE_AUTOCOMPLETE] = false" > ~/.irbrc
CMD [ "shoreman" ]
CMD ["foreman", "start"]

View File

@ -69,13 +69,13 @@ services:
- "34517:5432"
redis:
image: redis:alpine
image: redis:4.0.9-alpine
command: redis-server --save 10 1 --loglevel warning
volumes:
- redis_data:/data
- redis_data_v2:/data
memcached:
image: memcached:alpine
image: memcached:1.5.6-alpine
elastic:
image: elasticsearch:7.14.2
@ -150,7 +150,7 @@ volumes:
iqdb_data:
elastic_data:
db_data:
redis_data:
redis_data_v2:
node_modules:
public_packs:
public_packs_test:

View File

@ -1,5 +1,6 @@
{
"name": "app",
"packageManager": "yarn@1.22.19",
"private": true,
"dependencies": {
"@rails/webpacker": "^6.0.0-rc.5",