Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Переход на importmap #48

Merged
merged 11 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
/public/assets

*.private
/node_modules
12 changes: 2 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,26 @@ ENV RAILS_ENV="production" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"


# Throw-away build stage to reduce size of final image
FROM base as build

RUN apk add --no-cache --virtual .build-deps build-base git postgresql-dev vips-dev tzdata yarn nodejs-current npm

RUN apk add --no-cache --virtual .build-deps build-base git postgresql-dev vips-dev tzdata pkgconfig
RUN apk add --no-cache curl vips-dev postgresql-client tzdata
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives

RUN npm install -g yarn@latest

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
RUN bundle exec bootsnap precompile --gemfile

# Install node modules
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN ./bin/rails assets:precompile
vzalygin marked this conversation as resolved.
Show resolved Hide resolved

# Final stage for app image
FROM base
Expand Down
16 changes: 7 additions & 9 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ ENV RAILS_ENV="development" \
FROM base AS node

# Install node modules
RUN apk add --virtual .build-deps nodejs-current npm yarn
RUN apk add --virtual .build-deps yarn
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile --modules-folder /node_modules
RUN yarn install --frozen-lockfile --modules-folder $NODE_PATH
vzalygin marked this conversation as resolved.
Show resolved Hide resolved

FROM base AS run

# Install system dependencies
RUN apk add --virtual .build-deps \
build-base postgresql-dev vips-dev tzdata curl postgresql \
nodejs-current npm yarn
RUN apk add --no-cache --virtual .build-deps build-base git postgresql-dev vips-dev tzdata yarn pkgconfig
RUN apk add --no-cache curl vips-dev postgresql-client tzdata
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install application gems
Expand All @@ -29,16 +28,15 @@ RUN bundle install
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
RUN bundle exec bootsnap precompile --gemfile

# Copy application code
COPY . .

COPY --from=node /node_modules /node_modules
RUN yarn global add nodemon esbuild sass postcss postcss-cli --prefix /usr/local
RUN yarn global add nodemon sass postcss-cli --prefix /usr/local

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

vzalygin marked this conversation as resolved.
Show resolved Hide resolved
RUN adduser -D rails --shell /bin/bash
RUN mkdir -p /usr/local/bundle/ruby/3.2.0/cache
RUN chown -R rails:rails \
Expand Down
7 changes: 2 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ gem 'pg', '~> 1.1'
# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'

# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem 'jsbundling-rails'
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem 'importmap-rails'

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem 'turbo-rails'

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'

# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
gem 'cssbundling-rails'

vzalygin marked this conversation as resolved.
Show resolved Hide resolved
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'

Expand Down
11 changes: 5 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ GEM
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
csv (3.3.0)
date (3.3.4)
debug (1.9.2)
Expand Down Expand Up @@ -140,6 +138,10 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
instagram_basic_display (0.2.0)
instagram_graph_api (0.0.13)
koala
Expand All @@ -154,8 +156,6 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jsbundling-rails (1.3.0)
railties (>= 6.0.0)
json (2.7.2)
jwt (2.8.2)
base64
Expand Down Expand Up @@ -391,17 +391,16 @@ DEPENDENCIES
administrate
bootsnap
capybara
cssbundling-rails
debug
devise
digest
faraday
ffi (~> 1.16.3)
httparty
importmap-rails
instagram_basic_display
instagram_graph_api
jbuilder
jsbundling-rails
omniauth-instagram
open-uri
pg (~> 1.1)
Expand Down
166 changes: 84 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
SHELL=/bin/sh

UID := $(shell id -u)
GID := $(shell id -g)

include .env
export

setup: build db-prepare

build:
bundle lock --update
npm install --package-lock-only
docker compose build

up:
docker compose up

down:
docker compose down

clear:
sudo docker compose down -v --rmi all

creds:
EDITOR='code --wait' bin/rails credentials:edit

ash:
sudo docker compose run --rm app ash

console:
sudo docker compose run --rm app bundle exec rails c

yarn:
docker compose run --rm app yarn install

bundle:
docker compose run --rm app bundle install

