momocus / sakazuki

自宅の酒を管理するアプリケーション
https://sakazuki.fly.dev/
MIT License
13 stars 4 forks source link

fly deployに失敗する #713

Closed momocus closed 1 month ago

momocus commented 1 month ago

💡 Summary

fly deployに失敗する

https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459

📝 再現方法

main ブランチにpush

🥰 理想

fly deployに成功してサービスが動く

🤬 現実

fly deployに失敗してサービスが動かない

momocus commented 1 month ago

原因はこれっぽい

https://community.fly.io/t/error-after-deploy-warn-could-not-unmount-rootfs-einval-invalid-argument/19624

yonta commented 1 month ago

エラー全文

Run flyctl deploy --remote-only --dockerfile fly.Dockerfile
==> Verifying app config
--> Verified app config
Validating /home/runner/work/sakazuki/sakazuki/fly.toml
✓ Configuration is valid
==> Building image
Waiting for remote builder fly-builder-dawn-star-3[6](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:7)45...

Remote builder fly-builder-dawn-star-3645 ready
Waiting for remote builder fly-builder-dawn-star-3645...

Remote builder fly-builder-dawn-star-3645 ready
==> Building image with Docker
--> docker host: 24.0.[7](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:8) linux x86_64
#1 [internal] load .dockerignore
#1 DONE 0.0s

#2 [internal] load build definition from fly.Dockerfile
#2 transferring dockerfile:
#2 transferring dockerfile: 4.45kB 0.0s done
#2 DONE 0.0s

#1 [internal] load .dockerignore
#1 transferring context: 393B 0.0s done
#1 DONE 0.0s

#3 resolve image config for docker.io/docker/dockerfile:experimental
#3 DONE 0.1s

#4 docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff33[8](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:9)b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e78496ff5
#4 CACHED

#5 [internal] load build definition from fly.Dockerfile
#5 DONE 0.0s

#6 [internal] load .dockerignore
#6 DONE 0.0s

#7 [internal] load metadata for quay.io/evl.ms/fullstaq-ruby:3.2.2-jemalloc-slim
#7 DONE 0.1s

#8 [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.2.2-jemalloc-slim@sha256:8b5ab545356385c63d844abdc0e61a4ca5a118b6736c[9](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:10)8e1c9de176374727270
#8 DONE 0.0s

#9 [internal] load build context
#9 transferring context: 3.34MB 3.1s done
#9 DONE 3.1s

#[10](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:11) [base 2/6] RUN mkdir /app
#10 CACHED

#[11](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:12) [base 3/6] WORKDIR /app
#11 CACHED

#12 [base 5/6] RUN curl https://get.volta.sh | bash
#[12](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:13) CACHED

#[13](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:14) [base 6/6] RUN volta install node@18.* yarn@3.1.1 &&     gem update --system --no-document &&     gem install -N bundler -v 2.3.25
#13 CACHED

#[14](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:15) [base 4/6] RUN mkdir -p tmp/pids
#14 CACHED

#15 [build_deps 1/1] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential=12.9 libpq-dev=13.*     && rm -rf /var/lib/apt/lists /var/cache/apt/archives
#[15](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:16) CACHED

#[16](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:17) [node_modules 1/3] COPY package.json yarn.lock .yarnrc.yml ./
#16 DONE 0.0s

#[17](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:18) [node_modules 2/3] COPY .yarn/releases/ ./.yarn/releases/
#17 DONE 0.0s

#[18](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:19) [node_modules 3/3] RUN yarn workspaces focus --all --production
#18 1.059 ➤ YN0000: · Yarn 4.0.2
#18 1.081 ➤ YN0000: ┌ Resolution step
#18 1.134 ➤ YN0085: │ - @aashutoshrathi/word-wrap@npm:1.2.6, @babel/code-frame@npm:7.18.6, @babel/helper-validator-identifier@npm:7.[19](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:20).1, @babel/highlight@npm:7.18.6, and 225 more.
#18 1.140 ➤ YN0000: └ Completed
#18 1.140 ➤ YN0000: ┌ Fetch step
#18 4.646 ➤ YN0013: │ 129 packages were added to the project (+ 17.46 MiB).
#18 4.646 ➤ YN0000: └ Completed in 3s 506ms
#18 4.646 ➤ YN0000: ┌ Link step
#18 5.993 ➤ YN0007: │ esbuild@npm:0.19.11 must be built because it never has been before or the last one failed
#18 6.156 ➤ YN0000: └ Completed in 1s 509ms
#18 6.170 ➤ YN0000: · Done in 5s 111ms
#18 DONE 6.3s

