WEBVTT

1
00:00:00.420 --> 00:00:01.620
Kamal is a tool for deploying

2
00:00:01.620 --> 00:00:03.510
your web applications anywhere.

3
00:00:03.510 --> 00:00:05.580
Whether you’re deploying to a cloud VM,

4
00:00:05.580 --> 00:00:07.470
or to your own servers,

5
00:00:07.470 --> 00:00:10.860
or to a tiny little pi computer in your closet,

6
00:00:10.860 --> 00:00:12.720
you can use Kamal.

7
00:00:12.720 --> 00:00:16.230
Kamal simply asks that you give it a handful of IP addresses

8
00:00:16.230 --> 00:00:18.240
for the servers you wanna deploy to.

9
00:00:18.240 --> 00:00:20.010
Those servers don’t have to be set up

10
00:00:20.010 --> 00:00:21.600
in any special way in advance.

11
00:00:21.600 --> 00:00:23.460
Kamal will take care of all of that,

12
00:00:23.460 --> 00:00:25.650
including installing Docker,

13
00:00:25.650 --> 00:00:28.350
and that’s exactly what Kamal sits on top of.

14
00:00:28.350 --> 00:00:32.250
It is basically just docker underneath the Kamal controls

15
00:00:32.250 --> 00:00:36.600
to deploy your application to ensure that any updates happen

16
00:00:36.600 --> 00:00:40.470
completely gapless, no 500 errors to be thrown.

17
00:00:40.470 --> 00:00:43.410
It does this by putting a proxy

18
00:00:43.410 --> 00:00:45.600
in front of your applications

19
00:00:45.600 --> 00:00:47.460
as you swap them back and forth.

20
00:00:47.460 --> 00:00:50.100
It all happens without you having to do

21
00:00:50.100 --> 00:00:51.210
pretty much anything about it.

22
00:00:51.210 --> 00:00:54.720
Kamal controls all parts of the equation.

23
00:00:54.720 --> 00:00:59.700
Kamal 2 is now also capable of terminating SSL

24
00:00:59.700 --> 00:01:02.430
and automatically configuring those certificates

25
00:01:02.430 --> 00:01:04.710
using Let’s Encrypt.

26
00:01:04.710 --> 00:01:06.810
You can also deploy multiple applications

27
00:01:06.810 --> 00:01:08.490
on a single server.

28
00:01:08.490 --> 00:01:09.960
And of course you can also deploy

29
00:01:09.960 --> 00:01:11.700
to a bunch of different servers.

30
00:01:11.700 --> 00:01:15.630
That’s what we do at 37signals for all of our deployments,

31
00:01:15.630 --> 00:01:19.080
including things like Hey.com.

32
00:01:19.080 --> 00:01:21.840
And that was where Kamal was originally extracted.

33
00:01:21.840 --> 00:01:24.930
We wanted to move all of our stuff

34
00:01:24.930 --> 00:01:27.360
out of the cloud onto our own servers,

35
00:01:27.360 --> 00:01:30.240
and we created Kamal to do just that.

36
00:01:30.240 --> 00:01:32.880
All of our applications were already running in containers,

37
00:01:32.880 --> 00:01:37.470
so it wasn’t exactly a big leap to deploy them by ourselves

38
00:01:37.470 --> 00:01:39.840
using Kamal, using Docker,

39
00:01:39.840 --> 00:01:42.330
and we felt we didn’t really need anything else

40
00:01:42.330 --> 00:01:45.240
and that many other folks would be in the same boat,

41
00:01:45.240 --> 00:01:47.100
that they would find something like Kubernetes

42
00:01:47.100 --> 00:01:51.300
too complicated or other solutions simply wanting.

43
00:01:51.300 --> 00:01:54.360
We’ve created Kamal exclusively for the purpose

44
00:01:54.360 --> 00:01:58.140
of deploying web applications and keeping them up to date

45
00:01:58.140 --> 00:02:00.300
with as little hassle as possible,

46
00:02:00.300 --> 00:02:02.490
yet still being completely full featured.

47
00:02:02.490 --> 00:02:04.380
We do things like asset bridging

48
00:02:04.380 --> 00:02:06.420
to ensure there’s no 404 errors

49
00:02:06.420 --> 00:02:08.970
as you switch from one version of your application

50
00:02:08.970 --> 00:02:10.290
to the next.

51
00:02:10.290 --> 00:02:12.630
We have accessories that you could use Kamal

52
00:02:12.630 --> 00:02:16.380
to even deploy and control database servers.

53
00:02:16.380 --> 00:02:21.380
Kamal was originally created to work for Rails applications,

54
00:02:21.660 --> 00:02:24.030
but Kamal is really a general purpose tool

55
00:02:24.030 --> 00:02:26.970
that you can use to deploy any type of web application

56
00:02:26.970 --> 00:02:30.480
that can be containerized, which is really all of them.

57
00:02:30.480 --> 00:02:33.480
So I’ll start my example showing you how to do this

58
00:02:33.480 --> 00:02:37.500
with a very basic Hello World Go application.

59
00:02:37.500 --> 00:02:38.433
Let’s get to it.

60
00:02:39.300 --> 00:02:43.110
All right, let’s have a look at a incredibly basic

61
00:02:43.110 --> 00:02:45.510
Go application that simply says Hello World.

62
00:02:45.510 --> 00:02:48.150
This is one of the things I really like about Go.

63
00:02:48.150 --> 00:02:52.680
You can say Hello World in almost no work at all,

64
00:02:52.680 --> 00:02:55.530
and this is what we’re doing here in this single Go file

65
00:02:55.530 --> 00:02:57.510
we have set up in this directory,

66
00:02:57.510 --> 00:03:01.470
starting a server on port 80 and listening to everything,

67
00:03:01.470 --> 00:03:04.500
not just the route but all paths below.

68
00:03:04.500 --> 00:03:05.640
That’s by the way, important.

69
00:03:05.640 --> 00:03:09.330
Make a note of that because Kamal uses /up

70
00:03:09.330 --> 00:03:10.530
as the health check.

71
00:03:10.530 --> 00:03:14.670
So your application must respond 200 okay to /up.

72
00:03:14.670 --> 00:03:15.810
We do it automatically here

73
00:03:15.810 --> 00:03:19.260
because we serve everything on all paths

74
00:03:19.260 --> 00:03:22.380
with the Hello World and 200 Okay.

75
00:03:22.380 --> 00:03:24.390
So that’s a simple application here in Go,

76
00:03:24.390 --> 00:03:27.210
and the Docker file is almost as simple.

77
00:03:27.210 --> 00:03:29.040
It simply has a built stage

78
00:03:29.040 --> 00:03:31.020
that will compile the application,

79
00:03:31.020 --> 00:03:34.890
and then it will copy it into our container On app

80
00:03:34.890 --> 00:03:38.940
exposing port 80 and starting that application

81
00:03:38.940 --> 00:03:40.020
that we just built.

82
00:03:40.020 --> 00:03:43.920
So what we can do is we can start here by

83
00:03:43.920 --> 00:03:46.110
simply building that application

84
00:03:46.110 --> 00:03:49.170
or building the Docker image for that application

85
00:03:49.170 --> 00:03:50.003
we have right here.

86
00:03:50.003 --> 00:03:52.740
I’m calling it Kamago, and we’re just gonna build that.

87
00:03:52.740 --> 00:03:54.210
It goes really quickly.

88
00:03:54.210 --> 00:03:57.900
It is a tiny Docker file, and we are already done.

89
00:03:57.900 --> 00:04:00.510
So now that we’ve built it, we can run it here,

