- Bump Rails 7.0.2.2 by okonomi · Pull Request #1553 · okonomi/blg
- update ruby 3.1 by okonomi · Pull Request #1554 · okonomi/blg
アップデート後アプリが起動しない現象があったりで動作確認するのにHerokuのReview Appにだいぶ助けられた。
2022-03-05 15:56
2021-09-04 10:45
❯ sw_vers ProductName: macOS ProductVersion: 11.5.2 BuildVersion: 20G95 ❯ clang -v Apple clang version 12.0.5 (clang-1205.0.22.11) Target: arm64-apple-darwin20.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
❯ brew install xxhash openssl cmake ❯ export CPLUS_INCLUDE_PATH=(brew --prefix xxhash)/include:(brew --prefix openssl)/include ❯ export LIBRARY_PATH=(brew --prefix xxhash)/lib:(brew --prefix openssl)/lib ❯ make EXTRA_LDFLAGS="-lcrypto"
❯ pwd /Users/okonomi/src/github.com/rui314/mold
❯ make clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/arch-aarch64.o elf/arch-aarch64.cc In file included from elf/arch-aarch64.cc:1: elf/mold.h:33:10: fatal error: 'xxh3.h' file not found #include <xxh3.h> ^~~~~~~~ 1 error generated. make: *** [elf/arch-aarch64.o] Error 1
❯ brew install xxhash
❯ export CPLUS_INCLUDE_PATH=(brew --prefix xxhash)/include
❯ make clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/arch-aarch64.o elf/arch-aarch64.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/arch-i386.o elf/arch-i386.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/arch-x86-64.o elf/arch-x86-64.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/archive-file.o elf/archive-file.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/cmdline.o elf/cmdline.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/compress.o elf/compress.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/concurrent-map.o elf/concurrent-map.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/filepath.o elf/filepath.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/gc-sections.o elf/gc-sections.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/hyperloglog.o elf/hyperloglog.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/icf.o elf/icf.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/input-sections.o elf/input-sections.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/linker-script.o elf/linker-script.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/main.o elf/main.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/mapfile.o elf/mapfile.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/memory-mapped-file.o elf/memory-mapped-file.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/object-file.o elf/object-file.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/output-chunks.o elf/output-chunks.cc elf/output-chunks.cc:3:10: fatal error: 'openssl/rand.h' file not found #include <openssl/rand.h> ^~~~~~~~~~~~~~~~ 1 error generated. make: *** [elf/output-chunks.o] Error 1
❯ brew install openssl
❯ export CPLUS_INCLUDE_PATH=(brew --prefix xxhash)/include:(brew --prefix openssl)/include
❯ make clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/output-chunks.o elf/output-chunks.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/output-file.o elf/output-file.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/passes.o elf/passes.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/perf.o elf/perf.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/relocatable.o elf/relocatable.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/subprocess.o elf/subprocess.cc elf/subprocess.cc:186:7: warning: 'daemon' is deprecated: first deprecated in macOS 10.5 - Use posix_spawn APIs instead. [-Wdeprecated-declarations] if (daemon(1, 0) == -1) ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:292:6: note: 'daemon' has been explicitly marked deprecated here int daemon(int, int) __DARWIN_1050(daemon) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_0, __MAC_10_5, __IPHONE_2_0, __IPHONE_2_0, "Use posix_spawn APIs instead.") __WATCHOS_PROHIBITED __TVOS_PROHIBITED; ^ 1 warning generated. clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/symbols.o elf/symbols.cc clang++ -g -pthread -std=c++20 -fPIE -DMOLD_VERSION=\"0.9.4\" -DGIT_HASH=\"b4953951f0f09d163ca3560baf88396bef5c02c5\" -O2 -Ithird-party/tbb/include -c -o elf/tar.o elf/tar.cc mkdir -p out/tbb (cd out/tbb; cmake -G'Unix Makefiles' -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS=-D__TBB_DYNAMIC_LOAD_ENABLED=0 -DTBB_STRICT=OFF ../../third-party/tbb) /bin/sh: cmake: command not found make: *** [out/tbb/libs/libtbb.a] Error 127
cmake
コマンドがない。これもhomebrewでインストール:❯ brew install cmake
❯ make mkdir -p out/tbb (cd out/tbb; cmake -G'Unix Makefiles' -DBUILD_SHARED_LIBS=OFF -DTBB_TEST=OFF -DCMAKE_CXX_FLAGS=-D__TBB_DYNAMIC_LOAD_ENABLED=0 -DTBB_STRICT=OFF ../../third-party/tbb) -- The CXX compiler identification is AppleClang 12.0.5.12050022 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning at CMakeLists.txt:109 (message): You are building oneTBB as a static library. This is highly discouraged and such configuration is not supported. Consider building a dynamic library to avoid unforeseen issues. -- CMAKE_BUILD_TYPE is not specified. Using default: RelWithDebInfo -- Looking for C++ include pthread.h -- Looking for C++ include pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Checking for one of the modules 'hwloc' -- TBBBind build target is disabled due to unsupported environment -- Configuring done -- Generating done -- Build files have been written to: /Users/okonomi/src/github.com/rui314/mold/out/tbb /Library/Developer/CommandLineTools/usr/bin/make -C out/tbb tbb [ 3%] Building CXX object src/tbb/CMakeFiles/tbb.dir/address_waiter.cpp.o [ 6%] Building CXX object src/tbb/CMakeFiles/tbb.dir/allocator.cpp.o [ 10%] Building CXX object src/tbb/CMakeFiles/tbb.dir/arena.cpp.o [ 13%] Building CXX object src/tbb/CMakeFiles/tbb.dir/arena_slot.cpp.o [ 17%] Building CXX object src/tbb/CMakeFiles/tbb.dir/concurrent_bounded_queue.cpp.o [ 20%] Building CXX object src/tbb/CMakeFiles/tbb.dir/dynamic_link.cpp.o [ 24%] Building CXX object src/tbb/CMakeFiles/tbb.dir/exception.cpp.o [ 27%] Building CXX object src/tbb/CMakeFiles/tbb.dir/governor.cpp.o [ 31%] Building CXX object src/tbb/CMakeFiles/tbb.dir/global_control.cpp.o [ 34%] Building CXX object src/tbb/CMakeFiles/tbb.dir/itt_notify.cpp.o [ 37%] Building CXX object src/tbb/CMakeFiles/tbb.dir/main.cpp.o [ 41%] Building CXX object src/tbb/CMakeFiles/tbb.dir/market.cpp.o [ 44%] Building CXX object src/tbb/CMakeFiles/tbb.dir/misc.cpp.o [ 48%] Building CXX object src/tbb/CMakeFiles/tbb.dir/misc_ex.cpp.o [ 51%] Building CXX object src/tbb/CMakeFiles/tbb.dir/observer_proxy.cpp.o [ 55%] Building CXX object src/tbb/CMakeFiles/tbb.dir/parallel_pipeline.cpp.o [ 58%] Building CXX object src/tbb/CMakeFiles/tbb.dir/private_server.cpp.o [ 62%] Building CXX object src/tbb/CMakeFiles/tbb.dir/profiling.cpp.o [ 65%] Building CXX object src/tbb/CMakeFiles/tbb.dir/rml_tbb.cpp.o [ 68%] Building CXX object src/tbb/CMakeFiles/tbb.dir/rtm_mutex.cpp.o [ 72%] Building CXX object src/tbb/CMakeFiles/tbb.dir/rtm_rw_mutex.cpp.o [ 75%] Building CXX object src/tbb/CMakeFiles/tbb.dir/semaphore.cpp.o [ 79%] Building CXX object src/tbb/CMakeFiles/tbb.dir/small_object_pool.cpp.o [ 82%] Building CXX object src/tbb/CMakeFiles/tbb.dir/task.cpp.o [ 86%] Building CXX object src/tbb/CMakeFiles/tbb.dir/task_dispatcher.cpp.o [ 89%] Building CXX object src/tbb/CMakeFiles/tbb.dir/task_group_context.cpp.o [ 93%] Building CXX object src/tbb/CMakeFiles/tbb.dir/version.cpp.o [ 96%] Building CXX object src/tbb/CMakeFiles/tbb.dir/queuing_rw_mutex.cpp.o [100%] Linking CXX static library ../../appleclang_12.0_cxx11_64_relwithdebinfo/libtbb.a [100%] Built target tbb (cd out/tbb; ln -sf *_relwithdebinfo libs) clang++ elf/arch-aarch64.o elf/arch-i386.o elf/arch-x86-64.o elf/archive-file.o elf/cmdline.o elf/compress.o elf/concurrent-map.o elf/filepath.o elf/gc-sections.o elf/hyperloglog.o elf/icf.o elf/input-sections.o elf/linker-script.o elf/main.o elf/mapfile.o elf/memory-mapped-file.o elf/object-file.o elf/output-chunks.o elf/output-file.o elf/passes.o elf/perf.o elf/relocatable.o elf/subprocess.o elf/symbols.o elf/tar.o -o mold -L/opt/homebrew/opt/xxhash/lib -pthread -lz -lxxhash -ldl -lm out/tbb/libs/libtbb.a Undefined symbols for architecture arm64: "_RAND_bytes", referenced from: mold::elf::BuildIdSection<mold::elf::X86_64>::write_buildid(mold::elf::Context<mold::elf::X86_64>&) in output-chunks.o mold::elf::BuildIdSection<mold::elf::I386>::write_buildid(mold::elf::Context<mold::elf::I386>&) in output-chunks.o mold::elf::BuildIdSection<mold::elf::AARCH64>::write_buildid(mold::elf::Context<mold::elf::AARCH64>&) in output-chunks.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [mold] Error 1
_RAND_bytes
というシンボルが見つからない?❯ export LIBRARY_PATH=(brew --prefix xxhash)/lib:(brew --prefix openssl)/lib
❯ make clang++ elf/arch-aarch64.o elf/arch-i386.o elf/arch-x86-64.o elf/archive-file.o elf/cmdline.o elf/compress.o elf/concurrent-map.o elf/filepath.o elf/gc-sections.o elf/hyperloglog.o elf/icf.o elf/input-sections.o elf/linker-script.o elf/main.o elf/mapfile.o elf/memory-mapped-file.o elf/object-file.o elf/output-chunks.o elf/output-file.o elf/passes.o elf/perf.o elf/relocatable.o elf/subprocess.o elf/symbols.o elf/tar.o -o mold -pthread -lz -lxxhash -ldl -lm out/tbb/libs/libtbb.a Undefined symbols for architecture arm64: "_RAND_bytes", referenced from: mold::elf::BuildIdSection<mold::elf::X86_64>::write_buildid(mold::elf::Context<mold::elf::X86_64>&) in output-chunks.o mold::elf::BuildIdSection<mold::elf::I386>::write_buildid(mold::elf::Context<mold::elf::I386>&) in output-chunks.o mold::elf::BuildIdSection<mold::elf::AARCH64>::write_buildid(mold::elf::Context<mold::elf::AARCH64>&) in output-chunks.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [mold] Error 1
clang++
の引数を見るとopensslのライブラリが指定されてないみたい。EXTRA_LDFLAGS
で追加の引数を渡せるらしい。❯ make EXTRA_LDFLAGS="-lcrypto" clang++ elf/arch-aarch64.o elf/arch-i386.o elf/arch-x86-64.o elf/archive-file.o elf/cmdline.o elf/compress.o elf/concurrent-map.o elf/filepath.o elf/gc-sections.o elf/hyperloglog.o elf/icf.o elf/input-sections.o elf/linker-script.o elf/main.o elf/mapfile.o elf/memory-mapped-file.o elf/object-file.o elf/output-chunks.o elf/output-file.o elf/passes.o elf/perf.o elf/relocatable.o elf/subprocess.o elf/symbols.o elf/tar.o -o mold -lcrypto -pthread -lz -lxxhash -ldl -lm out/tbb/libs/libtbb.a ln -sf mold ld clang -fPIC -shared -o mold-wrapper.so elf/mold-wrapper.c -ldl
❯ ./mold -v mold 0.9.4 (b4953951f0f09d163ca3560baf88396bef5c02c5; compatible with GNU ld and GNU gold)
2021-06-29 12:19
assets:precompile
でwebpackerの処理も動く。assets:precompile
だけ動かしたかったので方法がないか調べた。rm bin/yarn WEBPACKER_PRECOMPILE=false bin/rails assets:precompile
❯ bin/rails assets:precompile yarn install v1.22.10 [1/4] 🔍 Resolving packages... success Already up-to-date. ✨ Done in 0.19s. Compiling... Compiled all packs in /Users/okonomi/src/local/rails-webpacker-sandbox/public/packs Hash: e4cb1aa40fed2663ee2c Version: webpack 4.46.0 Time: 446ms Built at: 2021/06/29 21:03:08 Asset Size Chunks Chunk Names js/application-c3e3aae48c4c321181e9.js 69.4 KiB 0 [emitted] [immutable] application js/application-c3e3aae48c4c321181e9.js.br 15.4 KiB [emitted] js/application-c3e3aae48c4c321181e9.js.gz 17.8 KiB [emitted] js/application-c3e3aae48c4c321181e9.js.map 205 KiB 0 [emitted] [dev] application js/application-c3e3aae48c4c321181e9.js.map.br 43.8 KiB [emitted] js/application-c3e3aae48c4c321181e9.js.map.gz 50.9 KiB [emitted] manifest.json 364 bytes [emitted] manifest.json.br 133 bytes [emitted] manifest.json.gz 142 bytes [emitted] Entrypoint application = js/application-c3e3aae48c4c321181e9.js js/application-c3e3aae48c4c321181e9.js.map [0] (webpack)/buildin/module.js 552 bytes {0} [built] [4] ./app/javascript/packs/application.js 480 bytes {0} [built] [5] ./app/javascript/channels/index.js 205 bytes {0} [built] [6] ./app/javascript/channels sync _channel\.js$ 160 bytes {0} [built] + 3 hidden modules
❯ bin/rails assets:precompile --trace ** Invoke assets:precompile (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Invoke yarn:install (first_time) ** Execute yarn:install yarn install v1.22.10 [1/4] 🔍 Resolving packages... success Already up-to-date. ✨ Done in 0.19s. ** Execute assets:precompile ** Invoke webpacker:compile (first_time) ** Invoke webpacker:verify_install (first_time) ** Invoke webpacker:check_node (first_time) ** Execute webpacker:check_node ** Invoke webpacker:check_yarn (first_time) ** Execute webpacker:check_yarn ** Invoke webpacker:check_binstubs (first_time) ** Execute webpacker:check_binstubs ** Execute webpacker:verify_install ** Invoke environment ** Execute webpacker:compile Everything's up-to-date. Nothing to do
yarn:install
とかwebpacker系のタスクが動いてる。❯ env WEBPACKER_PRECOMPILE=false bin/rails assets:precompile --trace ** Invoke assets:precompile (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Invoke yarn:install (first_time) ** Execute yarn:install yarn install v1.22.10 [1/4] 🔍 Resolving packages... success Already up-to-date. ✨ Done in 0.19s. ** Execute assets:precompile
yarn:install
がどこから呼ばれるのかソースコードを検索:❯ grep -r "yarn:install" .bundle/ruby/3.0.0/gems .bundle/ruby/3.0.0/gems/railties-6.1.4/lib/rails/tasks/yarn.rake: Rake::Task["assets:precompile"].enhance [ "yarn:install" ] .bundle/ruby/3.0.0/gems/webpacker-5.4.0/docs/engines.md: # yarn:install was added in Rails 5.1 .bundle/ruby/3.0.0/gems/webpacker-5.4.0/lib/tasks/webpacker/compile.rake: # yarn:install was added in Rails 5.1
lib/rails/tasks/yarn.rake
を見る:# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use. if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn")) Rake::Task["assets:precompile"].enhance [ "yarn:install" ] end
assets:precompile
タスクが定義されているのとbin/yarn
が存在する場合にyarn:install
が呼ばれるようになってる。bin/yarn
を消してみる:❯ rm bin/yarn ❯ WEBPACKER_PRECOMPILE=false bin/rails assets:precompile --trace ** Invoke assets:precompile (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Execute assets:precompile
yarn:install
が呼ばれなくなった!assets:precompile
だけ動かしたい場合は、以下のようにする:bin/yarn
を削除するWEBPACKER_PRECOMPILE=false
を設定するbin/yarn
の存在チェックはなかった:# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use. if Rake::Task.task_defined?("assets:precompile") Rake::Task["assets:precompile"].enhance [ "yarn:install" ] end
2021-06-12 07:53
~/.gem/ruby/3.0.0
を削除すると解決した。❯ asdf install ruby 3.0.1 Downloading openssl-1.1.1k.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5 Installing openssl-1.1.1k... Installed openssl-1.1.1k to /Users/okonomi/.asdf/installs/ruby/3.0.1 Downloading ruby-3.0.1.tar.gz... -> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz Installing ruby-3.0.1... ruby-build: using readline from homebrew BUILD FAILED (macOS 11.4 using ruby-build 20210423) Inspect or clean up the working tree at /var/folders/z3/9l1cmgy92175ph5q9dxg9h080000gp/T/ruby-build.20210612170008.31086.JdPjRE Results logged to /var/folders/z3/9l1cmgy92175ph5q9dxg9h080000gp/T/ruby-build.20210612170008.31086.log Last 10 log lines: The Ruby yaml extension was not compiled. ERROR: Ruby install aborted due to missing extensions Configure options used: --prefix=/Users/okonomi/.asdf/installs/ruby/3.0.1 --with-openssl-dir=/Users/okonomi/.asdf/installs/ruby/3.0.1/openssl --enable-shared --with-readline-dir=/opt/homebrew/opt/readline CC=clang LDFLAGS=-L/Users/okonomi/.asdf/installs/ruby/3.0.1/lib CPPFLAGS=-I/Users/okonomi/.asdf/installs/ruby/3.0.1/include
❯ tail -n 20 /var/folders/z3/9l1cmgy92175ph5q9dxg9h080000gp/T/ruby-build.20210612170008.31086.log power_assert 1.2.0 rake 13.0.3 test-unit 3.3.7 rexml 3.2.5 rss 0.2.9 rbs 1.0.4 typeprof 0.12.0 installing bundled gem cache: /Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/cache /Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. The Ruby yaml extension was not compiled. ERROR: Ruby install aborted due to missing extensions Configure options used: --prefix=/Users/okonomi/.asdf/installs/ruby/3.0.1 --with-openssl-dir=/Users/okonomi/.asdf/installs/ruby/3.0.1/openssl --enable-shared --with-readline-dir=/opt/homebrew/opt/readline CC=clang LDFLAGS=-L/Users/okonomi/.asdf/installs/ruby/3.0.1/lib CPPFLAGS=-I/Users/okonomi/.asdf/installs/ruby/3.0.1/include
failed = %w[openssl readline zlib yaml].reject do |lib| begin require lib rescue LoadError $stderr.puts "The Ruby #{lib} extension was not compiled." end end
require 'yaml'
がエラーになる?実際そうなるか試してみる。❯ vi ~/.asdf/plugins/ruby/ruby-build/share/ruby-build/3.0.1 install_package "openssl-1.1.1k" "https://www.openssl.org/source/openssl-1.1.1k.tar.gz#892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5" mac_openssl --if has_broken_mac_openssl install_package "ruby-3.0.1" "https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz#369825db2199f6aeef16b408df6a04ebaddb664fb9af0ec8c686b0ce7ab77727" ldflags_dirs enable_shared standard
❯ asdf install ruby 3.0.1 Downloading openssl-1.1.1k.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5 Installing openssl-1.1.1k... Installed openssl-1.1.1k to /Users/okonomi/.asdf/installs/ruby/3.0.1 Downloading ruby-3.0.1.tar.gz... -> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz Installing ruby-3.0.1... ruby-build: using readline from homebrew Installed ruby-3.0.1 to /Users/okonomi/.asdf/installs/ruby/3.0.1 ❯ asdf global ruby 3.0.1 ❯ ruby -v ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [arm64-darwin20]
require 'yaml'
を試す:❯ irb <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': incompatible library version - /Users/okonomi/.gem/ruby/3.0.0/gems/io-console-0.5.9/lib/io/console.bundle (LoadError) from <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from /Users/okonomi/.gem/ruby/3.0.0/gems/reline-0.2.5/lib/reline.rb:1:in `<top (required)>' from <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from /Users/okonomi/.gem/ruby/3.0.0/gems/irb-1.3.5/lib/irb.rb:13:in `<top (required)>' from <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from <internal:/Users/okonomi/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from /Users/okonomi/.gem/ruby/3.0.0/gems/irb-1.3.5/exe/irb:9:in `<top (required)>' from /Users/okonomi/.asdf/installs/ruby/3.0.1/bin/irb:23:in `load' from /Users/okonomi/.asdf/installs/ruby/3.0.1/bin/irb:23:in `<main>'
irb
が起動できない…?incompatible library version
と言われてるgemをディレクトリごとどかしてみる:❯ mv ~/.gem/ruby/3.0.0 ~/.gem/ruby/3.0.0_
❯ irb irb(main):001:0> require 'yaml' => true
irb
が起動してrequire
も成功した。❯ vi ~/.asdf/plugins/ruby/ruby-build/share/ruby-build/3.0.1 ❯ asdf uninstall ruby 3.0.1 ❯ asdf install ruby 3.0.1 Downloading openssl-1.1.1k.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5 Installing openssl-1.1.1k... Installed openssl-1.1.1k to /Users/okonomi/.asdf/installs/ruby/3.0.1 Downloading ruby-3.0.1.tar.gz... -> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz Installing ruby-3.0.1... ruby-build: using readline from homebrew Installed ruby-3.0.1 to /Users/okonomi/.asdf/installs/ruby/3.0.1
2021-02-09 13:58
render
にrender_in
メソッドを持つオブジェクトを渡せるようになった、だけだった:class ViewComponent def render_in(view_context) 'hello' end end
<%= render ViewComponent.new %>
RenderingHelper
supports rendering objects thatrespond_to?
:render_in
.
render_in
メソッドを実装してる:render_in
メソッドを定義したクラスを作るパターンでどうなるか、試してみたい。2021-02-02 13:04
2021-01-03 09:15
2020-12-31 03:18
Gemfile
のrailsのバージョンを6.1に変更:gem "rails", "6.1.0"
bundle install
bin/rails app:update
bin/rails db:migrate
app:update
で反映されなかったファイルを手で反映していく。2020-10-29 12:59
2020-10-26 14:33
2020-09-29 14:51
screenshots
テーブル作るの無駄かなと思ってフォームオブジェクトにして一覧表示はS3バケットのオブジェクト一覧取得でと思ったけど、付加情報の保存とか拡張性とか考えて普通にテーブル作る形に戻した。node_modules
が別途デプロイされるようになって、package.json
に更新がなければデプロイをスキップするのでデプロイサイクルが速くなってよかった。serverless.yml
じゃなくserverless.ts
になっててびっくりした。2020-04-20 13:02
2020-04-12 13:03
2020-04-12T12:04:23.599633+00:00 app[web.1]: I, [2020-04-12T21:04:23.599545 #3] INFO -- : [14cc8621-cf83-41f0-bc6f-a6ce692ec238] Started POST "/auth/github?origin=https://oknm.jp/auth" for 175.131.16.228 at 2020-04-12 21:04:23 +0900 2020-04-12T12:04:23.600394+00:00 app[web.1]: I, [2020-04-12T21:04:23.600343 #3] INFO -- : [14cc8621-cf83-41f0-bc6f-a6ce692ec238] (github) Request phase initiated. 2020-04-12T12:04:23.604646+00:00 heroku[router]: at=info method=POST path="/auth/github?origin=https://oknm.jp/auth" host=oknm.jp request_id=14cc8621-cf83-41f0-bc6f-a6ce692ec238 fwd="175.131.16.228" dyno=web.1 connect=1ms service=8ms status=302 bytes=1307 protocol=http 2020-04-12T12:04:24.167130+00:00 heroku[router]: at=info method=GET path="/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=adaf9f33d654c539841482c559e8b4b77c46a2f239aa5efa" host=oknm.jp request_id=58139b4d-7aa9-41b7-9037-6436dc4f6c24 fwd="175.131.16.228" dyno=web.1 connect=1ms service=8ms status=302 bytes=816 protocol=https 2020-04-12T12:04:24.162186+00:00 app[web.1]: I, [2020-04-12T21:04:24.162082 #3] INFO -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] Started GET "/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=adaf9f33d654c539841482c559e8b4b77c46a2f239aa5efa" for 175.131.16.228 at 2020-04-12 21:04:24 +0900 2020-04-12T12:04:24.163086+00:00 app[web.1]: I, [2020-04-12T21:04:24.163019 #3] INFO -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] (github) Callback phase initiated. 2020-04-12T12:04:24.163635+00:00 app[web.1]: E, [2020-04-12T21:04:24.163560 #3] ERROR -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] (github) Authentication failure! redirect_uri_mismatch: OmniAuth::Strategies::OAuth2::CallbackError, redirect_uri_mismatch | The redirect_uri MUST match the registered callback URL for this application. | https://developer.github.com/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch 2020-04-12T12:04:24.364745+00:00 app[web.1]: I, [2020-04-12T21:04:24.364644 #3] INFO -- : [54454333-96e9-4f35-9fd3-606895a438f2] Started GET "/auth/failure?message=redirect_uri_mismatch&origin=https%3A%2F%2Foknm.jp%2Fauth&strategy=github" for 175.131.16.228 at 2020-04-12 21:04:24 +0900
redirect_uri_mismatch
とのこと。前まで動いてたのになぜ…。OmniAuth.config.full_host
を設定すればいいらしい?2019-12-30 14:11
2019-12-29 14:12
$ xcode-select --print-path /Applications/Xcode.app/Contents/Developer
$ sudo xcode-select --switch /Library/Developer/CommandLineTools/
$ xcode-select --print-path /Library/Developer/CommandLineTools
2019-12-21 05:18
2019-12-08 08:36
2019-06-23 06:14
ENV["SECRET_KEY_BASE"]
config/credentials.yml.enc
config/secrets.yml
(Encrypted secretsが有効ならconfig/secrets.yml.enc
)tmp/development_secret.txt
tmp/development_secret.txt
の順Rails.applicatin.secret_key_base #=> "bb7a320962dda4262e21262f80229946f5a3b3c05cc8968d71d1ae9e40c64b5d7afb5340c196134089590b69d8a51a05ee801217b90eb859236bf4b14f8d5a76"
Rails::Application
にメソッドとして定義されている。module Rails # snip class Application < Engine # snip def secret_key_base if Rails.env.development? || Rails.env.test? secrets.secret_key_base ||= generate_development_secret else validate_secret_key_base( ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || secrets.secret_key_base ) end end end end
secrets.secret_key_base
が未設定なら、generate_development_secret
を実行し結果をsecrets.secret_key_base
に保存するsecrets.secret_key_base
を返すENV["SECRET_KEY_BASE"]
、credentials.secret_key_base
、secrets.secret_key_base
の順番で評価してバリデーションした上で結果を返すRails::Application#secrets
が定義されてる。def secrets @secrets ||= begin secrets = ActiveSupport::OrderedOptions.new files = config.paths["config/secrets"].existent files = files.reject { |path| path.end_with?(".enc") } unless config.read_encrypted_secrets secrets.merge! Rails::Secrets.parse(files, env: Rails.env) # Fallback to config.secret_key_base if secrets.secret_key_base isn't set secrets.secret_key_base ||= config.secret_key_base secrets end end
config/secrets.yml
を読み込むconfig/secrets.yml.enc
を読み込むconfig/secrets.yml
にsecret_key_baseが未定義ならconfig
から読み込むconfig/secrets.yml
はRails 4.1で導入されたようなので、それ以前はconfig/application.rb
とかに書いてたのかな?def generate_development_secret if secrets.secret_key_base.nil? key_file = Rails.root.join("tmp/development_secret.txt") if !File.exist?(key_file) random_key = SecureRandom.hex(64) FileUtils.mkdir_p(key_file.dirname) File.binwrite(key_file, random_key) end secrets.secret_key_base = File.binread(key_file) end secrets.secret_key_base end
tmp/development_secret.txt
を自動生成してその内容を返すらしい。へー。2019-06-15 11:34
<code class="ruby">
みたいに言語を指定したりできないけど、highlight.jsは勝手に言語を判別してなんとなくいい感じに色付けしてくれるので楽。class User < ApplicationRecord before_create :set_remember_token private def set_remember_token self.remember_token = generate_remember_token end def generate_remember_token SecureRandom.hex(20) end end
<!DOCTYPE html> <html> <head> <title>Sample</title> </head> <body> <p>Hello</p> </body> </html>
2019-06-14 13:47
WEBPACKER_DEV_SERVER_HOST
でRailsにwebpack-dev-serverの居場所を教えてあげる形にした。version: "3.7" services: web: &app_base build: . ports: - "3000:3000" volumes: - .:/app - bundle:/app/.bundle - node_modules:/app/node_modules - home:/root environment: BUNDLE_PATH: /app/.bundle BUNDLE_JOBS: 4 WEBPACKER_DEV_SERVER_HOST: webpacker command: /bin/sh -c "rm -f tmp/pids/server.pid && bin/rails s -p 3000 -b '0.0.0.0'" depends_on: - db webpacker: <<: *app_base ports: - "3035:3035" command: bin/webpack-dev-server db: image: postgres:11.2 ports: - "5432:5432" volumes: - pg_data:/data environment: PGDATA: /data volumes: bundle: node_modules: pg_data: home:
2019-06-07 09:38
2019-06-06 12:12
heroku
コマンドで切り替え:heroku stack:set container -a oknmjp
app.json
の指定を変更:{ "stack": "container" }
heroku.yml
を作る:build: docker: web: Dockerfile.production config: GITHUB_OAUTH_CLIENT_KEY: xxx GITHUB_OAUTH_CLIENT_SECRET: xxx SECRET_KEY_BASE: xxx release: image: web command: - bin/rails db:prepare run: web: bin/rails server -p $PORT
Dockerfile.production
をいい感じに用意する。bin/rails assets:precompile
を実行しているが、SECRET_KEY_BASE
を設定する必要があった$PORT
で指定しないといけないSECRET_KEY_BASE
とかの漏洩しちゃいけない値はどうDockerに渡せばいいのか2019-06-02 08:11
FROM ruby:2.6.3-alpine3.9 AS builder ENV RAILS_ENV production WORKDIR /app RUN apk add --update --no-cache \ build-base \ libxml2-dev \ libxslt-dev \ sqlite-dev \ nodejs \ yarn \ tzdata # install gems RUN gem install bundler COPY Gemfile . COPY Gemfile.lock . RUN bundle install --clean --frozen --jobs $(nproc) --without development test # install npm packages COPY package.json . COPY yarn.lock . RUN yarn install --frozen-lockfile # compile assets COPY Rakefile . COPY bin bin COPY .browserslistrc . COPY postcss.config.js . COPY babel.config.js . COPY config config COPY app/assets app/assets COPY app/javascript app/javascript RUN bin/rails assets:precompile FROM ruby:2.6.3-alpine3.9 ENV RAILS_ENV production ENV RAILS_LOG_TO_STDOUT 1 ENV RAILS_SERVE_STATIC_FILES 1 WORKDIR /app RUN apk add --update --no-cache \ sqlite-libs \ tzdata COPY --from=builder /usr/local/bundle /usr/local/bundle COPY --from=builder /app/public/assets /app/public/assets COPY --from=builder /app/public/packs /app/public/packs COPY . . RUN bin/rails db:schema:load EXPOSE 3000 ENTRYPOINT ["bin/rails"]
.dockerignore
はこうした:.bundle .dockerignore .git .gitignore Dockerfile log node_modules public/assets public/packs README.md storage test tmp
assets:precompile
を行う。2019-06-02 08:05
<title>
タグに個別のタイトルを表示するようにした。2019-05-18 13:51
<textarea>
ではなく、JSでテキスト入力をトラップして処理してる(らしい)ので、capybaraでフォームの入力をしようとしても普通のやり方だとうまくいかなかった。page.execute_script
でJSを実行して文字列をリッチテキストエディタに入力させるらしい。なるほど。2019-05-12 13:22
bin/
以下のファイルで引っかかるけど自分で作ったファイルじゃないので除外設定した。inherit_mode
を指定する。inherit_mode: merge: - Exclude AllCops: Exclude: - "bin/*"
2019-05-12 10:03
<code>
タグの機能がなかったので付けた。Trix.config.textAttributes
に要素を追加するのと、Trix.config.toolbar.getDefaultHTML
を置き換えたらできた。2019-05-11 14:18
2019-05-11 13:30
rescue
にelse
を指定できるとかensure
でreturn
しちゃいけないとか知らなかった。2019-05-11 10:27
<input>
にtype="datetime-local"
があるの知らなかった。config.time_zone
を設定しておけばよさそうと理解した。TZ
環境変数も設定しておいた。2019-05-11 06:00
<select multiple>
にした。2019-05-09 15:00
BLOG_TITLE
環境変数で設定できるようにした。2019-05-08 15:00
# c.f. https://dependabot.com/docs/config-file/ version: 1 update_configs: - package_manager: "ruby:bundler" directory: "/" update_schedule: "daily" allowed_updates: - match: update_type: "all" automerged_updates: - match: dependency_type: "development" update_type: "all" - match: dependency_type: "production" update_type: "semver:patch" version_requirement_updates: "off" - package_manager: "javascript" directory: "/" update_schedule: "daily" allowed_updates: - match: update_type: "all" automerged_updates: - match: dependency_type: "development" update_type: "all" - match: dependency_type: "production" update_type: "semver:patch" version_requirement_updates: "off"
2019-05-05 15:00
2019-05-02 15:00
2019-05-01 15:00
2019-04-30 15:00
2019-03-30 15:00
2019-02-09 15:00
$ mkdir awesome-rails-app $ cd awesome-rails-app
$ bundle init
Gemfile
に追加:$ bundle add rails --skip-install
vendor/bundle
以下にインストール:$ bundle install --path=vendor/bundle -j4
vendor/bundle
にインストールしたRailsを使ってrails new
実行(-f
オプションでファイル上書き):$ bundle exec rails new . -f
/vendor/bundle
をGit管理から除外:echo /vendor/bundle >> .gitignore