#19 [stage-4 4/8] COPY --from=gems /usr/local/bundle /usr/local/bundle
#19 CACHED

#[20](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:21) [gems 1/2] COPY Gemfile Gemfile.lock ./
#20 CACHED

#[21](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:22) [gems 2/2] RUN bundle install &&     rm -rf vendor/bundle/ruby/*/cache
#21 CACHED

#[22](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:23) [stage-4 1/8] RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt     apt-get update -qq &&     apt-get install --no-install-recommends -y     postgresql-client-13=13.*     && rm -rf /var/lib/apt/lists /var/cache/apt/archives
#22 CACHED

#[23](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:24) [stage-4 2/8] COPY --from=gems /app /app
#23 CACHED

#[24](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:25) [stage-4 3/8] COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
#24 CACHED

#[25](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:26) [stage-4 5/8] COPY --from=node_modules /app/node_modules /app/node_modules
#25 CACHED

#[26](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:27) [stage-4 6/8] COPY . .
#26 DONE 0.0s

#[27](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:28) [stage-4 7/8] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*
#27 DONE 0.2s

#[28](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:29) [stage-4 8/8] RUN bin/rails fly:build
#28 DONE 2.8s

#[29](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:30) exporting to image
#29 exporting layers
#29 exporting layers 0.2s done
#29 writing image sha256:209bc28b1b069d5cdad0ab60f88d5d9b07e982219823b3be97a1f837df9381cc done
#29 naming to registry.fly.io/sakazuki:deployment-01HXHDXYHHD5WQNPVJJG5DZ4QN done
#29 DONE 0.2s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/sakazuki]
363af7a0b0e3: Preparing
9cf5384d0909: Preparing
865d94f33eed: Preparing
daf0211999e1: Preparing
fb2da0c1fde0: Preparing
482e906683d8: Preparing
59b281ba5624: Preparing
dceecf229a9f: Preparing
50e3b8865913: Preparing
103344a12006: Preparing
abfc58502a44: Preparing
5f70bf18a086: Preparing
401002e91208: Preparing
ff76eb42c928: Preparing
cd588dc75603: Preparing
e1325a2db1db: Preparing
103344a12006: Waiting
abfc58502a44: Waiting
5f70bf18a086: Waiting
401002e91208: Waiting
ff76eb42c928: Waiting
cd588dc75603: Waiting
e1325a2db1db: Waiting
482e906683d8: Waiting
59b281ba5624: Waiting
dceecf229a9f: Waiting
50e3b8865913: Waiting
fb2da0c1fde0: Layer already exists
daf0211999e1: Layer already exists
482e906683d8: Layer already exists
59b281ba5624: Layer already exists
dceecf229a9f: Layer already exists
50e3b8865913: Layer already exists
103344a12006: Layer already exists
abfc58502a44: Layer already exists
5f70bf18a086: Layer already exists
401002e91208: Layer already exists
ff76eb42c928: Layer already exists
cd588dc75603: Layer already exists
e1325a2db1db: Layer already exists
9cf5384d0909: Pushed
363af7a0b0e3: Pushed
865d94f33eed: Pushed
deployment-01HXHDXYHHD5WQNPVJJG5DZ4QN: digest: sha256:99f14dbace7a0dd9289c94d67525b49b9e4d67f046f8058370d1817bbd4e277f size: 3682
--> Pushing image done
image: registry.fly.io/sakazuki:deployment-01HXHDXYHHD5WQNPVJJG5DZ4QN

Watch your deployment at https://fly.io/apps/sakazuki/monitoring
image size: 566 MB