90
00:04:00.510 --> 00:04:03.960
and I am going to map port 80 to 8080,

91
00:04:03.960 --> 00:04:05.610
and then let’s get it running.

92
00:04:05.610 --> 00:04:07.140
If we jump over in the browser here,

93
00:04:07.140 --> 00:04:09.270
and I have a look at 8080,

94
00:04:09.270 --> 00:04:10.950
you can see I’m running my application.

95
00:04:10.950 --> 00:04:12.840
So this is about as simple as it gets,

96
00:04:12.840 --> 00:04:14.610
but this is just enough

97
00:04:14.610 --> 00:04:17.610
and everything we needed to get going with Kamal.

98
00:04:17.610 --> 00:04:18.780
So the first thing we’re gonna do

99
00:04:18.780 --> 00:04:20.640
is we’re gonna do Kamal init,

100
00:04:20.640 --> 00:04:23.460
and that is going to copy over all the configuration files

101
00:04:23.460 --> 00:04:25.320
that we need for the setup,

102
00:04:25.320 --> 00:04:28.890
including a set of lifetime hooks we can look at.

103
00:04:28.890 --> 00:04:31.830
So let’s jump back into Neovim here,

104
00:04:31.830 --> 00:04:34.710
and we will hop into our config,

105
00:04:34.710 --> 00:04:36.600
and you can see there’s a deploy file.

106
00:04:36.600 --> 00:04:38.490
Now this deploy file has a few things

107
00:04:38.490 --> 00:04:40.260
that you need to replace.

108
00:04:40.260 --> 00:04:41.940
One is the name of your service.

109
00:04:41.940 --> 00:04:42.900
We’re gonna call it Kamago.

110
00:04:42.900 --> 00:04:46.500
It uses that to identify the different

111
00:04:46.500 --> 00:04:48.540
containers as they run on your setup.

112
00:04:48.540 --> 00:04:51.480
We will rename it here as well, Kamago.

113
00:04:51.480 --> 00:04:54.480
And then we need to replace my user.

114
00:04:54.480 --> 00:04:57.540
My user is the namespace for the image.

115
00:04:57.540 --> 00:05:00.660
It is also what the register uses to lock in.

116
00:05:00.660 --> 00:05:03.990
So let’s change that to my username.

117
00:05:03.990 --> 00:05:06.570
And we have one more here, down here under the registry.

118
00:05:06.570 --> 00:05:09.150
By default, we are set up to use Docker Hub,

119
00:05:09.150 --> 00:05:11.460
but you can of course use your own registry of any kind

120
00:05:11.460 --> 00:05:16.460
on DigitalOcean, or GitHub, or wherever you want to do it.

121
00:05:16.560 --> 00:05:19.350
Now we’re gonna specify the server we’re gonna deploy to.

122
00:05:19.350 --> 00:05:23.100
And I am going to use my demo server here

123
00:05:23.100 --> 00:05:25.213
that’s running on exitsoftware.io.

124
00:05:26.160 --> 00:05:30.300
And we would like to have SSL set up, yes.

125
00:05:30.300 --> 00:05:32.760
That allows for the auto certifications

126
00:05:32.760 --> 00:05:34.080
through Let’s Encrypt.

127
00:05:34.080 --> 00:05:36.720
And we need a host name for that to work as well.

128
00:05:36.720 --> 00:05:41.460
I have already set up the host name Kamago.exit.io

129
00:05:41.460 --> 00:05:43.620
to point to that demo server.

130
00:05:43.620 --> 00:05:46.680
So we can simply use that and roll off the way.

131
00:05:46.680 --> 00:05:48.630
Now one thing you’ll notice here is that the registry

132
00:05:48.630 --> 00:05:50.610
of course needs a password,

133
00:05:50.610 --> 00:05:55.610
and that password is being plucked out of the secrets.

134
00:05:55.950 --> 00:05:58.470
They’re gonna be here under .Kamal.

135
00:05:58.470 --> 00:06:00.480
And you can see here under Secrets.

136
00:06:00.480 --> 00:06:03.090
We have a bunch of different ways we can get these

137
00:06:03.090 --> 00:06:05.130
secrets to be available to Kamal.

138
00:06:05.130 --> 00:06:07.200
I’m using the very simplest, the default here,

139
00:06:07.200 --> 00:06:11.460
which is simply to pluck it out of the local machine’s ENV,

140
00:06:11.460 --> 00:06:14.310
but you can read straight out of a file,

141
00:06:14.310 --> 00:06:16.410
or you can do what most people will do

142
00:06:16.410 --> 00:06:19.350
and what we do for, for example, deploying Hey,

143
00:06:19.350 --> 00:06:23.700
we set it up with a vault, a secrets vault.

144
00:06:23.700 --> 00:06:26.430
We’re using one password at 37signals.

145
00:06:26.430 --> 00:06:29.700
Here is the setup where you would pluck those

146
00:06:29.700 --> 00:06:31.500
secrets out from a vault, and extract them,

147
00:06:31.500 --> 00:06:34.260
and then assign them to the secrets

148
00:06:34.260 --> 00:06:35.880
that Kamal are gonna use for deploy.

149
00:06:35.880 --> 00:06:38.970
But as I said, we’re just gonna plug it out at the end.

150
00:06:38.970 --> 00:06:40.560
We are going to rely on that,

151
00:06:40.560 --> 00:06:44.670
and we’re building here on an amd64.

152
00:06:44.670 --> 00:06:46.860
That is X86 processor.

153
00:06:46.860 --> 00:06:48.540
That’s what we’re going deploy to.

154
00:06:48.540 --> 00:06:51.510
So this is basically all I need to set up.

155
00:06:51.510 --> 00:06:53.430
So if we save this file,

156
00:06:53.430 --> 00:06:58.430
and we hop back out and do Kamal setup,

157
00:06:59.040 --> 00:07:00.870
it will connect to this server

158
00:07:00.870 --> 00:07:03.990
that is essentially wiped at this stage.

159
00:07:03.990 --> 00:07:06.570
I have a clean demo server for us to use.

160
00:07:06.570 --> 00:07:10.980
It’ll check that Docker is already installed.

161
00:07:10.980 --> 00:07:14.310
Well first, I’m obviously going to connect to it with SSH.

162
00:07:14.310 --> 00:07:15.630
This is, by the way, quite important.

163
00:07:15.630 --> 00:07:16.950
This is the first thing you need to do

164
00:07:16.950 --> 00:07:18.330
when you set up a new server.

165
00:07:18.330 --> 00:07:20.400
You need to exchange SSH keys,

166
00:07:20.400 --> 00:07:22.080
and then turn off password access

167
00:07:22.080 --> 00:07:26.910
such that no one can access your server except by SSH keys.

168
00:07:26.910 --> 00:07:27.743
So.

169
00:07:30.630 --> 00:07:32.010
This is a good point.

170
00:07:32.010 --> 00:07:33.630
I cannot deploy just yet

171
00:07:33.630 --> 00:07:37.080
because we have not committed all of this to Git.

172
00:07:37.080 --> 00:07:39.570
And Git is what we use to get the version

173
00:07:39.570 --> 00:07:41.640
for our application.

174
00:07:41.640 --> 00:07:44.580
So the first thing I’m gonna do is I’m gonna do Git init,

175
00:07:44.580 --> 00:07:47.520
and then I’m gonna do Git add everything,

176
00:07:47.520 --> 00:07:49.830
and then I’m going to commit everything

177
00:07:49.830 --> 00:07:52.170
with the first deploy here.

178
00:07:52.170 --> 00:07:55.710
That will mean that we are now ready to run Kamal’s setup,

