Skip to content

Instantly share code, notes, and snippets.

@IvanIvashchenko
Created March 14, 2024 16:23
Show Gist options
  • Save IvanIvashchenko/eb43e502593eb4793808a03771fa6c33 to your computer and use it in GitHub Desktop.
Save IvanIvashchenko/eb43e502593eb4793808a03771fa6c33 to your computer and use it in GitHub Desktop.
Example of local docker configuration for simple RoR application
version: "3.8"
services:
db:
image: postgres:11-alpine
environment:
POSTGRES_USER: ${DOCKER_POSTGRES_USER}
POSTGRES_PASSWORD: ${DOCKER_POSTGRES_PASSWORD}
ports:
- '5434:5432'
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build:
target: web
command: bash -c "bundle check || bundle install && rails s -b 0.0.0.0 -p 3003"
environment:
SSH_AUTH_SOCK: /ssh-agent
ports:
- '3000:3003'
volumes:
- .:/app
- bundle_cache:/bundle_cache
- ${HOST_SSH_SOCKET_PATH}:/ssh-agent
<<: &default
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile
tty: true
stdin_open: true
depends_on:
- db
job:
<<: *default
build:
target: job
command: bash -c "bundle check || bundle install && bundle exec rake jobs:work"
volumes:
- .:/app
- bundle_cache:/bundle_cache
bundle_cache:
image: busybox
volumes:
- bundle_cache:/bundle_cache
volumes:
bundle_cache:
FROM ubuntu:22.04 AS build
SHELL ["/bin/bash", "-c"]
ENV RUBY_MAJOR 3.2
ENV RUBY_VERSION 3.2.2
# Default directory
ENV WORKING_PATH /app
RUN mkdir -p $WORKING_PATH
# Prepare to install tzdata
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=America/New_York
# No output except for errors
RUN apt-get update -qq && apt-get install -y wget gnupg cmake g++ file sudo pkg-config imagemagick libtool\
libpq-dev postgresql-client git gawk bison libffi-dev libgdbm-dev tzdata\
libncurses5-dev libsqlite3-dev libyaml-dev sqlite3 zlib1g-dev libgmp-dev libreadline-dev
# https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9
RUN git config --global --add safe.directory $WORKING_PATH
# Install ruby (download and compile from source)
RUN wget -O ruby.tar.gz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR}/ruby-$RUBY_VERSION.tar.gz"; \
mkdir -p tmp/src/ruby; \
tar -xzf ruby.tar.gz -C tmp/src/ruby --strip-components=1; \
rm ruby.tar.gz; \
cd tmp/src/ruby; \
./configure --disable-install-doc; \
make; \
make install
RUN rm -r tmp/src/ruby; \
ruby --version; \
gem --version; \
bundle --version
ENV BUNDLE_SILENCE_ROOT_WARNING=1
ENV BUNDLE_PATH /bundle_cache
ENV PATH="$WORKING_PATH/bin:${PATH}"
WORKDIR $WORKING_PATH
RUN gem update --system --no-document
FROM build as web
# Yarn installation deps
RUN wget -O- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn-pubkey.gpg > /dev/null
RUN echo "deb [signed-by=/etc/apt/keyrings/yarn-pubkey.gpg] https://dl.yarnpkg.com/debian/ stable main" | \
tee /etc/apt/sources.list.d/yarn.list
RUN wget -qO- https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get update -qq && apt-get install -y nodejs yarn
RUN yarn install
## Integration tests configuration
# Installation firefox via apt is a little bit tricky thing
RUN apt-get -y install software-properties-common; \
add-apt-repository -y ppa:mozillateam/ppa
RUN echo $' \n\
Package: *\n\
Pin: release o=LP-PPA-mozillateam\n\
Pin-Priority: 1001' | tee /etc/apt/preferences.d/mozilla-firefox
RUN apt-get -y install firefox
# Install chromium
RUN apt purge chromium-browser chromium-chromedriver; \
apt-get install debian-archive-keyring
RUN echo $'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian buster main\n\
deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian-security/ buster/updates main\n\
deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian buster-updates main' | \
tee /etc/apt/sources.list.d/debian.list
RUN echo $' \n\
Explanation: Allow installing chromium from the debian repo.\n\
Package: chromium*\n\
Pin: origin "*.debian.org"\n\
Pin-Priority: 100\n\
\n\
Explanation: Avoid other packages from the debian repo.\n\
Package: *\n\
Pin: origin "*.debian.org"\n\
Pin-Priority: 1' | tee /etc/apt/preferences.d/chromium.pref
RUN apt-get update && apt-get -y install chromium
EXPOSE 3003
# Run a server
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3003"]
FROM build as job
# Run jobs
CMD ["bundle", "exec", "rake", "jobs:work"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment