Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the docker env #873

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
FROM ruby:2.7.8

ARG USER_ID=1000
ARG GROUP_ID=1000

ENV DEBIAN_FRONTEND noninteractive
ENV NODE_VERSION=16.20.0

RUN sed -i '/deb-src/d' /etc/apt/sources.list && \
apt-get update
ENV BUNDLER_VERSION 2.4.13
ENV NODE_VERSION 16.20.0
ENV YARN_VERSION 1.22.19

ENV BUNDLE_PATH /bundle
ENV BUNDLE_BIN /bundle/bin
ENV GEM_HOME /bundle
ENV PATH "${BUNDLE_BIN}:${PATH}"

RUN apt-get install -y build-essential postgresql-client
RUN gem install bundler
RUN curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | tar xfJ - -C /usr/local --strip-components=1
RUN npm install --global --unsafe-perm yarn
RUN sed -i '/deb-src/d' /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y build-essential postgresql-client \
&& gem install bundler -v ${BUNDLER_VERSION} \
&& groupadd --gid ${GROUP_ID} app \
&& useradd --system --create-home --no-log-init --uid ${USER_ID} --gid ${GROUP_ID} --groups sudo app \
&& mkdir /var/app && chown -R app:app /var/app \
&& echo "app ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R app:app $BUNDLE_PATH

# Install chrome and chromedriver for integration tests
ENV CHROME_VERSION 106.0.5249.61
RUN wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb \
&& dpkg -i google-chrome-stable_${CHROME_VERSION}-1_amd64.deb || true \
Expand All @@ -20,12 +34,17 @@ RUN wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/
&& unzip chromedriver_linux64.zip -d /usr/local/bin \
&& rm chromedriver_linux64.zip

WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
COPY yarn.lock yarn.lock
COPY .env.sample .env
USER app

RUN bundle install
# Install node for app user
ENV NVM_DIR /home/app/.nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
&& . ~/.nvm/nvm.sh \
&& nvm install ${NODE_VERSION} \
&& nvm alias default ${NODE_VERSION} \
&& nvm use default \
&& npm install -g yarn@${YARN_VERSION}
ENV NODE_PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/lib/node_modules
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:${PATH}

WORKDIR /app
WORKDIR /var/app
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Or using docker:
# Prepare container
$ docker compose build
$ docker compose run --rm web yarn install
$ docker compose run --rm web bundle install
$ docker compose run --rm web bundle exec rake db:create
$ docker compose run --rm web bundle exec rake db:migrate
$ docker compose run --rm web bundle exec rake db:seed
Expand Down
85 changes: 41 additions & 44 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
version: '2.4'

services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro

postgres:
image: postgres:14.2
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=postgres
expose:
- '5432'

redis:
image: redis:6.2
expose:
- "6379"
volumes:
- redis:/data

web:
build: .
app: &app
build:
context: .
args:
USER_ID: ${USER_ID:-1000}
GROUP_ID: ${GROUP_ID:-1000}
environment:
MAIN_HOST: "localhost:3000"
DB_USERNAME: 'postgres'
Expand All @@ -41,34 +22,49 @@ services:
ports:
- 3000
volumes:
- .:/app
- ./node_modules:/app/node_modules
- .:/var/app
- bundle_cache:/bundle
command: echo "off by default"

web:
<<: *app
ports:
- "3000:3000"
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"

worker:
build: .
environment:
DB_USERNAME: 'postgres'
DB_PASSWORD: 'postgres'
DB_HOST: 'postgres'
REDISCLOUD_URL: 'redis://redis:6379/0'
MEMCACHIER_SERVERS: memcached:11211
depends_on:
- postgres
- redis
volumes:
- .:/app
<<: *app
command: sidekiq

vite:
build: .
<<: *app
ports:
- "3036:3036"
volumes:
- .:/app
- ./node_modules:/app/node_modules
command: sh -c "bundle binstubs bundler --force && ruby ./bin/vite dev"

nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro

postgres:
image: postgres:14.2
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=postgres
expose:
- '5432'

redis:
image: redis:6.2
expose:
- "6379"
volumes:
- redis:/data

adminer:
image: adminer:4.8.1
environment:
Expand All @@ -78,6 +74,7 @@ services:
image: memcached

volumes:
bundle_cache:
db:
redis:
node_modules:
redis:
Loading