Skip to content

Commit 8db5a25

Browse files
author
Mattia Roccoberton
committed
Improve Docker setup for Ruby 3.0
1 parent 0fe50ef commit 8db5a25

4 files changed

Lines changed: 80 additions & 55 deletions

File tree

extra/Dockerfile_26

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ RUN gem install bundler
88
# App setup
99
WORKDIR /usr/src/app
1010
COPY .. .
11-
RUN bundle install
1211

1312
# Setup the entrypoint script
1413
COPY extra/entrypoint.sh /usr/bin/

extra/Dockerfile_27

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RUN apk add --no-cache --update build-base dpkg gcompat mysql-dev postgresql-dev
77
# App setup
88
WORKDIR /usr/src/app
99
COPY .. .
10-
RUN bundle install
1110

1211
# Setup the entrypoint script
1312
COPY extra/entrypoint.sh /usr/bin/

extra/Dockerfile_30

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ruby:3.0-alpine
2+
3+
ARG DB_TEST
4+
5+
RUN apk add --no-cache --update build-base dpkg gcompat mysql-dev postgresql-dev tzdata
6+
7+
# App setup
8+
WORKDIR /usr/src/app
9+
COPY .. .
10+
11+
# Setup the entrypoint script
12+
COPY extra/entrypoint.sh /usr/bin/
13+
RUN chmod +x /usr/bin/entrypoint.sh
14+
15+
ENTRYPOINT ["entrypoint.sh"]

extra/docker-compose.yml

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
version: "3.3"
33

44
x-defaults:
5-
tests: &base_tests
6-
environment: &base_enviroment
5+
tests_mysql: &tests_mysql
6+
environment:
77
CI: 1
8+
DB_TEST: mysql
9+
DB_PORT: 3306
10+
MYSQL_DB_HOST: mysql
11+
MYSQL_DB_NAME: test_db
12+
MYSQL_DB_USERNAME: root
13+
MYSQL_DB_PASSWORD: password
814
RAILS_ENV: test
915
command:
1016
- sh
@@ -17,6 +23,36 @@ x-defaults:
1723
bin/setup
1824
cd ../..
1925
bin/rspec
26+
volumes:
27+
- ..:/usr/src/app:delegated
28+
depends_on:
29+
- mysql
30+
31+
tests_postgres: &tests_postgres
32+
environment:
33+
CI: 1
34+
DB_TEST: postgres
35+
DB_PORT: 5432
36+
PG_DB_HOST: postgres
37+
PG_DB_NAME: test_db
38+
PG_DB_USERNAME: postgres
39+
PG_DB_PASSWORD: password
40+
RAILS_ENV: test
41+
command:
42+
- sh
43+
- -c
44+
- |
45+
while ! nc -z $${DB_TEST} $${DB_PORT} </dev/null
46+
do echo "Waiting for DB ($${DB_TEST})..." && sleep 5; done
47+
echo "DB is now available!"
48+
cd spec/dummy
49+
bin/setup
50+
cd ../..
51+
bin/rspec
52+
volumes:
53+
- ..:/usr/src/app:delegated
54+
depends_on:
55+
- postgres
2056

2157
services:
2258
postgres:
@@ -30,74 +66,50 @@ services:
3066
environment:
3167
MYSQL_ROOT_PASSWORD: password
3268

33-
tests_26_pg:
34-
<<: *base_tests
69+
tests_26_mysql:
70+
<<: *tests_mysql
3571
build:
3672
context: ..
37-
dockerfile: extra/Dockerfile_27
73+
dockerfile: extra/Dockerfile_26
3874
args:
39-
DB_TEST: postgres
40-
environment:
41-
<<: *base_enviroment
42-
DB_TEST: postgres
43-
DB_PORT: 5432
44-
PG_DB_HOST: postgres
45-
PG_DB_NAME: postgres_26
46-
PG_DB_USERNAME: postgres
47-
PG_DB_PASSWORD: password
48-
depends_on:
49-
- postgres
75+
DB_TEST: mysql
5076

51-
tests_26_mysql:
52-
<<: *base_tests
77+
tests_26_postgres:
78+
<<: *tests_postgres
5379
build:
5480
context: ..
5581
dockerfile: extra/Dockerfile_26
82+
args:
83+
DB_TEST: postgres
84+
85+
tests_27_mysql:
86+
<<: *tests_mysql
87+
build:
88+
context: ..
89+
dockerfile: extra/Dockerfile_27
5690
args:
5791
DB_TEST: mysql
58-
environment:
59-
<<: *base_enviroment
60-
DB_TEST: mysql
61-
DB_PORT: 3306
62-
MYSQL_DB_HOST: mysql
63-
MYSQL_DB_NAME: mysql_26
64-
MYSQL_DB_USERNAME: root
65-
MYSQL_DB_PASSWORD: password
66-
depends_on:
67-
- mysql
6892

69-
tests_27_pg:
70-
<<: *base_tests
93+
tests_27_postgres:
94+
<<: *tests_postgres
7195
build:
7296
context: ..
7397
dockerfile: extra/Dockerfile_27
7498
args:
7599
DB_TEST: postgres
76-
environment:
77-
<<: *base_enviroment
78-
DB_TEST: postgres
79-
DB_PORT: 5432
80-
PG_DB_HOST: postgres
81-
PG_DB_NAME: postgres_27
82-
PG_DB_USERNAME: postgres
83-
PG_DB_PASSWORD: password
84-
depends_on:
85-
- postgres
86100

87-
tests_27_mysql:
88-
<<: *base_tests
101+
tests_30_mysql:
102+
<<: *tests_mysql
89103
build:
90104
context: ..
91-
dockerfile: extra/Dockerfile_27
105+
dockerfile: extra/Dockerfile_30
92106
args:
93107
DB_TEST: mysql
94-
environment:
95-
<<: *base_enviroment
96-
DB_TEST: mysql
97-
DB_PORT: 3306
98-
MYSQL_DB_HOST: mysql
99-
MYSQL_DB_NAME: mysql_27
100-
MYSQL_DB_USERNAME: root
101-
MYSQL_DB_PASSWORD: password
102-
depends_on:
103-
- mysql
108+
109+
tests_30_postgres:
110+
<<: *tests_postgres
111+
build:
112+
context: ..
113+
dockerfile: extra/Dockerfile_30
114+
args:
115+
DB_TEST: postgres

0 commit comments

Comments
 (0)