Skip to content

Commit 0280fbc

Browse files
Add fly.io deploy files and replace yarn with bun
* Removes /builds from manifest.js because Vite handles this now
1 parent 1bce140 commit 0280fbc

File tree

14 files changed

+138
-1253
lines changed

14 files changed

+138
-1253
lines changed

.dockerignore

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Ignore git directory.
44
/.git/
5-
/.gitignore
65

76
# Ignore bundler config.
87
/.bundle
@@ -37,12 +36,8 @@
3736
!/app/assets/builds/.keep
3837
/public/assets
3938

40-
# Ignore CI service files.
41-
/.github
42-
43-
# Ignore development files
44-
/.devcontainer
45-
46-
# Ignore Docker-related files
47-
/.dockerignore
48-
/Dockerfile*
39+
# Vite Ruby
40+
/public/vite*
41+
# Vite uses dotenv and suggests to ignore local-only env files. See
42+
# https://vitejs.dev/guide/env-and-mode.html#env-files
43+
*.local

.github/workflows/fly-deploy.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.15.0

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
ruby 3.2.4
2+
nodejs 18.15.0

Dockerfile

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
# syntax = docker/dockerfile:1
22

3-
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
4-
# docker build -t my-app .
5-
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
6-
7-
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
8-
9-
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
3+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
104
ARG RUBY_VERSION=3.2.4
11-
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
5+
FROM ruby:$RUBY_VERSION-slim as base
6+
7+
LABEL fly_launch_runtime="rails"
128

139
# Rails app lives here
1410
WORKDIR /rails
1511

16-
# Install base packages
17-
RUN apt-get update -qq && \
18-
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 libvips && \
19-
rm -rf /var/lib/apt/lists /var/cache/apt/archives
20-
2112
# Set production environment
22-
ENV RAILS_ENV="production" \
23-
BUNDLE_DEPLOYMENT="1" \
13+
ENV BUNDLE_DEPLOYMENT="1" \
2414
BUNDLE_PATH="/usr/local/bundle" \
25-
BUNDLE_WITHOUT="development"
15+
BUNDLE_WITHOUT="development:test" \
16+
LITESTACK_DATA_PATH="/data" \
17+
RAILS_ENV="production"
18+
19+
# Update gems and bundler
20+
RUN gem update --system --no-document && \
21+
gem install -N bundler
22+
2623

2724
# Throw-away build stage to reduce size of final image
28-
FROM base AS build
25+
FROM base as build
2926

3027
# Install packages needed to build gems
3128
RUN apt-get update -qq && \
32-
apt-get install --no-install-recommends -y build-essential git pkg-config && \
33-
rm -rf /var/lib/apt/lists /var/cache/apt/archives
29+
apt-get install --no-install-recommends -y build-essential curl git libvips pkg-config unzip
30+
31+
# Install Bun
32+
ARG BUN_VERSION=1.1.27
33+
ENV BUN_INSTALL=/usr/local/bun
34+
ENV PATH=/usr/local/bun/bin:$PATH
35+
RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}"
3436

3537
# Install application gems
36-
COPY Gemfile Gemfile.lock ./
38+
COPY --link Gemfile Gemfile.lock ./
3739
RUN bundle install && \
38-
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
39-
bundle exec bootsnap precompile --gemfile
40+
bundle exec bootsnap precompile --gemfile && \
41+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
42+
43+
# Install node modules
44+
COPY --link package.json bun.lockb ./
45+
RUN bun install --frozen-lockfile
4046

4147
# Copy application code
42-
COPY . .
48+
COPY --link . .
4349

4450
# Precompile bootsnap code for faster boot times
4551
RUN bundle exec bootsnap precompile app/ lib/
@@ -48,24 +54,32 @@ RUN bundle exec bootsnap precompile app/ lib/
4854
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
4955

5056

51-
52-
5357
# Final stage for app image
5458
FROM base
5559

60+
# Install packages needed for deployment
61+
RUN apt-get update -qq && \
62+
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
63+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
64+
5665
# Copy built artifacts: gems, application
5766
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
5867
COPY --from=build /rails /rails
5968

6069
# Run and own only the runtime files as a non-root user for security
6170
RUN groupadd --system --gid 1000 rails && \
6271
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
63-
chown -R rails:rails db log storage tmp
72+
mkdir /data && \
73+
chown -R 1000:1000 db log storage tmp /data
6474
USER 1000:1000
6575

76+
# Deployment options
77+
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"
78+
6679
# Entrypoint prepares the database.
6780
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
6881