179
00:07:55.710 --> 00:07:58.630
and we will actually have

180
00:08:00.720 --> 00:08:03.210
the version, the reference that we can deploy with.

181
00:08:03.210 --> 00:08:05.850
As you can see here, the first thing we do is we build

182
00:08:05.850 --> 00:08:10.200
the image, putting it into a a container image,

183
00:08:10.200 --> 00:08:12.180
and then we push that to Docker Hub.

184
00:08:12.180 --> 00:08:14.160
It goes very quickly,

185
00:08:14.160 --> 00:08:18.600
and then we pull that image down on the remote server.

186
00:08:18.600 --> 00:08:21.120
It’ll pull it off Docker Hub there.

187
00:08:21.120 --> 00:08:23.670
All the setup and exchange of keys is already set up

188
00:08:23.670 --> 00:08:25.890
through those Kamal secrets that we had,

189
00:08:25.890 --> 00:08:28.323
the Kamal registry password.

190
00:08:29.550 --> 00:08:30.780
It’ll start the servers.

191
00:08:30.780 --> 00:08:32.340
It’ll first check if anything is running.

192
00:08:32.340 --> 00:08:33.600
It’ll start the proxy

193
00:08:33.600 --> 00:08:35.970
in case that is not running already as it wasn’t.

194
00:08:35.970 --> 00:08:40.740
And voila, in 39 seconds we have deployed everything.

195
00:08:40.740 --> 00:08:44.940
Let’s go check and see if that is live

196
00:08:44.940 --> 00:08:47.850
at Kamago Exitsoftware.io.

197
00:08:47.850 --> 00:08:49.560
It is, Hello World here.

198
00:08:49.560 --> 00:08:51.330
Everything is working.

199
00:08:51.330 --> 00:08:54.480
If we jump back into our application note,

200
00:08:54.480 --> 00:08:58.800
we could change it here to say Hello World times two,

201
00:08:58.800 --> 00:09:03.210
save that, jump back out, commit an update,

202
00:09:03.210 --> 00:09:06.870
and then we can do Kamal deploy.

203
00:09:06.870 --> 00:09:09.420
Kamal deploy is not gonna do any of the setup activities.

204
00:09:09.420 --> 00:09:12.090
It is simply going to Kamal the changes

205
00:09:12.090 --> 00:09:14.730
that we have to our document, which will go even faster

206
00:09:14.730 --> 00:09:16.770
because now we have all those lovely

207
00:09:16.770 --> 00:09:19.080
layer caches we can lean on.

208
00:09:19.080 --> 00:09:22.410
It will compile it in, what’d it say, six seconds here

209
00:09:22.410 --> 00:09:23.670
to get it all pushed out.

210
00:09:23.670 --> 00:09:26.100
It’ll push it back up to Docker Hub,

211
00:09:26.100 --> 00:09:29.310
pull it onto the new server, and pull it back there.

212
00:09:29.310 --> 00:09:31.170
And then the proxy will do its magic.

213
00:09:31.170 --> 00:09:32.400
If this was a real application

214
00:09:32.400 --> 00:09:34.650
and we had a ton of traffic going into it,

215
00:09:34.650 --> 00:09:38.580
it would first start the new version of the application,

216
00:09:38.580 --> 00:09:40.380
check that that was sound,

217
00:09:40.380 --> 00:09:43.050
and then not switch over until it was making sure

218
00:09:43.050 --> 00:09:45.630
that you would have no dropped connections

219
00:09:45.630 --> 00:09:47.160
in between the two updates.

220
00:09:47.160 --> 00:09:51.480
If we load here, we are running version two,

221
00:09:51.480 --> 00:09:54.123
and that is basically all there is to it.

222
00:09:55.020 --> 00:09:57.210
Now let’s try to make a more substantial demo.

223
00:09:57.210 --> 00:10:00.240
I’m going to create a new Rails 8 application

224
00:10:00.240 --> 00:10:01.080
called Alpha,

225
00:10:01.080 --> 00:10:04.260
and we’re going to run it with the MySQL database.

226
00:10:04.260 --> 00:10:06.330
Normally I would just use SQL Light

227
00:10:06.330 --> 00:10:07.980
if we’re deploying to a single server,

228
00:10:07.980 --> 00:10:10.320
but because we’re going to set this up

229
00:10:10.320 --> 00:10:11.310
with multiple servers,

230
00:10:11.310 --> 00:10:14.340
including an independent database server in this example,

231
00:10:14.340 --> 00:10:17.520
we are going to use MySQL.

232
00:10:17.520 --> 00:10:19.860
But before we get going with the multiple servers,

233
00:10:19.860 --> 00:10:23.280
I’m going to deploy this new application

234
00:10:23.280 --> 00:10:26.640
alongside our Go application on the same server.

235
00:10:26.640 --> 00:10:28.590
That is one of the new things in Kamal 2

236
00:10:28.590 --> 00:10:32.280
that we can deploy to the same server, multiple apps,

237
00:10:32.280 --> 00:10:34.500
and just route it on the host name.

238
00:10:34.500 --> 00:10:36.930
It’s really simple to do.

239
00:10:36.930 --> 00:10:38.730
But this Rails application needs to do something,

240
00:10:38.730 --> 00:10:41.700
and we are going to give it a scaffold interface.

241
00:10:41.700 --> 00:10:42.990
This is the same scaffold interface

242
00:10:42.990 --> 00:10:44.220
I’ve done about a million times.

243
00:10:44.220 --> 00:10:48.900
It’s gonna have a post with a title and a body that is text.

244
00:10:48.900 --> 00:10:51.990
We are going to migrate that

245
00:10:51.990 --> 00:10:54.180
and create our schema files.

246
00:10:54.180 --> 00:10:57.390
And then we are going to have a look at this.

247
00:10:57.390 --> 00:10:58.380
The first thing we need to do

248
00:10:58.380 --> 00:10:59.670
is have a look at the routes here,

249
00:10:59.670 --> 00:11:03.180
make sure that the routes on the route

250
00:11:03.180 --> 00:11:06.540
is routed to our new scaffold correctly.

251
00:11:06.540 --> 00:11:10.440
And now we’re actually set to test if all this works.

252
00:11:10.440 --> 00:11:11.610
Let’s do that.

253
00:11:11.610 --> 00:11:16.610
Let’s do a bin dev to start up our development server.

254
00:11:16.680 --> 00:11:21.680
Let’s hop over here in our browser and look at Local 3000.

255
00:11:21.840 --> 00:11:24.000
As you can see here, this is the standard setup

256
00:11:24.000 --> 00:11:27.480
for a scaffold interface in Rails.

257
00:11:27.480 --> 00:11:29.340
Everything is working just fine.

258
00:11:29.340 --> 00:11:30.750
So let’s hop back out

259
00:11:30.750 --> 00:11:34.620
and go back to looking at the application itself

260
00:11:34.620 --> 00:11:37.530
because the main file we need to change here is,

261
00:11:37.530 --> 00:11:39.600
as we did in the Go example,

262
00:11:39.600 --> 00:11:42.720
we need to look up our deploy file.

263
00:11:42.720 --> 00:11:44.790
And it’s already filled out here in Rails.

264
00:11:44.790 --> 00:11:47.040
It’s coming a little better pre-baked

265
00:11:47.040 --> 00:11:49.770
than it is straight out of Kamal because of course we know

266
00:11:49.770 --> 00:11:51.990
that you are running a Rails application.

267
00:11:51.990 --> 00:11:54.480
But we still need to change some of the same things.

