Created
September 28, 2020 15:34
-
-
Save mazaira/9d09e0bdf617088ef2a42fca437b60e1 to your computer and use it in GitHub Desktop.
Docker config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker compose | |
``` | |
version: "3.0" | |
services: | |
redis: | |
image: redis:alpine | |
restart: unless-stopped | |
ports: | |
- "6379:6379" | |
expose: | |
- "6379" | |
volumes: | |
- $PWD/redis-data:/var/lib/redis | |
- $PWD/redis.conf:/usr/local/etc/redis/redis.conf | |
environment: | |
- 'API_PORT=6379' | |
- 'NODE_ENV=production' | |
db: | |
image: postgres:11 | |
ports: | |
- 5432:5432 | |
environment: | |
POSTGRES_PASSWORD: '123456' | |
webpacker: | |
image: counter-server | |
command: ["./scripts/start_webpack_dev.sh"] | |
volumes: | |
- .:/opt/counter_server:cached | |
ports: | |
- 3035:3035 | |
web: | |
image: counter-server | |
env_file: | |
- ./.env.docker | |
build: | |
context: . | |
args: | |
precompileassets: "not" | |
command: web | |
links: | |
- db | |
- webpacker | |
ports: | |
- 3000:3000 | |
volumes: | |
- .:/opt/counter_server:cached | |
crontab: | |
image: counter-server | |
env_file: | |
- ./.env.docker | |
command: cron_jobs | |
djs: | |
image: counter-server | |
env_file: | |
- ./.env.docker | |
command: delayed_jobs | |
``` | |
Dockerfile | |
``` | |
FROM ruby:2.7.1-slim | |
ARG precompileassets | |
RUN apt-get update && apt-get install -y curl gnupg | |
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list | |
RUN curl -q https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | |
RUN apt-get -y update && \ | |
apt-get install --fix-missing --no-install-recommends -qq -y \ | |
build-essential \ | |
vim \ | |
wget gnupg \ | |
git-all \ | |
curl \ | |
cron \ | |
ssh \ | |
postgresql-client-11 libpq5 libpq-dev -y && \ | |
wget -qO- https://deb.nodesource.com/setup_12.x | bash - && \ | |
apt-get install -y nodejs && \ | |
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ | |
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ | |
apt-get update && \ | |
apt-get install yarn && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
RUN gem install bundler -v 2.1.4 | |
#Install gems | |
RUN mkdir /gems | |
WORKDIR /gems | |
COPY Gemfile . | |
COPY Gemfile.lock . | |
RUN bundle install | |
COPY config/webpacker.docker.yml config/webpacker.yml | |
ARG INSTALL_PATH=/opt/counter-server | |
ENV INSTALL_PATH $INSTALL_PATH | |
WORKDIR $INSTALL_PATH | |
COPY ./entrypoint.sh / | |
ENTRYPOINT ["/entrypoint.sh"] | |
COPY . . | |
RUN scripts/potential_asset_precompile.sh $precompileassets | |
EXPOSE 3000 | |
``` | |
entrypoint | |
``` | |
#!/bin/sh | |
rm -f tmp/pids/server.pid | |
set -e | |
case $1 in | |
web) | |
exec su -s /bin/sh -c "bundle exec rails server -b 0.0.0.0" | |
;; | |
migrations) | |
exec su -s /bin/sh -c "bundle exec rake db:migrate" | |
;; | |
delayed_jobs) | |
exec su -s /bin/sh -c "bundle exec sidekiq" | |
;; | |
cron_jobs) | |
bundle exec whenever --update-crontab && cron -f | |
;; | |
*) | |
exec "$@" | |
;; | |
esac | |
exit 0 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment