Skip to content

Commit 51de1c2

Browse files
committed
Setup docker and Add to Readme
1 parent 9ab61a0 commit 51de1c2

13 files changed

+325
-72
lines changed

.dev_to/.bashrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alias be="bundle exec"

.dev_to/.env-example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALGOLIASEARCH_APPLICATION_ID: YOUR
2+
ALGOLIASEARCH_API_KEY: KEYS
3+
ALGOLIASEARCH_SEARCH_ONLY_KEY: HERE

.dev_to/Aptfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vim
2+
python-dev

.dev_to/Dockerfile

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG RUBY_VERSION
4+
ARG DISTRO_NAME=buster
5+
6+
FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME
7+
8+
ARG DISTRO_NAME
9+
10+
# Common dependencies
11+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
12+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
13+
--mount=type=tmpfs,target=/var/log \
14+
rm -f /etc/apt/apt.conf.d/docker-clean; \
15+
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache; \
16+
apt-get update -qq \
17+
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
18+
build-essential \
19+
gnupg2 \
20+
curl \
21+
less \
22+
git
23+
24+
# Install PostgreSQL dependencies
25+
ARG PG_MAJOR
26+
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
27+
gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg \
28+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/" \
29+
$DISTRO_NAME-pgdg main $PG_MAJOR | tee /etc/apt/sources.list.d/postgres.list > /dev/null
30+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
31+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
32+
--mount=type=tmpfs,target=/var/log \
33+
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
34+
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
35+
libpq-dev \
36+
postgresql-client-$PG_MAJOR
37+
38+
# Install NodeJS and Yarn
39+
ARG NODE_MAJOR
40+
ARG YARN_VERSION=latest
41+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
42+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
43+
--mount=type=tmpfs,target=/var/log \
44+
apt-get update && \
45+
apt-get install -y curl software-properties-common && \
46+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
47+
echo "deb https://deb.nodesource.com/node_${NODE_MAJOR}.x $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/nodesource.list && \
48+
apt-get update && \
49+
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends nodejs
50+
RUN npm install -g yarn@$YARN_VERSION
51+
52+
# Application dependencies
53+
# We use an external Aptfile for this, stay tuned
54+
COPY Aptfile /tmp/Aptfile
55+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
56+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
57+
--mount=type=tmpfs,target=/var/log \
58+
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
59+
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
60+
$(grep -Ev '^\s*#' /tmp/Aptfile | xargs)
61+
62+
# Configure bundler
63+
ENV LANG=C.UTF-8 \
64+
BUNDLE_JOBS=4 \
65+
BUNDLE_RETRY=3
66+
67+
# Store Bundler settings in the project's root
68+
ENV BUNDLE_APP_CONFIG=.bundle
69+
70+
# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec`
71+
# ENV PATH /app/bin:$PATH
72+
73+
# Upgrade RubyGems and install the latest Bundler version
74+
RUN gem install bundler -v 2.4.22
75+
76+
# Create a directory for the app code
77+
RUN mkdir -p /app
78+
WORKDIR /app
79+
80+
# Document that we're going to expose port 3000
81+
EXPOSE 3000
82+
# Use Bash as the default command
83+
CMD ["/bin/bash"]

.dev_to/compose.yml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
x-app: &app
2+
build:
3+
context: .
4+
args:
5+
RUBY_VERSION: '2.6.10'
6+
PG_MAJOR: '15'
7+
NODE_MAJOR: '10'
8+
image: optimize-dev-to:1.0.0
9+
environment: &env
10+
NODE_ENV: ${NODE_ENV:-development}
11+
RAILS_ENV: ${RAILS_ENV:-development}
12+
tmpfs:
13+
- /tmp
14+
- /app/tmp/pids
15+
16+
x-backend: &backend
17+
<<: *app
18+
stdin_open: true
19+
tty: true
20+
volumes:
21+
- ..:/app:cached
22+
- bundle:/usr/local/bundle
23+
- rails_cache:/app/tmp/cache
24+
- node_modules:/app/node_modules
25+
- packs:/app/public/packs
26+
- packs-test:/app/public/packs-test
27+
- history:/usr/local/hist
28+
- ./.psqlrc:/root/.psqlrc:ro
29+
- ./.bashrc:/root/.bashrc:ro
30+
environment: &backend_environment
31+
<<: *env
32+
YARN_INTEGRITY_ENABLED: "false"
33+
ALGOLIASEARCH_APPLICATION_ID: ${ALGOLIASEARCH_APPLICATION_ID}
34+
ALGOLIASEARCH_API_KEY: ${ALGOLIASEARCH_API_KEY}
35+
ALGOLIASEARCH_SEARCH_ONLY_KEY: ${ALGOLIASEARCH_SEARCH_ONLY_KEY}
36+
REDIS_URL: redis://redis:6379/
37+
DATABASE_URL: postgres://postgres:postgres@postgres:5432
38+
WEBPACKER_DEV_SERVER_HOST: webpacker
39+
MALLOC_ARENA_MAX: 2
40+
WEB_CONCURRENCY: ${WEB_CONCURRENCY:-1}
41+
BOOTSNAP_CACHE_DIR: /usr/local/bundle/_bootsnap
42+
XDG_DATA_HOME: /app/tmp/caches
43+
YARN_CACHE_FOLDER: /app/node_modules/.yarn-cache
44+
HISTFILE: /usr/local/hist/.bash_history
45+
PSQL_HISTFILE: /usr/local/hist/.psql_history
46+
IRB_HISTFILE: /usr/local/hist/.irb_history
47+
EDITOR: vi
48+
depends_on: &backend_depends_on
49+
postgres:
50+
condition: service_healthy
51+
redis:
52+
condition: service_healthy
53+
54+
services:
55+
rails:
56+
<<: *backend
57+
command: bundle exec rails
58+
59+
web:
60+
<<: *backend
61+
command: bundle exec rails server -b 0.0.0.0
62+
ports:
63+
- '3000:3000'
64+
depends_on:
65+
webpacker:
66+
condition: service_started
67+
# sidekiq:
68+
# condition: service_started
69+
70+
# sidekiq:
71+
# <<: *backend
72+
# command: bundle exec sidekiq -C config/sidekiq.yml
73+
74+
postgres:
75+
image: postgres:14
76+
volumes:
77+
- .psqlrc:/root/.psqlrc:ro
78+
- postgres:/var/lib/postgresql/data
79+
- history:/user/local/hist
80+
environment:
81+
PSQL_HISTFILE: /user/local/hist/.psql_history
82+
POSTGRES_PASSWORD: postgres
83+
ports:
84+
- 5432
85+
healthcheck:
86+
test: pg_isready -U postgres -h 127.0.0.1
87+
interval: 5s
88+
89+
redis:
90+
image: redis:6.2-alpine
91+
volumes:
92+
- redis:/data
93+
ports:
94+
- 6379
95+
healthcheck:
96+
test: redis-cli ping
97+
interval: 1s
98+
timeout: 3s
99+
retries: 30
100+
101+
webpacker:
102+
<<: *app
103+
command: bundle exec ./bin/webpack-dev-server
104+
ports:
105+
- '3035:3035'
106+
volumes:
107+
- ..:/app:cached
108+
- bundle:/usr/local/bundle
109+
- node_modules:/app/node_modules
110+
- packs:/app/public/packs
111+
- packs-test:/app/public/packs-test
112+
environment:
113+
<<: *env
114+
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
115+
YARN_CACHE_FOLDER: /app/node_modules/.yarn-cache
116+
117+
volumes:
118+
bundle:
119+
node_modules:
120+
history:
121+
rails_cache:
122+
postgres:
123+
redis:
124+
packs:
125+
packs-test:

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# or operating system, you probably want to add a global ignore instead:
55
# git config --global core.excludesfile '~/.gitignore_global'
66

