-
Notifications
You must be signed in to change notification settings - Fork 717
Expand file tree
/
Copy pathsetup
More file actions
executable file
·69 lines (57 loc) · 1.63 KB
/
setup
File metadata and controls
executable file
·69 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
require "fileutils"
require "socket"
require "timeout"
REDIS_PORT = 6379
REDIS_HOST = "localhost"
APP_ROOT = File.expand_path("..", __dir__)
def system!(*args)
system(*args, exception: true)
end
def installed?(tool)
system("command -v #{tool} > /dev/null 2>&1")
end
def redis_running?
Timeout::timeout(3) do
socket = TCPSocket.new(REDIS_HOST, REDIS_PORT)
socket.close
return true
end
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError, Timeout::Error
return false
end
if ENV["RAILS_ENV"] == "production"
puts "RAILS_ENV is production; bailing out"
exit
end
FileUtils.chdir APP_ROOT do
puts "== Installing dependencies =="
system "mise install"
if installed?("brew")
system "brew install sqlite ffmpeg"
elsif installed?("pacman")
system "sudo pacman -S --noconfirm --needed sqlite ffmpeg"
elsif installed?("apt")
system "sudo apt-get install --no-install-recommends -y libsqlite3-0 ffmpeg"
end
system("bundle check") || system!("bundle install")
puts "\n== Preparing database =="
if ARGV.include?("--reset")
system "rm -rf ./storage/{db,files}"
system! "bin/rails db:reset"
end
system! "bin/rails db:prepare"
unless redis_running?
if installed?("docker")
system("docker run -d --name campfire-redis -p #{REDIS_PORT}:#{REDIS_PORT} redis:7")
else
puts "Couldn't start Redis"
puts "Install either docker or redis and then run this command again"
exit 1
end
end
puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"
puts "\n== Restarting services =="
system! "bin/rails restart"
end