Last active
October 13, 2021 04:46
-
-
Save kfatehi/0156fb380cd5b102bfba981a391316dc to your computer and use it in GitHub Desktop.
Classic Ruby Dockerfile & Docker Compose
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
version: '3.5' | |
services: | |
postgres: | |
image: postgres:11 | |
environment: | |
POSTGRES_USER: example_user | |
POSTGRES_PASSWORD: example_pass | |
POSTGRES_DB: example | |
volumes: | |
- ./postgres-data:/var/lib/postgresql/data | |
ports: | |
- 42001:5432 | |
restart: unless-stopped | |
elasticsearch: | |
image: elasticsearch:5.6.16 | |
environment: | |
- cluster.name=elasticsearch | |
- bootstrap.memory_lock=true | |
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" | |
ulimits: | |
memlock: | |
soft: -1 | |
hard: -1 | |
command: "elasticsearch -E 'http.port=9333' -E 'transport.tcp.port=9200'" | |
ports: | |
- 42002:9333 | |
volumes: | |
- ./elasticsearch-data:/usr/share/elasticsearch/data | |
restart: unless-stopped | |
redis: | |
image: redis | |
ports: | |
- 42003:6379 | |
restart: unless-stopped |
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
FROM ubuntu:20.04 | |
ENV TZ=America/Los_Angeles | |
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | |
RUN useradd -s /usr/bin/bash -d /home/deployer -m deployer | |
RUN mkdir /app | |
RUN chown deployer /app | |
RUN apt-get update && apt-get install -y \ | |
autoconf bison build-essential libssl-dev libyaml-dev \ | |
libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev \ | |
libgdbm6 libgdbm-dev libdb-dev git \ | |
imagemagick libxml2-dev libxslt-dev wget curl \ | |
&& rm -rf /var/lib/apt/lists/* | |
ENV NODE_VERSION v13.12.0 | |
RUN curl -ksSLO https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz && \ | |
tar -C /usr/local --strip-components 1 -xzf node-$NODE_VERSION-linux-x64.tar.gz && \ | |
rm node-$NODE_VERSION-linux-x64.tar.gz | |
# Postgres client | |
RUN cd /usr/src && \ | |
wget https://ftp.postgresql.org/pub/source/v11.12/postgresql-11.12.tar.gz && \ | |
tar xvf postgresql-11.12.tar.gz && \ | |
cd postgresql-11.12 && \ | |
./configure --prefix=/opt/postgresql-11.12 && \ | |
make -j$(nproc) && \ | |
make install | |
# Get Openssl for Ruby | |
RUN cd /usr/src && \ | |
wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz && \ | |
tar -zxvf openssl-1.0.2u.tar.gz && \ | |
cd openssl-1.0.2u && \ | |
./config --prefix=/opt/openssl-1.0 shared && \ | |
make -j$(nproc) && \ | |
make install && \ | |
curl -sSL -o /opt/openssl-1.0/ssl/cert.pem https://curl.se/ca/cacert.pem && \ | |
mkdir -p /usr/share/ca-certificates && \ | |
curl -sSL -o /usr/share/ca-certificates/cacert.pem https://curl.se/ca/cacert.pem | |
# Get Ruby 2.3.8 | |
RUN cd /usr/src && \ | |
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.8.tar.gz && \ | |
tar xvf ruby-2.3.8.tar.gz && \ | |
cd ruby-2.3.8/ && \ | |
./configure --prefix=/opt/ruby-2.3.8 --with-openssl-dir=/opt/openssl-1.0 && \ | |
make -j$(nproc) && \ | |
make install | |
RUN chown -R deployer:deployer /opt/ruby-2.3.8/bin /opt/ruby-2.3.8/lib/ruby/gems | |
USER deployer | |
WORKDIR /app | |
ADD --chown=deployer:deployer Gemfile /app/ | |
ADD --chown=deployer:deployer Gemfile.lock /app/ | |
ENV PATH=/opt/ruby-2.3.8/bin:/opt/postgresql-11.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin | |
RUN gem install bundler -v 1.17.2 --no-rdoc --no-ri | |
RUN bundle install | |
ADD --chown=deployer:deployer Rakefile /app/Rakefile | |
ADD --chown=deployer:deployer app /app/app | |
ADD --chown=deployer:deployer config /app/config | |
ADD --chown=deployer:deployer config.ru /app/config.ru | |
ADD --chown=deployer:deployer db /app/db | |
ADD --chown=deployer:deployer lib /app/lib | |
ADD --chown=deployer:deployer public /app/public | |
ADD --chown=deployer:deployer script /app/script | |
ADD --chown=deployer:deployer services /app/services | |
ADD --chown=deployer:deployer spec /app/spec | |
ADD --chown=deployer:deployer vendor /app/vendor | |
EXPOSE 3000 | |
CMD ["rails", "server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment