1
- # syntax = docker/dockerfile:1
1
+ # syntax=docker/dockerfile:1
2
+ # check=error=true
2
3
3
- # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
4
5
ARG RUBY_VERSION=3.4.2
5
- FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-jemalloc-slim as base
6
+ FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-jemalloc-slim AS base
6
7
7
8
LABEL fly_launch_runtime="rails"
8
9
9
10
# Rails app lives here
10
11
WORKDIR /rails
11
12
13
+ # Update gems and bundler
14
+ RUN gem update --system --no-document && \
15
+ gem install -N bundler
16
+
17
+ # Install base packages
18
+ RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
19
+ --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
20
+ apt-get update -qq && \
21
+ apt-get install --no-install-recommends -y curl sqlite3
22
+
12
23
# Set production environment
13
24
ENV BUNDLE_DEPLOYMENT="1" \
14
25
BUNDLE_PATH="/usr/local/bundle" \
15
26
BUNDLE_WITHOUT="development:test" \
16
27
RAILS_ENV="production"
17
28
18
- # Update gems and bundler
19
- RUN gem update --system --no-document && \
20
- gem install -N bundler
21
-
22
29
23
30
# Throw-away build stages to reduce size of final image
24
- FROM base as prebuild
31
+ FROM base AS prebuild
25
32
26
33
# Install packages needed to build gems and node modules
27
34
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
28
35
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
29
36
apt-get update -qq && \
30
- apt-get install --no-install-recommends -y build-essential curl libpq -dev libyaml-dev node-gyp pkg-config python-is-python3
37
+ apt-get install --no-install-recommends -y build-essential libffi -dev libyaml-dev node-gyp pkg-config python-is-python3
31
38
32
39
33
- FROM prebuild as node
40
+ FROM prebuild AS node
34
41
35
42
# Install JavaScript dependencies
36
- ARG NODE_VERSION=20.10.0
43
+ ARG NODE_VERSION=20.12.2
37
44
ARG YARN_VERSION=1.22.22
38
45
ENV PATH=/usr/local/node/bin:$PATH
39
46
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
@@ -42,15 +49,15 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz
42
49
rm -rf /tmp/node-build-master
43
50
44
51
# Install node modules
45
- COPY --link package.json yarn.lock ./
52
+ COPY package.json yarn.lock ./
46
53
RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
47
54
YARN_CACHE_FOLDER=/root/.yarn yarn install --frozen-lockfile
48
55
49
56
50
- FROM prebuild as build
57
+ FROM prebuild AS build
51
58
52
59
# Install application gems
53
- COPY --link Gemfile Gemfile.lock ./
60
+ COPY Gemfile Gemfile.lock ./
54
61
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
55
62
bundle config set app_config .bundle && \
56
63
bundle config set path /srv/vendor && \
@@ -67,7 +74,7 @@ COPY --from=node /usr/local/node /usr/local/node
67
74
ENV PATH=/usr/local/node/bin:$PATH
68
75
69
76
# Copy application code
70
- COPY --link . .
77
+ COPY . .
71
78
72
79
# Precompile bootsnap code for faster boot times
73
80
RUN bundle exec bootsnap precompile app/ lib/
@@ -79,27 +86,26 @@ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
79
86
# Final stage for app image
80
87
FROM base
81
88
82
- # Install packages needed for deployment
83
- RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
84
- --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
85
- apt-get update -qq && \
86
- apt-get install --no-install-recommends -y curl postgresql-client
87
89
88
90
# Copy built artifacts: gems, application
89
- COPY --from=build /usr/local/bundle /usr/local/bundle
91
+ COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
90
92
COPY --from=build /rails /rails
91
93
92
94
# Run and own only the runtime files as a non-root user for security
93
95
RUN groupadd --system --gid 1000 rails && \
94
96
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
95
- chown -R 1000:1000 db log storage tmp
97
+ mkdir /data && \
98
+ chown -R 1000:1000 db log storage tmp /data
96
99
USER 1000:1000
97
100
98
101
# Deployment options
99
- ENV RUBY_YJIT_ENABLE="1"
102
+ ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
103
+ RUBY_YJIT_ENABLE="1"
100
104
101
105
# Entrypoint sets up the container.
102
106
ENTRYPOINT ["/rails/bin/docker-entrypoint" ]
103
107
104
108
# Start the server by default, this can be overwritten at runtime
105
109
EXPOSE 3000
110
+ VOLUME /data
111
+ CMD ["./bin/rails" , "server" ]
0 commit comments