7+
# Ignore personal env variables
8+
.dev_to/.env
9+
710
# Ignore bundler config.
811
/.bundle
912
vendor/bundle
@@ -52,4 +55,4 @@ package-lock.json
5255
.idea/
5356

5457
#sitemap
55-
/public/sitemap.xml.gz
58+
/public/sitemap.xml.gz

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.3
1+
3.3.1

Dockerfile

-31
This file was deleted.

Gemfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# rubocop:disable LineLength
22
source "https://rubygems.org"
3-
ruby "2.6.3"
3+
ruby "2.6.10"
44

55
# Enforce git to transmitted via https.
66
# workaround until bundler 2.0 is released.
@@ -130,8 +130,8 @@ group :development, :test do
130130
gem "rspec-retry", "~> 0.6"
131131
gem "rubocop", "~> 0.63", require: false
132132
gem "rubocop-rspec", "~> 1.31"
133-
gem "spring", "~> 2.0"
134-
gem "spring-commands-rspec", "~> 1.0"
133+
# gem "spring", "~> 2.0"
134+
# gem "spring-commands-rspec", "~> 1.0"
135135
gem "vcr", "~> 4.0"
136136
end
137137

Gemfile.lock

+1-7
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,6 @@ GEM
836836
activesupport (>= 4.2.0)
837837
slack-notifier (2.3.2)
838838
smart_properties (1.13.1)
839-
spring (2.0.2)
840-
activesupport (>= 4.2)
841-
spring-commands-rspec (1.0.4)
842-
spring (>= 0.9.1)
843839
sprockets (3.7.2)
844840
concurrent-ruby (~> 1.0)
845841
rack (> 1, < 3)
@@ -1046,8 +1042,6 @@ DEPENDENCIES
10461042
sitemap_generator (~> 6.0)
10471043
skylight (~> 3.1)
10481044
slack-notifier (~> 2.3)
1049-
spring (~> 2.0)
1050-
spring-commands-rspec (~> 1.0)
10511045
sprockets (~> 3.7)
10521046
staccato (~> 0.5)
10531047
stackprof (~> 0.2)
@@ -1069,7 +1063,7 @@ DEPENDENCIES
10691063
zonebie (~> 0.6.1)
10701064

10711065
RUBY VERSION
1072-
ruby 2.6.3p62
1066+
ruby 2.6.10p210
10731067

10741068
BUNDLED WITH
10751069
1.17.3

Readme.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
# Setup через docker, docker-compose и dip
2+
3+
После успешного запуска проекта в 4м задании тут должно уже быть легко.
4+
5+
- probably change .ruby-version file with your ruby version
6+
- cp config/database.yml.sample config/database.yml (or take from your HW #4)
7+
- cp -r ../rails-optimization-task4/public/uploads public (for seeded images)
8+
- cp .env from your HW #4 (optional)
9+
- cd .dev_to
10+
- docker-compose up
11+
- open localhost:3000 in your browser
12+
13+
After setup you can
14+
15+
- dip bundle - to bundle install after adding gems
16+
- dip setup - to rerun bin/setup
17+
- dip bash - to do any other commands or just to peek around
18+
119
# Задание №5
220

321
## Цели задания
422

23+
**ПОКА НЕ НАЧИНАЙТЕ ЭТО ЗАДАНИЕ ПОЖАЛУЙСТА, Я ЕГО НЕМНОГО ПЕРЕРАБОТАЮ В БЛИЖАЙШИЕ ДНИ**
24+
25+
526
В этом задании немного попрактикуемся с `HTTP/2` в `Rails`.
627

728
Польза:

0 commit comments

Comments
 (0)