Running sakazuki release_command: bin/rails fly:release
> Created release_command machine 4d89944b439e58
> Waiting for 4d89944b439e58 to have state: started
> Machine 4d89944b439e58 has state: started
> Waiting for 4d89944b439e58 to have state: destroyed
> Machine 4d89944b439e58 has state: destroyed
> Waiting for 4d89944b439e58 to get exit event
✔ release_command 4d89944b439e58 completed successfully
Updating existing machines in 'sakazuki' with rolling strategy
> Updating 6e82996a735787 [app]
> Updating 6e82996a735787 [app]
> Waiting for 6e82996a735787 [app] to have state: started
> Machine 6e82996a735787 [app] has state: started
> Checking that 6e82996a735787 [app] is up and running
Smoke checks for 6e82996a735787 failed: the app appears to be crashing
Check its logs: here's the last lines below, or run 'fly logs -i 6e82996a735787':
  Successfully prepared image registry.fly.io/sakazuki:deployment-01HXHDXYHHD5WQNPVJJG5DZ4QN (9.700428026s)
  Configuring firecracker
  [    0.032601] PCI: Fatal: No config space access function found
   INFO Starting init (commit: d772ddd9)...
   INFO starting statics vsock server
✖ Machine 6e82996a735787 [app] update failed: smoke checks for 6e82996a735787 failed: the app appears to be crashing
   INFO Preparing to run: `/bin/bash -o pipefail -c ${SERVER_COMMAND}` as root
   INFO [fly api proxy] listening at /.fly/api
  2024/05/10 23:19:50 INFO SSH listening listen_address=[fdaa:0:d70e:a7b:b4f0:c853:74b:2]:22 dns_server=[fdaa::3]:53
  Machine created and started in 11.885s
  fallocate -l 512M /swapfile
  chmod 0600 /swapfile
  mkswap /swapfile
  Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
  no label, UUID=f864ce6f-f87b-45b5-b041-768bc1b00d7c
  echo 10 > /proc/sys/vm/swappiness
  swapon /swapfile
  swapon: /swapfile: swapon failed: Invalid argument
  rails aborted!
  Command failed with status (255): [swapon /swapfile]
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/file_utils.rb:65:in `block in create_shell_runner'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/file_utils.rb:57:in `sh'
  /app/lib/tasks/fly.rake:36:in `block (2 levels) in <main>'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `invoke_prerequisites'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
  /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
  Tasks: TOP => fly:server => fly:swapfile
  (See full trace by running task with --trace)
   INFO Main child exited normally with code: 1
   INFO Starting clean up.
   WARN could not unmount /rootfs: EINVAL: Invalid argument
  [    2.257039] reboot: Restarting system
  machine did not have a restart policy, defaulting to restart
  [    0.032705] PCI: Fatal: No config space access function found
   INFO Starting init (commit: d772ddd9)...
   INFO starting statics vsock server
   INFO Preparing to run: `/bin/bash -o pipefail -c ${SERVER_COMMAND}` as root
   INFO [fly api proxy] listening at /.fly/api
  2024/05/10 23:19:53 INFO SSH listening listen_address=[fdaa:0:d70e:a7b:b4f0:c853:74b:2]:22 dns_server=[fdaa::3]:53
  Machine started in 427ms
  chmod 0600 /swapfile
  mkswap /swapfile
  no label, UUID=5515236e-279a-4246-9357-68bf5c9c13cd
  echo 10 > /proc/sys/vm/swappiness
  swapon: /swapfile: swapon failed: Invalid argument
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/file_utils.rb:65:in `block in create_shell_runner'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/file_utils.rb:57:in `sh'
  /app/lib/tasks/fly.rake:36:in `block (2 levels) in <main>'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
  /app/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
  /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
  /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
   INFO Starting clean up.
  [    2.[30](https://github.com/momocus/sakazuki/actions/runs/9033600663/job/24824300459#step:4:31)3772] reboot: Restarting system
Checking DNS configuration for sakazuki.fly.dev
Error: smoke checks for 6e82996a735787 failed: the app appears to be crashing
Error: Process completed with exit code 1.
yonta commented 1 month ago

エラーはswapon: /swapfile: swapon failed: Invalid argument。 swapメモリーを生成するswaponコマンドが失敗している。

探すとlib/tasks/fly.rake内のswapfileタスクにて該当コマンドを実行している。 ChatGPTに聞くとfallocateコマンドでなくddコマンドで作ってみたらといわれる。 しかしこれは効果なし。

yonta commented 1 month ago

flyのドキュメント見てるとswapファイルの設定項目があった。 ここでは自分でカスタムなスワップファイルを生成するのではなく、fly.tomlの設定で可能とある。

https://fly.io/docs/reference/configuration/#swap_size_mb-option

これに従い、swapfileのタスクを削除し、fly.tomlswap_size_mb = 512を設定する。 無事にビルドできる。