-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
138 lines (114 loc) · 3.36 KB
/
Copy pathRakefile
File metadata and controls
138 lines (114 loc) · 3.36 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# frozen_string_literal: true
require 'English'
task :default => ['run:server']
LISTEN_ADDR = ENV['LISTEN_ADDR'] || ':8000'
namespace :run do
desc "run server with fake infra"
task :fake do
server = %{ GOLANG_ENV=development go run . }
compose = %{ docker compose -f stacks/local/docker-compose.yml up --build }
compose_down = %{ docker compose -f stacks/local/docker-compose.yml down }
pids = []
Signal.trap('INT') do
pids.each do |pid|
begin
Process.kill("KILL", pid)
rescue Errno::ESRCH
next
end
end
end
puts '[rake]: you need to press CTRL+C twice :)'
puts '[rake]: kicking go server'
pids << Process.spawn(server)
puts '[rake]: kicking fake infra'
pids << Process.spawn(compose)
Process.waitall
puts
puts '[rake]: running compose down'
system compose_down
puts '[rake]: all clear'
exit $?&.exitstatus || 1
end
desc "run server (default: #{LISTEN_ADDR})"
task :server do
system %{ GOLANG_ENV=development go run . }
status = $?&.exitstatus || 1
rescue Interrupt
status = 0
ensure
exit status
end
namespace :infra do
desc 'up orbstack infra'
task :up do
system %{ docker compose -f stacks/local/docker-compose.yml up --build }
status = $?&.exitstatus || 1
rescue Interrupt
status = 0
ensure
exit status
end
desc 'down orbstack infra'
task :down do
system %{ docker compose -f stacks/local/docker-compose.yml down }
status = $?&.exitstatus || 1
rescue Interrupt
status = 0
ensure
exit status
end
end
end
task :command_exists, [:command] do |_, args|
abort "#{args.command} doesn't exists" if `command -v #{args.command} > /dev/null 2>&1 && echo $?`.chomp.empty?
end
task :is_repo_clean do
abort 'please commit your changes first!' unless `git status -s | wc -l`.strip.to_i.zero?
end
task :has_bump_my_version do
Rake::Task['command_exists'].invoke('bump-my-version')
end
AVAILABLE_REVISIONS = %w[major minor patch].freeze
task :bump, [:revision] => [:has_bump_my_version] do |_, args|
args.with_defaults(revision: 'patch')
unless AVAILABLE_REVISIONS.include?(args.revision)
abort "Please provide valid revision: #{AVAILABLE_REVISIONS.join(',')}"
end
system %{ bump-my-version bump #{args.revision} }
exit $?.exitstatus
end
desc "release new version #{AVAILABLE_REVISIONS.join(',')}, default: patch"
task :release, [:revision] => [:is_repo_clean] do |_, args|
args.with_defaults(revision: 'patch')
Rake::Task['bump'].invoke(args.revision)
end
DOCKER_IMAGE_NAME = "bilus.org:latest"
namespace :docker do
desc "build docker image locally"
task :build do
system %{
GOOS="linux"
GOARCH=$(go env GOARCH)
docker build \
--build-arg="GOOS=${GOOS}" \
--build-arg="GOARCH=${GOARCH}" \
--build-arg="BUILD_SHA=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo 'not_available')" \
--build-arg="BUILD_DATE=$(date)" \
-t #{DOCKER_IMAGE_NAME} .
}
exit $?.exitstatus
end
desc "run docker image locally"
task :run do
port = LISTEN_ADDR.split(':').last
system %{
docker run -p "#{port}:#{port}" #{DOCKER_IMAGE_NAME}
}
status = $?&.exitstatus || 1
rescue Interrupt
status = 0
ensure
exit status
end
end