268
00:11:54.480 --> 00:11:56.460
Like we need to change your username.

269
00:11:56.460 --> 00:12:00.120
I’m gonna go back here to do my username for the image

270
00:12:00.120 --> 00:12:03.060
and the same thing for the registry.

271
00:12:03.060 --> 00:12:04.950
We have the same Kamal registry password

272
00:12:04.950 --> 00:12:05.910
we’re pulling out of ENV,

273
00:12:05.910 --> 00:12:07.830
so nothing has really changed there.

274
00:12:07.830 --> 00:12:11.730
We are going to run this with the same proxy to,

275
00:12:11.730 --> 00:12:16.230
except we are going to give it a different host name.

276
00:12:16.230 --> 00:12:19.765
This is gonna be exitsoftware.io.

277
00:12:19.765 --> 00:12:22.890
We are gonna deploy it to the same demo server that we had,

278
00:12:22.890 --> 00:12:27.090
which lives on demo.exitsoftware.io.

279
00:12:27.090 --> 00:12:28.890
And then let’s scroll down here and see what else we got.

280
00:12:28.890 --> 00:12:32.580
We got the fact that the Rails master key is being injected

281
00:12:32.580 --> 00:12:34.350
as a secret by default.

282
00:12:34.350 --> 00:12:38.520
We are running the job server here in Puma.

283
00:12:38.520 --> 00:12:40.830
That’s just how Rails 8 is already set up.

284
00:12:40.830 --> 00:12:42.450
We can actually toggle this off

285
00:12:42.450 --> 00:12:44.757
so we get a little more information when we look at things.

286
00:12:44.757 --> 00:12:49.080
And here are a couple of other new features from Kamal 2.

287
00:12:49.080 --> 00:12:50.820
These are things called aliases

288
00:12:50.820 --> 00:12:53.160
where you can then just do Kamal console,

289
00:12:53.160 --> 00:12:55.380
and you get a Rails console

290
00:12:55.380 --> 00:12:58.170
instead of having to write out all these options,

291
00:12:58.170 --> 00:12:59.940
the fact that it needs to be an interactive,

292
00:12:59.940 --> 00:13:02.793
and reused container, and all that stuff.

293
00:13:04.260 --> 00:13:06.870
We are again just building for amd64.

294
00:13:06.870 --> 00:13:08.700
We don’t need to pass anything in.

295
00:13:08.700 --> 00:13:10.110
What we are going to do though

296
00:13:10.110 --> 00:13:12.930
is we’re gonna set up accessories.

297
00:13:12.930 --> 00:13:17.220
And accessories are a way for

298
00:13:17.220 --> 00:13:20.220
Kamal to allow you to run things like a database server.

299
00:13:20.220 --> 00:13:23.190
We’re gonna host this on the same box,

300
00:13:23.190 --> 00:13:24.600
at least for the moment here.

301
00:13:24.600 --> 00:13:27.840
We’re gonna host it on exitsoftware.io.

302
00:13:27.840 --> 00:13:30.330
And then for the port, there’s something interesting.

303
00:13:30.330 --> 00:13:32.880
If we just leave it like this 3306,

304
00:13:32.880 --> 00:13:35.730
it’s gonna open that port to the whole world.

305
00:13:35.730 --> 00:13:38.850
That’s actually not what we want with this application

306
00:13:38.850 --> 00:13:41.340
where the database is running alongside

307
00:13:41.340 --> 00:13:43.500
the app service itself.

308
00:13:43.500 --> 00:13:46.440
We want it only to be accessible on local hosts.

309
00:13:46.440 --> 00:13:49.170
So Docker can do that too.

310
00:13:49.170 --> 00:13:53.580
You simply map it to 127.0.0.1,

311
00:13:53.580 --> 00:13:55.290
and then do the port.

312
00:13:55.290 --> 00:13:58.740
Then you’re gonna get that port opening just on local host

313
00:13:58.740 --> 00:14:00.780
instead of the entire world.

314
00:14:00.780 --> 00:14:02.523
That’s quite helpful.

315
00:14:03.420 --> 00:14:04.860
It’s also set up here that you could do your

316
00:14:04.860 --> 00:14:06.030
custom configuration.

317
00:14:06.030 --> 00:14:07.110
We’re not gonna use that.

318
00:14:07.110 --> 00:14:10.500
We are just gonna use the default configuration for MySQL,

319
00:14:10.500 --> 00:14:14.790
and then we have to set up the production SQL file

320
00:14:14.790 --> 00:14:17.310
that will load the initial entry point

321
00:14:17.310 --> 00:14:19.500
when the MySQL server’s first set up.

322
00:14:19.500 --> 00:14:21.540
We’ll set up in one second.

323
00:14:21.540 --> 00:14:23.010
We could also have set up Redis here,

324
00:14:23.010 --> 00:14:26.610
but we’re not gonna use that in this example.

325
00:14:26.610 --> 00:14:28.740
If we do go back up here though,

326
00:14:28.740 --> 00:14:31.740
we do need to change the database host.

327
00:14:31.740 --> 00:14:33.180
So we can change that.

328
00:14:33.180 --> 00:14:36.180
And now we’re gonna rely on

329
00:14:36.180 --> 00:14:38.850
yet another new aspect of Kamal 2,

330
00:14:38.850 --> 00:14:41.790
which is the fact that Kamal will create

331
00:14:41.790 --> 00:14:43.830
its own internal network.

332
00:14:43.830 --> 00:14:47.820
So instead of referring to this with an external IP address,

333
00:14:47.820 --> 00:14:50.910
we can refer to it with its logical name,

334
00:14:50.910 --> 00:14:53.970
which is gonna be alpha-db.

335
00:14:53.970 --> 00:14:54.900
Where does it get that from?

336
00:14:54.900 --> 00:14:58.410
It gets the db from the name of the accessory,

337
00:14:58.410 --> 00:15:01.350
and it gets the alpha from the name of the service.

338
00:15:01.350 --> 00:15:04.380
So this is how you can essentially set things up

339
00:15:04.380 --> 00:15:07.500
to be quarantine per application

340
00:15:07.500 --> 00:15:09.270
but still having multiple of them

341
00:15:09.270 --> 00:15:11.643
running on the same server.

342
00:15:12.630 --> 00:15:14.820
We’re gonna hop in here and have a look at the

343
00:15:14.820 --> 00:15:16.200
database YAML file as well.

344
00:15:16.200 --> 00:15:17.430
Let’s close this.

345
00:15:17.430 --> 00:15:21.990
And you can see here we are set up to use a root password.

346
00:15:21.990 --> 00:15:24.900
That’s actually correct for what we’re gonna use right now.

347
00:15:24.900 --> 00:15:27.150
And then normally in a real production app,

348
00:15:27.150 --> 00:15:30.600
you’d set up a custom user for this database.

349
00:15:30.600 --> 00:15:31.620
We’re not gonna do that right now.

350
00:15:31.620 --> 00:15:34.500
We’re just gonna rely on the root user,

351
00:15:34.500 --> 00:15:36.180
and then we’re gonna rely on the fact

352
00:15:36.180 --> 00:15:38.310
that we need a password here.

353
00:15:38.310 --> 00:15:41.670
And that password is something we’re gonna shove into

354
00:15:41.670 --> 00:15:42.960
the secrets file.

355
00:15:42.960 --> 00:15:45.750
You see we already have the Kamal registry password here.

356
00:15:45.750 --> 00:15:49.410
We’re gonna do the database password as well.

357
00:15:49.410 --> 00:15:52.920
And in a real app, again, you’re going to wanna use