6982
# Start the server by default, this can be overwritten at runtime
7083
EXPOSE 3000
84+
VOLUME /data
7185
CMD ["./bin/rails", "server"]

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ end
7171
group :development do
7272
gem "standard", ">= 1.35.1"
7373
gem "annotate"
74+
gem "dockerfile-rails", ">= 1.6"
7475
end
76+

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ GEM
110110
irb (~> 1.10)
111111
reline (>= 0.3.8)
112112
diff-lcs (1.5.1)
113+
dockerfile-rails (1.6.17)
114+
rails (>= 3.0.0)
113115
dotenv (3.1.2)
114116
drb (2.2.1)
115117
dry-cli (1.1.0)
@@ -121,13 +123,17 @@ GEM
121123
railties (>= 5.0.0)
122124
faker (3.4.2)
123125
i18n (>= 1.8.11, < 2)
126+
ffi (1.17.0-aarch64-linux-gnu)
124127
ffi (1.17.0-arm64-darwin)
125128
ffi (1.17.0-x86_64-darwin)
126129
ffi (1.17.0-x86_64-linux-gnu)
127130
friendly_id (5.5.1)
128131
activerecord (>= 4.0.0)
129132
globalid (1.2.1)
130133
activesupport (>= 6.1)
134+
google-protobuf (4.27.3-aarch64-linux)
135+
bigdecimal
136+
rake (>= 13)
131137
google-protobuf (4.27.3-arm64-darwin)
132138
bigdecimal
133139
rake (>= 13)
@@ -183,6 +189,8 @@ GEM
183189
net-smtp (0.5.0)
184190
net-protocol
185191
nio4r (2.7.3)
192+
nokogiri (1.16.7-aarch64-linux)
193+
racc (~> 1.4)
186194
nokogiri (1.16.7-arm64-darwin)
187195
racc (~> 1.4)
188196
nokogiri (1.16.7-x86_64-darwin)
@@ -308,6 +316,7 @@ GEM
308316
actionpack (>= 6.1)
309317
activesupport (>= 6.1)
310318
sprockets (>= 3.0.0)
319+
sqlite3 (1.7.3-aarch64-linux)
311320
sqlite3 (1.7.3-arm64-darwin)
312321
sqlite3 (1.7.3-x86_64-darwin)
313322
sqlite3 (1.7.3-x86_64-linux)
@@ -360,6 +369,7 @@ GEM
360369
zeitwerk (2.6.17)
361370

362371
PLATFORMS
372+
aarch64-linux
363373
arm64-darwin-23
364374
x86_64-darwin-18
365375
x86_64-linux
@@ -370,6 +380,7 @@ DEPENDENCIES
370380
brakeman
371381
capybara
372382
debug
383+
dockerfile-rails (>= 1.6)
373384
dotenv
374385
factory_bot_rails
375386
faker

app/assets/config/manifest.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
//= link_tree ../images
22
//= link_directory ../stylesheets .css
3-
//= link_tree ../builds

bin/docker-entrypoint

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#!/bin/bash -e
22

3-
# Enable jemalloc for reduced memory usage and latency.
4-
if [ -z "${LD_PRELOAD+x}" ] && [ -f /usr/lib/*/libjemalloc.so.2 ]; then
5-
export LD_PRELOAD="$(echo /usr/lib/*/libjemalloc.so.2)"
6-
fi
7-
83
# If running the rails server then create or migrate existing database
94
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
105
./bin/rails db:prepare

bun.lockb

69.2 KB
Binary file not shown.

config/dockerfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# generated by dockerfile-rails
2+
3+
---
4+
options:
5+
label:
6+
fly_launch_runtime: rails

fly.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# fly.toml app configuration file generated for phlexy-ui-docs on 2024-09-18T00:37:00+02:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'phlexy-ui-docs'
7+
primary_region = 'lax'
8+
console_command = '/rails/bin/rails console'
9+
10+
[build]
11+
12+
[env]
13+
DATABASE_URL = 'sqlite3:///data/production.sqlite3'
14+
15+
[[mounts]]
16+
source = 'data'
17+
destination = '/data'
18+
19+
[http_service]
20+
internal_port = 3000
21+
force_https = true
22+
auto_stop_machines = 'stop'
23+
auto_start_machines = true
24+
min_machines_running = 0
25+
processes = ['app']
26+
27+
[checks]
28+
[checks.status]
29+
port = 3000
30+
type = 'http'
31+
interval = '10s'
32+
timeout = '2s'
33+
grace_period = '5s'
34+
method = 'GET'
35+
path = '/up'
36+
protocol = 'http'
37+
tls_skip_verify = false
38+
39+
[checks.status.headers]
40+
X-Forwarded-Proto = 'https'
41+
42+
[[vm]]
43+
memory = '2gb'
44+
cpu_kind = 'shared'
45+
cpus = 1
46+
47+
[[statics]]
48+
guest_path = '/rails/public'
49+
url_prefix = '/'

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@
1616
"vite": "^5.0.0",
1717
"vite-plugin-ruby": "^5.0.0",
1818
"vite-plugin-stimulus-hmr": "^3.0.0"
19+
},
20+
"packageManager": "yarn@1.22.22",
21+
"scripts": {
22+
"build": "vite build --outDir public"
1923
}
20-
}
24+
}

0 commit comments

Comments
 (0)