Skip to content

Commit d4c111c

Browse files
authored
Optimized Dockerfile and Updated the Project (#14)
1 parent ec31dee commit d4c111c

File tree

4 files changed

+77
-37
lines changed

4 files changed

+77
-37
lines changed

.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .dockerignore
2+
.github/
3+
.idea/
4+
examples/
5+
README.md
6+
LICENSE
7+
.git/
8+
*.md
9+
*.yml
10+
Dockerfile

Dockerfile

+44-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
1-
FROM ruby:3.0.5
1+
# The first stage is dedicated to building the application
2+
FROM ruby:3.2.2-alpine as BUILD
23

3-
MAINTAINER James Hu <[email protected]>
4-
5-
ENV PORT 9594
6-
ENV ROOT /srv
7-
RUN mkdir -p $ROOT
4+
ENV PORT=9594 \
5+
USER=app \
6+
GROUP=appgroup \
7+
ROOT=/srv
88

99
WORKDIR $ROOT
1010

11-
COPY Gemfile $ROOT
12-
COPY Gemfile.lock $ROOT
11+
# Updating system packages and installing dependencies
12+
RUN apk update && apk upgrade && \
13+
apk add --update --no-cache --virtual .build-deps \
14+
build-base \
15+
libffi-dev \
16+
ruby-dev
17+
18+
# Copy the Gemfile and Gemfile.lock
19+
COPY Gemfile Gemfile.lock $ROOT/
20+
21+
# Run the specific version of bundle to install all the necessary libraries
22+
RUN gem install bundler && \
23+
bundle install && \
24+
apk del .build-deps && \
25+
rm -rf /usr/local/bundle/cache/*.gem && \
26+
find /usr/local/bundle/gems/ -name "*.c" -delete && \
27+
find /usr/local/bundle/gems/ -name "*.o" -delete
28+
29+
COPY . $ROOT/
1330

14-
RUN bundle install
31+
# The second stage is responsible for preparing the runtime
32+
FROM ruby:3.2.2-alpine as RUNTIME
33+
34+
# Copy over files from the BUILD step
35+
COPY --from=BUILD $ROOT $ROOT
36+
37+
# Set environmental variables
38+
ENV PORT=9594 \
39+
USER=app \
40+
GROUP=appgroup \
41+
ROOT=/srv
42+
43+
WORKDIR $ROOT
1544

16-
COPY . $ROOT
45+
RUN addgroup -S $GROUP && \
46+
adduser -S $USER -G $GROUP && \
47+
chown -R $USER:$GROUP $ROOT && \
48+
chmod 755 config.ru
1749

18-
RUN chmod +x config.ru
50+
USER $USER:$GROUP
1951

20-
CMD bundle exec puma --port $PORT
52+
CMD bundle exec puma -b tcp://0.0.0.0:$PORT

Gemfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
source "https://rubygems.org"
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

4-
ruby "3.0.5"
4+
ruby "3.2.2"
55

6-
gem "http", "5.1.0"
7-
gem "prometheus-client", "4.0.0"
8-
gem "puma", "6.0.0"
9-
gem "rack", "3.0.1"
6+
gem "http", "~> 5.1.1"
7+
gem "prometheus-client", "~> 4.2.2"
8+
gem "puma", "~> 6.4.0"
9+
gem "rack", "~> 3.0.8"

Gemfile.lock

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.8.1)
4+
addressable (2.8.6)
55
public_suffix (>= 2.0.2, < 6.0)
6-
domain_name (0.5.20190701)
7-
unf (>= 0.0.5, < 1.0.0)
8-
ffi (1.15.5)
6+
domain_name (0.6.20231109)
7+
ffi (1.16.3)
8+
ffi (1.16.3-x64-mingw-ucrt)
99
ffi-compiler (1.0.1)
1010
ffi (>= 1.0.0)
1111
rake
12-
http (5.1.0)
12+
http (5.1.1)
1313
addressable (~> 2.8)
1414
http-cookie (~> 1.0)
1515
http-form_data (~> 2.2)
@@ -20,29 +20,27 @@ GEM
2020
llhttp-ffi (0.4.0)
2121
ffi-compiler (~> 1.0)
2222
rake (~> 13.0)
23-
nio4r (2.5.8)
24-
prometheus-client (4.0.0)
25-
public_suffix (5.0.0)
26-
puma (6.0.0)
23+
nio4r (2.7.0)
24+
prometheus-client (4.2.2)
25+
public_suffix (5.0.4)
26+
puma (6.4.0)
2727
nio4r (~> 2.0)
28-
rack (3.0.1)
29-
rake (13.0.6)
30-
unf (0.1.4)
31-
unf_ext
32-
unf_ext (0.0.8.2)
28+
rack (3.0.8)
29+
rake (13.1.0)
3330

3431
PLATFORMS
3532
aarch64-linux
3633
arm64-darwin-21
34+
x64-mingw-ucrt
3735

3836
DEPENDENCIES
39-
http (= 5.1.0)
40-
prometheus-client (= 4.0.0)
41-
puma (= 6.0.0)
42-
rack (= 3.0.1)
37+
http
38+
prometheus-client
39+
puma
40+
rack
4341

4442
RUBY VERSION
45-
ruby 3.0.5p211
43+
ruby 3.2.2p53
4644

4745
BUNDLED WITH
48-
2.2.33
46+
2.5.3

0 commit comments

Comments
 (0)