358
00:15:52.920 --> 00:15:55.590
one of the proper ways of doing this,

359
00:15:55.590 --> 00:15:58.170
either storing this in something like one password,

360
00:15:58.170 --> 00:16:01.500
or storing it in ENV, or pulling it from a file.

361
00:16:01.500 --> 00:16:04.230
You’re definitely not gonna encode it right here,

362
00:16:04.230 --> 00:16:07.380
but I’m gonna do that anyway just for demo purposes.

363
00:16:07.380 --> 00:16:11.463
So it’s gonna be MySQL root password.

364
00:16:12.300 --> 00:16:17.300
This is absolutely not something you should do for real.

365
00:16:19.200 --> 00:16:20.100
That’s gonna be our password.

366
00:16:20.100 --> 00:16:21.810
Isn’t that great?

367
00:16:21.810 --> 00:16:26.080
Now that password is going to be injected into

368
00:16:27.030 --> 00:16:29.910
the setup here so that we can refer to it

369
00:16:29.910 --> 00:16:34.740
down for the setup in the database accessory.

370
00:16:34.740 --> 00:16:36.360
It’s gonna pull this password,

371
00:16:36.360 --> 00:16:38.640
and it’s going to essentially see the database

372
00:16:38.640 --> 00:16:40.290
that that is going to be the root password,

373
00:16:40.290 --> 00:16:43.620
and which is going to refer to that root password

374
00:16:43.620 --> 00:16:45.450
in all the cases.

375
00:16:45.450 --> 00:16:47.490
So we’re gonna have to parse

376
00:16:47.490 --> 00:16:50.490
or pass that into our Rails application as well,

377
00:16:50.490 --> 00:16:52.923
such that that has access to the MySQL root.

378
00:16:54.300 --> 00:16:57.123
Not root host, root password.

379
00:16:57.990 --> 00:17:01.740
And we are going to use that in the database YAML file here.

380
00:17:01.740 --> 00:17:04.650
Instead of this alpha database password,

381
00:17:04.650 --> 00:17:08.130
we’re gonna do the MySQL root password.

382
00:17:08.130 --> 00:17:10.180
Now we have everything set up

383
00:17:11.040 --> 00:17:12.510
to be able to refer to each other.

384
00:17:12.510 --> 00:17:16.800
And then as I said, we actually do need to just set up an

385
00:17:16.800 --> 00:17:21.420
initializer file for our database.

386
00:17:21.420 --> 00:17:23.647
We’re gonna call that Production.SQL.

387
00:17:25.170 --> 00:17:28.350
And in that you need to do create database,

388
00:17:28.350 --> 00:17:30.390
and then the different databases that you need.

389
00:17:30.390 --> 00:17:33.360
We have one database that’s called Alpha Production.

390
00:17:33.360 --> 00:17:34.980
That’s great, we need that.

391
00:17:34.980 --> 00:17:39.980
And then we also need one that is Alpha Production Cache,

392
00:17:41.190 --> 00:17:45.330
and we need one that is Alpha Production Queue,

393
00:17:45.330 --> 00:17:49.680
and we need one that is Alpha production cable.

394
00:17:49.680 --> 00:17:51.120
Where are all these coming from?

395
00:17:51.120 --> 00:17:52.200
This is Rail stuff.

396
00:17:52.200 --> 00:17:53.190
It is coming out here.

397
00:17:53.190 --> 00:17:56.310
You can see we have a cable schema, cache schema,

398
00:17:56.310 --> 00:17:57.480
what else have you?

399
00:17:57.480 --> 00:18:01.320
And they’re all defined in our database YAML file.

400
00:18:01.320 --> 00:18:02.670
Production has a primary database.

401
00:18:02.670 --> 00:18:03.750
That’s the one we just set up,

402
00:18:03.750 --> 00:18:06.330
along with a cache, queue, and cable.

403
00:18:06.330 --> 00:18:09.030
Alright, so we have now four databases we’re gonna set up.

404
00:18:09.030 --> 00:18:12.420
They’re gonna be set up with this MySQL root password,

405
00:18:12.420 --> 00:18:14.010
and we’re going to create them all

406
00:18:14.010 --> 00:18:16.020
when this is all initially set up,

407
00:18:16.020 --> 00:18:19.950
and we are going to deploy it to the existing server

408
00:18:19.950 --> 00:18:22.800
on demoexitsoftware.io.

409
00:18:22.800 --> 00:18:25.380
We’re gonna run with SSL in front of it,

410
00:18:25.380 --> 00:18:28.800
and we are going to deploy this.

411
00:18:28.800 --> 00:18:30.210
I think this is everything we need.

412
00:18:30.210 --> 00:18:33.510
Well, the first thing we do need is actually,

413
00:18:33.510 --> 00:18:35.280
let’s start a new terminal here.

414
00:18:35.280 --> 00:18:39.270
We are going to need to check all this stuff into Git.

415
00:18:39.270 --> 00:18:41.370
When you generate a new Rails application,

416
00:18:41.370 --> 00:18:44.490
it’s already been Git initialized,

417
00:18:44.490 --> 00:18:46.595
but we need to add everything to it

418
00:18:46.595 --> 00:18:49.620
and then we need to commit everything as first.

419
00:18:49.620 --> 00:18:54.420
Alright, that should make us ready to do Kamal setup.

420
00:18:54.420 --> 00:18:59.420
And Kamal setup is going to set up not only the

421
00:18:59.520 --> 00:19:00.360
application itself,

422
00:19:00.360 --> 00:19:03.630
it’s also going to set up that accessory,

423
00:19:03.630 --> 00:19:05.340
that database accessory.

424
00:19:05.340 --> 00:19:08.400
You can see here it’s setting up the Alpha DB data.

425
00:19:08.400 --> 00:19:11.550
You get to see everything that basically goes on with Kamal

426
00:19:11.550 --> 00:19:15.690
because we output all the operations that Kamal perform

427
00:19:15.690 --> 00:19:17.730
when you run things like Kamal setup

428
00:19:17.730 --> 00:19:20.130
or you run Kamal Deploy.

429
00:19:20.130 --> 00:19:23.340
You see here now we’re running and setting up the database.

430
00:19:23.340 --> 00:19:26.640
We are then going to build our Rails application

431
00:19:26.640 --> 00:19:27.750
from scratch.

432
00:19:27.750 --> 00:19:31.080
We’re gonna build that Docker container image,

433
00:19:31.080 --> 00:19:34.140
and we’re gonna push it up to Docker Hub

434
00:19:34.140 --> 00:19:36.240
just like we were doing with the Go example.

435
00:19:36.240 --> 00:19:38.700
And then we’re gonna pull it down on the server.

436
00:19:38.700 --> 00:19:42.270
And then these two applications will live side by side

437
00:19:42.270 --> 00:19:43.620
on the same server.

438
00:19:43.620 --> 00:19:47.850
They’re being routed by that proxy host configuration.

439
00:19:47.850 --> 00:19:51.360
So we can have them both live on the server

440
00:19:51.360 --> 00:19:52.200
at the same time.

441
00:19:52.200 --> 00:19:55.803
It’s one proxy, multiple applications.

442
00:19:56.850 --> 00:19:58.920
And that’s really neat.

443
00:19:58.920 --> 00:20:00.660
Now, once this is all set up,

444
00:20:00.660 --> 00:20:02.580
we will take it one step further,

445
00:20:02.580 --> 00:20:06.840
and we will move beyond my little dedicated demo server,

446
00:20:06.840 --> 00:20:10.560
and we’re gonna set up some cloud VMs on Hetzner