rubocop:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml

rubocop-verbose:
docker compose run --rm app bundle exec rubocop

rubocopA:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml -A

db-psql:
sudo docker compose run --rm app psql -d ${POSTGRES_DB} -U ${POSTGRES_USER} -W -h db

db-prepare: db-drop db-create db-migrate db-seed

db-create:
sudo docker compose run --rm app bin/rails db:create RAILS_ENV=development

db-migrate:
sudo docker compose run --rm app bin/rails db:migrate

db-rollback:
sudo docker compose run --rm app bin/rails db:rollback

db-seed:
sudo docker compose run --rm app bin/rails db:seed

db-reset:
sudo docker compose run --rm app bin/rails db:reset

db-drop:
docker compose run --rm app bin/rails db:drop

ci-build:
bundle lock --update
npm install --package-lock-only
docker compose build -q

ci-up-healthy: db-prepare
docker compose up -d --wait --wait-timeout 60

ci-rubocop: rubocop

ci-clear: clear
SHELL=/bin/sh

UID := $(shell id -u)
GID := $(shell id -g)

include .env
export

setup: build db-prepare

build:
docker compose build

deps:
yarn install && rm -rf ./node_modules
bundle install

up:
docker compose up

down:
docker compose down

clear:
docker compose down -v --rmi all

creds:
EDITOR='code --wait' bin/rails credentials:edit

ash:
docker compose run --rm app ash

console:
docker compose run --rm app bundle exec rails c

yarn:
docker compose run --rm app yarn install

bundle:
docker compose run --rm app bundle install

rubocop:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml

rubocop-verbose:
docker compose run --rm app bundle exec rubocop

rubocopA:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml -A

db-psql:
docker compose run --rm app psql -d ${POSTGRES_DB} -U ${POSTGRES_USER} -W -h db

db-prepare: db-drop db-create db-migrate db-seed

db-create:
docker compose run --rm app bin/rails db:create RAILS_ENV=development

db-migrate:
docker compose run --rm app bin/rails db:migrate

db-rollback:
docker compose run --rm app bin/rails db:rollback

db-seed:
docker compose run --rm app bin/rails db:seed

db-reset:
docker compose run --rm app bin/rails db:reset

db-drop:
docker compose run --rm app bin/rails db:drop

ci-build:
bundle lock --update
npm install --package-lock-only
docker compose build -q

ci-up-healthy: db-prepare
docker compose up -d --wait --wait-timeout 60

ci-rubocop: rubocop

ci-clear: clear
1 change: 0 additions & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
web: env RUBY_DEBUG_OPEN=true RUBY_DEBUG_PORT=12345 RUBY_DEBUG_HOST=0.0.0.0 bin/rails server -b 0.0.0.0 -p3000
js: yarn build --watch
css: yarn watch:css
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Where Are My Likes - это сервис, помогающий пользова

- `make setup` - сборка и конфигурация всех контейнеров, необходимых для работы приложения;
- `make up` - запуск всех контейнеров и приложения;
- `make deps` - обновить lock-файлы и установить зависимости локально (необходимы bundle и yarn);
- `make down` - удаление контейнеров приложения;
- `make clear` - удаление контейнеров/образов/волюмов/сетей и прочего, связанных с приложением;
- `make ash` - запуск терминала в контейнере приложения;
Expand Down
2 changes: 2 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
//= link_tree ../images
//= link_tree ../builds
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
16 changes: 1 addition & 15 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
/* Application styles */
vzalygin marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Entry point for the build script in your package.json
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "./controllers"
import * as bootstrap from "bootstrap"
import "controllers"
vzalygin marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 11 additions & 5 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName
// Import and register all your controllers from the importmap under controllers/*

import { application } from "./application"

import HelloController from "./hello_controller"
application.register("hello", HelloController)
import VkidController from "./vkid_controller"

// Eager load all controllers defined in the import map under controllers/**/*_controller
// import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
// eagerLoadControllersFrom("controllers", application)

application.register("hello", HelloController)
application.register("vkid", VkidController)

// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)
Loading
Loading