447
00:20:10.560 --> 00:20:14.970
to show you how you can deploy the same application

448
00:20:14.970 --> 00:20:18.180
to an entirely new setup

449
00:20:18.180 --> 00:20:20.370
using almost all the same configuration,

450
00:20:20.370 --> 00:20:22.260
only changing the things that actually do change.

451
00:20:22.260 --> 00:20:25.980
So here we have the deployments finished in 84 seconds.

452
00:20:25.980 --> 00:20:28.830
That’s not bad for building everything from scratch.

453
00:20:28.830 --> 00:20:33.330
Let’s now hop over and see if this was actually real.

454
00:20:33.330 --> 00:20:38.100
We’re gonna go to alpha, alphaexitsoftware.io.

455
00:20:38.100 --> 00:20:39.870
Here we have our real application.

456
00:20:39.870 --> 00:20:41.760
We can do Hello World.

457
00:20:41.760 --> 00:20:43.080
Hello.

458
00:20:43.080 --> 00:20:45.840
And you can see it is all successful.

459
00:20:45.840 --> 00:20:47.280
It is saving to the database.

460
00:20:47.280 --> 00:20:48.900
Everything is up and running.

461
00:20:48.900 --> 00:20:49.980
Wonderful.

462
00:20:49.980 --> 00:20:54.980
And we can check that we still have our old application,

463
00:20:55.530 --> 00:20:58.110
our Go application running on the same server on Kamago.

464
00:20:58.110 --> 00:21:00.240
Hello World times two.

465
00:21:00.240 --> 00:21:01.410
Wonderful.

466
00:21:01.410 --> 00:21:05.250
Now let’s set up some cloud VMs.

467
00:21:05.250 --> 00:21:07.320
I’m gonna use Hetzner here for that.

468
00:21:07.320 --> 00:21:11.490
We’re gonna set up three different servers.

469
00:21:11.490 --> 00:21:12.960
They’re all gonna run Ubuntu.

470
00:21:12.960 --> 00:21:16.350
I’m just gonna use some shared vCPUs here.

471
00:21:16.350 --> 00:21:18.150
Look at these amazing prices.

472
00:21:18.150 --> 00:21:21.990
I’m gonna use the smallest box I can get for this setup.

473
00:21:21.990 --> 00:21:23.970
I’m going to have my SSH key

474
00:21:23.970 --> 00:21:25.860
already configured for those boxes,

475
00:21:25.860 --> 00:21:28.350
and that’s about it.

476
00:21:28.350 --> 00:21:31.650
Let’s name them something like Alpha-Web-1,

477
00:21:31.650 --> 00:21:33.450
and then make three of them.

478
00:21:33.450 --> 00:21:37.320
We’re gonna call the last one now Alpha-db-1.

479
00:21:37.320 --> 00:21:40.410
Alright, creating these, setting these up.

480
00:21:40.410 --> 00:21:43.500
And as these are being set up, we also need a load balancer

481
00:21:43.500 --> 00:21:46.440
because now we have two application servers.

482
00:21:46.440 --> 00:21:48.600
We have web one, and we have web two,

483
00:21:48.600 --> 00:21:52.590
and we need to expose them as a single IP address

484
00:21:52.590 --> 00:21:54.540
that we can route things to.

485
00:21:54.540 --> 00:21:56.610
And we can do that as a load balancer.

486
00:21:56.610 --> 00:21:58.950
I’ll go in here and create that load balancer

487
00:21:58.950 --> 00:22:02.220
if I can get these out of the way.

488
00:22:02.220 --> 00:22:04.710
All right, we’re gonna put it in the same region.

489
00:22:04.710 --> 00:22:07.230
You can see we already have three servers available

490
00:22:07.230 --> 00:22:08.370
in this network zone.

491
00:22:08.370 --> 00:22:10.590
We’re just gonna use the smallest one.

492
00:22:10.590 --> 00:22:13.650
We don’t really even need anything but the target.

493
00:22:13.650 --> 00:22:17.370
We’re gonna declare the two alpha webs,

494
00:22:17.370 --> 00:22:19.260
web one and web two.

495
00:22:19.260 --> 00:22:21.990
We are going to bah-bah-bah.

496
00:22:21.990 --> 00:22:22.950
It’s gonna do all that.

497
00:22:22.950 --> 00:22:23.783
Yeah, that’s fine.

498
00:22:23.783 --> 00:22:27.540
We’re going to have /up be our health check

499
00:22:27.540 --> 00:22:31.020
for these servers just like Kamal itself would use.

500
00:22:31.020 --> 00:22:32.310
It’s just gonna be round robbing,

501
00:22:32.310 --> 00:22:34.803
and let’s call that Alpha-lb.

502
00:22:36.386 --> 00:22:37.500
Great.

503
00:22:37.500 --> 00:22:39.270
So that set up as well.

504
00:22:39.270 --> 00:22:41.250
Now, it’s gonna cook.

505
00:22:41.250 --> 00:22:43.200
It’s gonna get all configured up,

506
00:22:43.200 --> 00:22:45.540
but we have our three servers.

507
00:22:45.540 --> 00:22:47.880
So let’s set up our application

508
00:22:47.880 --> 00:22:49.410
to actually use these servers.

509
00:22:49.410 --> 00:22:54.410
If I hop back in here and go back to our setup,

510
00:22:54.450 --> 00:22:55.830
we have our deploy file.

511
00:22:55.830 --> 00:22:57.960
We are going to create an additional deploy file.

512
00:22:57.960 --> 00:23:00.450
So this is one of the really nice features of Kamal.

513
00:23:00.450 --> 00:23:03.360
You can have multiple destinations.

514
00:23:03.360 --> 00:23:05.370
So if we take this deploy YAML file,

515
00:23:05.370 --> 00:23:09.960
and we copy it over to be deploy Hetzner.yaml,

516
00:23:09.960 --> 00:23:13.860
we now have a new file that we can change

517
00:23:13.860 --> 00:23:14.693
for the things that change,

518
00:23:14.693 --> 00:23:17.220
but we don’t need all the things that did not change.

519
00:23:17.220 --> 00:23:19.830
So let’s first get rid of all of that.

520
00:23:19.830 --> 00:23:22.020
And now interestingly enough here,

521
00:23:22.020 --> 00:23:24.210
we are not gonna need the proxy

522
00:23:24.210 --> 00:23:26.820
because we are going to terminate SSL

523
00:23:26.820 --> 00:23:30.360
behind Cloudflare once we set everything up.

524
00:23:30.360 --> 00:23:32.490
So let’s turn off this proxy.

525
00:23:32.490 --> 00:23:34.050
By default it is actually off,

526
00:23:34.050 --> 00:23:36.000
but because everything depends

527
00:23:36.000 --> 00:23:38.400
or inherits from deploy YAML where we turn it off,

528
00:23:38.400 --> 00:23:40.890
we need to explicitly turn it off.

529
00:23:40.890 --> 00:23:43.410
Let’s also change these so these are not false.

530
00:23:43.410 --> 00:23:46.500
All this registry stuff is exactly the same.

531
00:23:46.500 --> 00:23:49.200
We are gonna change the end of those.

532
00:23:49.200 --> 00:23:52.440
So let’s leave that be exactly the DB host here.

533
00:23:52.440 --> 00:23:54.030
That’s gonna change.

534
00:23:54.030 --> 00:23:58.020
And the aliases, we don’t need to change those.

535
00:23:58.020 --> 00:24:00.060
We’re not gonna change the volume.

536
00:24:00.060 --> 00:24:03.030
We’re not gonna change the asset path or the builder,

537
00:24:03.030 --> 00:24:03.960
any of this stuff.

538
00:24:03.960 --> 00:24:06.090
We can really just boil it down.

539
00:24:06.090 --> 00:24:09.330
We are going to change though the accessory.

540
00:24:09.330 --> 00:24:12.720
Now, the first thing we’re gonna have to do is

541
00:24:12.720 --> 00:24:15.360
set up which web servers we’re deploying to.

542
00:24:15.360 --> 00:24:20.160
And let’s go over here and copy web one,

543
00:24:20.160 --> 00:24:21.840
the IP address for that.

544
00:24:21.840 --> 00:24:23.340
Hop back in.

545
00:24:23.340 --> 00:24:24.900
Great.

546
00:24:24.900 --> 00:24:27.330
We’re gonna copy over the other one as well.

547
00:24:27.330 --> 00:24:28.503
That’s web two.

548
00:24:29.908 --> 00:24:30.741
Great.

549
00:24:30.741 --> 00:24:34.773
Now we have those, we can copy over the database.

550
00:24:36.480 --> 00:24:37.470
Let’s see, where do we have that?

551
00:24:37.470 --> 00:24:39.900
First of all, we need to set it up here for the host.

552
00:24:39.900 --> 00:24:41.280
We need to set that up for the host,

553
00:24:41.280 --> 00:24:45.993
and we need to have it one more time for the host here.

554
00:24:47.550 --> 00:24:49.260
Delete to the end of line there.

555
00:24:49.260 --> 00:24:52.170
And then on this one we are actually going to set it up

556
00:24:52.170 --> 00:24:53.790
as a public port.

557
00:24:53.790 --> 00:24:56.040
Now when you do that, obviously you need a firewall

558
00:24:56.040 --> 00:24:58.560
of something else in front that ensures

559
00:24:58.560 --> 00:25:00.180
that only those two web servers

560
00:25:00.180 --> 00:25:04.500
are actually able to have access to the database set up.

561
00:25:04.500 --> 00:25:07.620
But otherwise all of this stuff is the same.

562
00:25:07.620 --> 00:25:10.260
The database host now is the only thing that we changed.

563
00:25:10.260 --> 00:25:12.420
We still need everything else.

564
00:25:12.420 --> 00:25:14.703
We need the secrets, and that’s basically it.

565
00:25:15.810 --> 00:25:18.870
Actually, we do need to set up one more thing.

566
00:25:18.870 --> 00:25:22.440
We need to have the secrets set up.

567
00:25:22.440 --> 00:25:23.880
So the secrets might have changed.

568
00:25:23.880 --> 00:25:25.980
We can actually change this to common I believe.

569
00:25:25.980 --> 00:25:28.140
But we can also just have an example here showing you

570
00:25:28.140 --> 00:25:30.423
how you can have secrets per,

571
00:25:33.540 --> 00:25:34.590
per deployment.

572
00:25:34.590 --> 00:25:37.108
And if we set that up, we’re actually gonna use

573
00:25:37.108 --> 00:25:37.941
the same to MySQL.

574
00:25:37.941 --> 00:25:38.940
Everything is gonna be the same.

575
00:25:38.940 --> 00:25:41.880
So you could do .com, and you could share that file,

576
00:25:41.880 --> 00:25:45.990
but if you have them dedicated to each destination,

577
00:25:45.990 --> 00:25:48.150
this is how you would set that up.

578
00:25:48.150 --> 00:25:51.900
Alright, I think we now have everything that we need

579
00:25:51.900 --> 00:25:54.450
to deploy our new setup

580
00:25:54.450 --> 00:25:59.070
to our new servers that are running on Hetzner.

581
00:25:59.070 --> 00:26:01.770
Oh, the host is actually gonna change,

582
00:26:01.770 --> 00:26:06.720
not in the original deploy file, but in our new setup.

583
00:26:06.720 --> 00:26:08.850
Actually, no, we don’t need to set up the host.

584
00:26:08.850 --> 00:26:10.350
The host is actually only something you need

585
00:26:10.350 --> 00:26:11.880
when you are using the proxy,

586
00:26:11.880 --> 00:26:14.940
and you are using it to run multiple applications

587
00:26:14.940 --> 00:26:16.080
on a single server

588
00:26:16.080 --> 00:26:19.410
or you’re using it to procure that SSL certificate.

589
00:26:19.410 --> 00:26:22.260
Otherwise we can just point to it from afar.

590
00:26:22.260 --> 00:26:26.010
So let’s check in our two new changes here,

591
00:26:26.010 --> 00:26:29.040
and then everything is going to get deployed,

592
00:26:29.040 --> 00:26:34.040
set up Hetzner as the, as second destination.

593
00:26:38.130 --> 00:26:39.240
Great.

594
00:26:39.240 --> 00:26:42.390
Alright, now we’re ready to deploy our application

595
00:26:42.390 --> 00:26:44.130
to this new Hetzner setup.

596
00:26:44.130 --> 00:26:48.240
So we’re gonna do Kamal setup -D for destination,

597
00:26:48.240 --> 00:26:52.080
HTC to match the name we gave that destination.

598
00:26:52.080 --> 00:26:54.750
And then we are essentially gonna run

599
00:26:54.750 --> 00:26:55.950
everything through from scratch.

600
00:26:55.950 --> 00:27:00.030
These are brand new Ubuntu procured setups

601
00:27:00.030 --> 00:27:01.230
that have nothing on them.

602
00:27:01.230 --> 00:27:03.480
So the first thing that Kamal does

603
00:27:03.480 --> 00:27:06.030
is to check whether they have Docker, which they do not.

604
00:27:06.030 --> 00:27:08.820
So they have to get Docker installed,

605
00:27:08.820 --> 00:27:10.440
and we will do that automatically.

606
00:27:10.440 --> 00:27:14.040
That happens as part of the Kamal setup process

607
00:27:14.040 --> 00:27:17.040
where everything is checked that we the need,

608
00:27:17.040 --> 00:27:18.930
the prerequisites that we have.

609
00:27:18.930 --> 00:27:19.763
And as you can see,

610
00:27:19.763 --> 00:27:22.710
that takes about 20 seconds on the first deploy.

611
00:27:22.710 --> 00:27:25.950
Then we log into Docker to be able to pull

612
00:27:25.950 --> 00:27:28.230
our Docker Hub image in just a second.

613
00:27:28.230 --> 00:27:29.340
And as you can see here,

614
00:27:29.340 --> 00:27:33.540
we still create that Kamal network on all of the setups,

615
00:27:33.540 --> 00:27:35.520
even if we don’t actually need to

616
00:27:35.520 --> 00:27:38.010
refer to an internal accessory in this case.

617
00:27:38.010 --> 00:27:41.130
Then we’re gonna build the container image.

618
00:27:41.130 --> 00:27:42.060
Again one more time,

619
00:27:42.060 --> 00:27:43.650
you can see there’s actually some of these layers

620
00:27:43.650 --> 00:27:45.690
that have already been cached.

621
00:27:45.690 --> 00:27:48.330
This is one of those really wonderful things about Docker

622
00:27:48.330 --> 00:27:49.680
that it has layer caching.

623
00:27:49.680 --> 00:27:50.970
It really speeds things up.

624
00:27:50.970 --> 00:27:52.830
And you see we’re able to just build the whole thing

625
00:27:52.830 --> 00:27:56.340
in 14 seconds with those layers cached.

626
00:27:56.340 --> 00:27:58.983
Now, the image is being pulled on all our three servers.

627
00:27:58.983 --> 00:28:01.620
It’s gonna be pulled on web one, two,

628
00:28:01.620 --> 00:28:04.440
and the DB one server that we set up.

629
00:28:04.440 --> 00:28:08.850
Everything is going to be booted on those servers

630
00:28:08.850 --> 00:28:10.530
with that image.

631
00:28:10.530 --> 00:28:12.180
I suppose on the accessory server.

632
00:28:12.180 --> 00:28:15.450
On the DB server, we’re gonna boot MySQL

633
00:28:15.450 --> 00:28:18.300
on its own server, instead of what we were doing before

634
00:28:18.300 --> 00:28:21.360
where we’re rebooting it on the same server

635
00:28:21.360 --> 00:28:22.530
as we were deploying everything else.

636
00:28:22.530 --> 00:28:26.970
So, alright, so now in 88 seconds we have set up

637
00:28:26.970 --> 00:28:31.020
a dedicated server from MySQL, two of these web app servers.

638
00:28:31.020 --> 00:28:34.020
And now we can go back here

639
00:28:34.020 --> 00:28:37.530
and check if our load balancer is ready.

640
00:28:37.530 --> 00:28:40.500
It’s gonna have this IP address.

641
00:28:40.500 --> 00:28:42.420
It probably won’t be ready for a few seconds

642
00:28:42.420 --> 00:28:46.350
because it pings every 10-15 seconds, something like that.

643
00:28:46.350 --> 00:28:50.220
But while it’s getting ready, let’s go into Cloudflare,

644
00:28:50.220 --> 00:28:52.140
which is where I’m managing my domain.

645
00:28:52.140 --> 00:28:54.510
And we’re gonna set up a new record.

646
00:28:54.510 --> 00:28:56.460
It’s gonna be an A record for Bravo,

647
00:28:56.460 --> 00:28:59.280
which is what we’re gonna call the destination

648
00:28:59.280 --> 00:29:00.960
for this deployment.

649
00:29:00.960 --> 00:29:04.350
And we’re gonna use the IP address of the load balancer,

650
00:29:04.350 --> 00:29:06.330
and we’re gonna set it up as being proxy.

651
00:29:06.330 --> 00:29:10.833
That means Cloudflare is going to terminate the SSL.

652
00:29:10.833 --> 00:29:14.263
It’s also gonna be doing CDN work.

653
00:29:14.263 --> 00:29:16.606
It’s a really nice setup to have it like this.

654
00:29:16.606 --> 00:29:18.780
All right, so now we have Bravo being proxy

655
00:29:18.780 --> 00:29:20.490
to the load balancer.

656
00:29:20.490 --> 00:29:23.400
And look and behold, our load balancer is healthy,

657
00:29:23.400 --> 00:29:25.140
and it’s ready to go.

658
00:29:25.140 --> 00:29:28.620
So let’s see if it all works.

659
00:29:28.620 --> 00:29:31.740
Bravo exitsoftware.io.

660
00:29:31.740 --> 00:29:32.573
Wonderful.

661
00:29:32.573 --> 00:29:37.460
Now we have a two web app server setup

662
00:29:40.260 --> 00:29:45.150
that is with a dedicated database,

663
00:29:45.150 --> 00:29:48.120
and it is running by itself.

664
00:29:48.120 --> 00:29:51.000
And by the way, we still of course have our own setup

665
00:29:51.000 --> 00:29:53.133
of the same application running on Alpha,

666
00:29:54.180 --> 00:29:56.400
and we can deploy back and forth between these two things.

667
00:29:56.400 --> 00:29:59.400
So now we have two deployments of this same application,

668
00:29:59.400 --> 00:30:02.430
and we can do a few Kamal things.

669
00:30:02.430 --> 00:30:07.430
Like we can look at the logs for the Hetzner setup.

670
00:30:08.580 --> 00:30:11.040
That’s going to show us that index controller

671
00:30:11.040 --> 00:30:13.830
we just accessed there.

672
00:30:13.830 --> 00:30:14.663
What else can we do?

673
00:30:14.663 --> 00:30:17.550
We can do things like we can access the console,

674
00:30:17.550 --> 00:30:21.060
which is going to grab the first of our web servers

675
00:30:21.060 --> 00:30:24.600
and give us a console for Rails.

676
00:30:24.600 --> 00:30:25.560
And what do we have here?

677
00:30:25.560 --> 00:30:27.090
Let’s see if we can load that first post.

678
00:30:27.090 --> 00:30:29.280
You can see, there we have it.

679
00:30:29.280 --> 00:30:33.060
We can even update that post and set a new title.

680
00:30:33.060 --> 00:30:35.463
Let’s do change from console.

681
00:30:36.360 --> 00:30:39.420
Let’s hop back and see that that actually took effect.

682
00:30:39.420 --> 00:30:42.483
It did, changed from console right here.

683
00:30:44.220 --> 00:30:47.130
This is Kamal.

684
00:30:47.130 --> 00:30:51.120
You are able to run it first on a single box,

685
00:30:51.120 --> 00:30:53.430
either with just something like SQL Light

686
00:30:53.430 --> 00:30:57.810
or using an accessory with the existing Kamal network

687
00:30:57.810 --> 00:31:00.330
to all have it operate inside of itself,

688
00:31:00.330 --> 00:31:02.700
or you can set it up with multiple servers

689
00:31:02.700 --> 00:31:05.580
like we just did in this example.

690
00:31:05.580 --> 00:31:08.340
And of course, it’s very easy to expand that.

691
00:31:08.340 --> 00:31:10.200
You can add as many servers as you want.

692
00:31:10.200 --> 00:31:13.565
You can start classifying different types of servers.

693
00:31:13.565 --> 00:31:17.760
You could have job servers running something like SQL Jobs

694
00:31:17.760 --> 00:31:20.550
as we do in Rails now with Solid Queue.

695
00:31:20.550 --> 00:31:22.560
You have a ton of options.

696
00:31:22.560 --> 00:31:25.020
We can configure how many processes

697
00:31:25.020 --> 00:31:27.180
we wanna run on each server.

698
00:31:27.180 --> 00:31:31.530
You have all the power of Kamal right at your fingers

699
00:31:31.530 --> 00:31:33.150
for any type of application,

700
00:31:33.150 --> 00:31:35.670
all the way from a Go Hello World

701
00:31:35.670 --> 00:31:39.330
to a full three tier Rails application

702
00:31:39.330 --> 00:31:41.490
with three different servers.

703
00:31:41.490 --> 00:31:42.690
It’s pretty amazing.

704
00:31:42.690 --> 00:31:44.850
It’ll work great on cloud VMs.

705
00:31:44.850 --> 00:31:47.760
It’ll work great on a dedicated box.

706
00:31:47.760 --> 00:31:50.340
It’ll work great on your own hardware.

707
00:31:50.340 --> 00:31:52.980
You just go in and add a second destination,

708
00:31:52.980 --> 00:31:55.440
or you change your Deploy YAML file

709
00:31:55.440 --> 00:31:57.780
to be the new destination.

710
00:31:57.780 --> 00:32:00.030
If we were to move this to DigitalOcean,

711
00:32:00.030 --> 00:32:01.920
I would just change these IP addresses,

712
00:32:01.920 --> 00:32:05.637
and I would run Kamal, setup -D DigitalOcean,

713
00:32:05.637 --> 00:32:09.150
and I would be up and running on the new server immediately.

714
00:32:09.150 --> 00:32:10.530
This is the power of Kamal.

715
00:32:10.530 --> 00:32:11.700
It’s pretty incredible.

716
00:32:11.700 --> 00:32:13.473
I hope you enjoy it.
