1
00:00:05,570 --> 00:00:10,520
Welcome back everyone in this section of the course we're going to focus on flasks deployment actually

2
00:00:10,520 --> 00:00:14,120
getting our local class applications to live live on the web.

3
00:00:15,470 --> 00:00:19,430
So in order to do this we're going to be using the Heroku platform since really it's one of the easiest

4
00:00:19,430 --> 00:00:21,790
to use for initial deployment.

5
00:00:21,800 --> 00:00:27,290
Now before we use Heroku we'll need to install some command line tools and create our application.

6
00:00:27,290 --> 00:00:29,480
The basic steps we're going to do are the following.

7
00:00:29,600 --> 00:00:34,190
We'll start by installing some libraries and command line tools that will actually allow us to connect

8
00:00:34,280 --> 00:00:39,650
our local application and then push it to the Heroku platform then we're going to need to create a flask

9
00:00:39,680 --> 00:00:43,880
app you can use any of the applications you've already been building throughout the course or just create

10
00:00:43,910 --> 00:00:48,640
a simple Hello World app it's up to you then you create a requirements that text file.

11
00:00:48,650 --> 00:00:53,300
So you make sure all the requirements for the application are going to be pushed and installed live

12
00:00:53,300 --> 00:00:58,490
on the web that will create what's known as a proc file or a process file essentially just the list

13
00:00:58,490 --> 00:01:02,120
of process commands and we'll talk about that more in detail later.

14
00:01:02,330 --> 00:01:06,080
Then we're going to create a Heroku account and then we'll push and launch the application.

15
00:01:06,290 --> 00:01:07,550
So let's get started.

16
00:01:07,550 --> 00:01:12,350
The first thing to do is visit our command line and I'll visit the command line at Adam and we'll kind

17
00:01:12,350 --> 00:01:16,930
of do create in the flask application and install in the command line tools at the same time.

18
00:01:17,210 --> 00:01:21,650
So for this deployment I'm going to be deploying just a very simple Hello World app that where we can

19
00:01:21,650 --> 00:01:23,820
really focus on the deployment process.

20
00:01:23,840 --> 00:01:25,880
Let's get started hopping over to Adam.

21
00:01:26,090 --> 00:01:26,400
OK.

22
00:01:26,410 --> 00:01:27,910
Here I am at Adam.

23
00:01:28,070 --> 00:01:30,910
I've opened up a new folder it's called deployment example.

24
00:01:30,920 --> 00:01:32,870
And right now it's totally empty.

25
00:01:32,870 --> 00:01:38,370
So we're just going to create a new file right here and I'm going to call it app dot pi.

26
00:01:38,660 --> 00:01:43,540
So I have this app that pi is just a very simple python file and I'm going to do the following.

27
00:01:43,610 --> 00:01:47,060
I'll say from flask import flask.

28
00:01:47,330 --> 00:01:55,040
Then we'll say app is equal to flask underscore underscore name and then we'll create just the very

29
00:01:55,040 --> 00:01:56,760
simple route for the home page.

30
00:01:57,660 --> 00:02:02,550
So the home page route is just going to be index and we're not going to have a template.

31
00:02:02,560 --> 00:02:07,700
We're just going to return right off the bat saying this is working.

32
00:02:08,020 --> 00:02:13,000
So if I am able to launch the Web site and see the text this is working that I know everything's working

33
00:02:13,270 --> 00:02:17,740
and you can expand this deployment process to any of the applications we've created throughout the course

34
00:02:17,800 --> 00:02:21,290
we're just using a really simple one here so we don't have a bunch of files to deal with.

35
00:02:22,430 --> 00:02:28,230
OK then we're going to say if name is equal to mean go ahead and run our application.

36
00:02:28,490 --> 00:02:31,820
So save that we have an application that's basically the main step.

37
00:02:32,000 --> 00:02:35,180
And again you could have used any of the applications we've done so far.

38
00:02:35,180 --> 00:02:38,600
The next hour to do is really to create a virtual environment.

39
00:02:38,690 --> 00:02:39,820
So we'll do the following.

40
00:02:39,830 --> 00:02:48,380
I'll say Konda create dash n and I'm going to call this flask deploy and then we'll add in that I want

41
00:02:48,380 --> 00:02:49,660
flasks to be installed.

42
00:02:49,670 --> 00:02:54,140
So notice the spacing here and basically saying create this new environment called Flast deploy and

43
00:02:54,140 --> 00:02:56,250
then install flask in that new environment.

44
00:02:56,330 --> 00:02:57,470
So hit enter.

45
00:02:57,590 --> 00:03:02,120
And what should be happening here is it will create the environment for us and then install flask in

46
00:03:02,120 --> 00:03:02,990
that environment.

47
00:03:03,170 --> 00:03:06,050
So I'm going to jump forward in time until this is done.

48
00:03:06,080 --> 00:03:08,930
Installing it may ask you if you want to proceed.

49
00:03:08,930 --> 00:03:10,420
Go ahead and say why.

50
00:03:10,430 --> 00:03:12,820
All right so my virtual environment has now been created.

51
00:03:12,950 --> 00:03:16,910
So if you scroll up here there should be instructions on how to activate it for Window users.

52
00:03:16,910 --> 00:03:21,680
It's just activate Flast deploy and then deactivate if you're on Mac OS or Linux you're going to need

53
00:03:21,680 --> 00:03:24,840
to say Source activate or source deactivate.

54
00:03:25,010 --> 00:03:31,610
So let's activate this flasks deploy and make sure everything's working well see activate flask deploy

55
00:03:32,370 --> 00:03:35,780
enter and then you should see that it is now activated.

56
00:03:35,780 --> 00:03:40,160
So what are you going to do here is with your virtual environment activated you're going to install

57
00:03:40,280 --> 00:03:43,040
any required libraries for your flask application.

58
00:03:43,250 --> 00:03:47,340
So those can be things like flask in or flask sequel alchemy.

59
00:03:47,420 --> 00:03:49,240
In this case I'm really just using Flash.

60
00:03:49,280 --> 00:03:52,130
So I already installed everything I need.

61
00:03:52,250 --> 00:03:57,200
But for larger applications this is where you would begin to install all the required libraries for

62
00:03:57,200 --> 00:03:58,450
your application.

63
00:03:58,490 --> 00:04:02,120
Let's make sure that our application is actually working by quickly running it locally.

64
00:04:02,540 --> 00:04:08,120
So say Python app that PI enter and lets visit our browser to make sure that we don't have any local

65
00:04:08,120 --> 00:04:09,450
issues.

66
00:04:09,620 --> 00:04:12,470
If I bring in my browser I can see this is working.

67
00:04:12,470 --> 00:04:16,650
So we successfully launched it locally which means it's ready for primetime on the live web.

68
00:04:16,810 --> 00:04:23,200
So I'm going to exit this Control-C then we have one more thing we want to install in this virtual environment

69
00:04:23,330 --> 00:04:26,370
and that's green unicorn or G unicorn.

70
00:04:26,630 --> 00:04:34,580
So we can say pipin stall G unicorn and that's basically going to allow us to correctly render this

71
00:04:34,580 --> 00:04:41,960
on the web green unicorn or unicorn is a python web server Gateway Interface for Unix that is basically

72
00:04:41,960 --> 00:04:43,820
a pre fork worker model.

73
00:04:43,820 --> 00:04:46,260
You don't need to worry too much about how it works in the background.

74
00:04:46,340 --> 00:04:50,570
Basically you just need to worry that you installed that or not to go ahead and Pipp install unicorn.

75
00:04:50,690 --> 00:04:53,670
And we'll be using that when we actually the player application.

76
00:04:53,690 --> 00:04:59,540
Next up we want to do is save all of these requirements to a requirements that text file that way for

77
00:04:59,540 --> 00:05:03,000
using other libraries like Flast log in or flasks sequel alchemy.

78
00:05:03,020 --> 00:05:08,420
We have a requirement a text file that basically has everything ready to go that we need to install.

79
00:05:08,420 --> 00:05:09,660
So we'll do the following.

80
00:05:09,680 --> 00:05:17,060
We're going to say Pip freeze and then pointed to requirements.

81
00:05:17,120 --> 00:05:19,700
Make sure you spell that right requirements.

82
00:05:19,890 --> 00:05:25,820
Textfile it's going to zoom in so you can see this all in one line or zoom out Pip freeze two requirements

83
00:05:25,830 --> 00:05:31,220
that text enter and then after running that command you should see that you've created a requirements

84
00:05:31,220 --> 00:05:34,880
alt text file in the same folder that has everything you need.

85
00:05:34,880 --> 00:05:37,140
OK so now that's ready to go.

86
00:05:38,180 --> 00:05:42,230
The next step we want to do is create a proc file or a process file.

87
00:05:42,230 --> 00:05:51,860
So in this same deployment example folder I'm going to say new file and then call this capital P R O

88
00:05:51,860 --> 00:05:57,820
C f i l e and this has to be spelled correctly so you don't make any typos here enter.

89
00:05:57,860 --> 00:06:03,380
And this process file you can already see it looks like a kind of Heroku logo here on ATOM.

90
00:06:03,560 --> 00:06:07,430
All we're going to do is type the following and I'm going to zoom in here so make sure you don't get

91
00:06:07,430 --> 00:06:08,750
any typos.

92
00:06:08,750 --> 00:06:20,590
Are you going to say is web colon space unicorn space app Colan app and then save those changes.

93
00:06:20,610 --> 00:06:26,730
So all this is just basically telling us hey we're going to use green unicorn to run this flask application.

94
00:06:26,730 --> 00:06:32,490
So this is just like one line per process and this is what this is basically roughly translating to.

95
00:06:32,490 --> 00:06:36,150
So again make sure you spell all of this correctly and get your spacing correct.

96
00:06:36,150 --> 00:06:39,770
Now we have two things left we need to do locally before we can push this to the Web.

97
00:06:39,930 --> 00:06:44,680
And that is installed get and install the Heroku command line interface tool.

98
00:06:44,700 --> 00:06:51,660
So in order to make that we have to come over to Heroku see Elyse if you just google search Heroku Seelye

99
00:06:51,720 --> 00:06:55,130
or go to this link right here under the Data Center the Heroku dot com.

100
00:06:55,230 --> 00:06:58,380
You should see the download and install link.

101
00:06:58,430 --> 00:07:04,410
Now as mentioned the Heroku command line interface here it's going to require gets which is a version

102
00:07:04,410 --> 00:07:05,450
control system.

103
00:07:05,610 --> 00:07:10,360
So if you if you do not already have it installed you're going to need to install it before.

104
00:07:10,440 --> 00:07:14,880
So they have links right here for installation so you can just click on that link and they also have

105
00:07:14,880 --> 00:07:17,250
instructions for first time get set up.

106
00:07:17,280 --> 00:07:22,470
So right here and get it says getting started installing it you're going to follow the instructions

107
00:07:22,500 --> 00:07:25,610
notices instructions for Linux Mac.

108
00:07:25,620 --> 00:07:26,670
And if you keep scrolling down.

109
00:07:26,700 --> 00:07:30,810
There's also instructions for installing on Windows and there's several ways to do it.

110
00:07:30,840 --> 00:07:37,590
So go ahead and follow the instructions from this Web site on the fly on how to install gets and then

111
00:07:37,620 --> 00:07:39,610
set up get for the first time again.

112
00:07:39,870 --> 00:07:43,820
It's all just here really you just need to worry about installing it.

113
00:07:43,830 --> 00:07:46,820
You don't really have to set it up to the specifications here.

114
00:07:47,010 --> 00:07:52,140
So once you've installed already then you need to install the Heroku command line interface or that

115
00:07:52,230 --> 00:07:53,260
command line tool.

116
00:07:53,490 --> 00:07:57,960
And then we have different installations so if you're on a Mac OS you can download the graphical installer

117
00:07:58,010 --> 00:08:03,600
or if you use homebrew you can brew install it on Windows and if you are on 64 bit 32 bit just click

118
00:08:03,600 --> 00:08:07,730
on one of these installers or if you're on a YouTube you can just run this command right here.

119
00:08:07,770 --> 00:08:10,990
Pseudo snap install Heroku dash dash classic.

120
00:08:11,070 --> 00:08:17,790
And that right ran and running that on your terminal will install the command line for Ubuntu.

121
00:08:17,790 --> 00:08:22,230
Now there's other insulation methods in case none of those work for you as well including tar balls.

122
00:08:22,230 --> 00:08:22,800
OK.

123
00:08:22,830 --> 00:08:27,920
So just follow these instructions on how to install a command line interface for Heroku.

124
00:08:28,080 --> 00:08:30,860
And again you have to install it to make sure that works.

125
00:08:30,870 --> 00:08:35,910
I've already installed the command line interface so I won't need to install it myself.

126
00:08:35,940 --> 00:08:41,430
So once you've installed that then we're going to do is go straight to Heroku and set up an account

127
00:08:41,430 --> 00:08:42,000
there.

128
00:08:42,060 --> 00:08:48,070
So go to w b w the Heroku dot com and create a free account and then log in.

129
00:08:48,360 --> 00:08:54,270
Once you create a free account on Heroku on their main Heroku dot com sign up page after you've logged

130
00:08:54,270 --> 00:08:54,780
in.

131
00:08:54,780 --> 00:08:57,880
It should take you to dashboard that Heroku dot com.

132
00:08:58,050 --> 00:09:00,820
And then by default it goes to forward slash apps.

133
00:09:00,840 --> 00:09:04,920
We're going to do is create a new app so we know our app is using Python.

134
00:09:04,920 --> 00:09:09,420
So if you want you can click on Python and this will give you an introduction on kind of full step by

135
00:09:09,420 --> 00:09:11,570
step including a lot of stuff we've already gone over.

136
00:09:11,610 --> 00:09:12,600
This one's on jingo.

137
00:09:12,600 --> 00:09:16,490
You can search the documentation for the flask applications.

138
00:09:16,570 --> 00:09:18,170
For now we're going to walk you through it.

139
00:09:18,210 --> 00:09:20,720
So we're going to sit here and create a new app.

140
00:09:20,790 --> 00:09:25,890
So all these are getting started guide but we'll hit the create new app button and then go ahead and

141
00:09:25,890 --> 00:09:27,450
give your app a name.

142
00:09:27,690 --> 00:09:34,800
So I'm going to call this my cache flask deploy a demo app.

143
00:09:34,800 --> 00:09:36,930
I'm going to select a region United States.

144
00:09:36,990 --> 00:09:40,800
Keep in mind this has to be kind of uniquely available and then go ahead.

145
00:09:40,800 --> 00:09:43,260
You don't need to worry about adding to the pipeline.

146
00:09:43,260 --> 00:09:50,960
You can just hear create app and this will basically instantly create the application for you.

147
00:09:50,970 --> 00:09:56,460
Now what you need to do is take what we have locally and deploy it to this flask application that's

148
00:09:56,460 --> 00:09:59,470
living on Heroku.

149
00:09:59,490 --> 00:10:04,350
Once you've done this what we're gonna do is we're going to use the Heroku command line interface in

150
00:10:04,350 --> 00:10:05,770
order to actually deploy this.

151
00:10:05,820 --> 00:10:09,350
And the directions we're going to follow are actually all right here first.

152
00:10:09,360 --> 00:10:11,860
Again you have to install the Heroku Seelye.

153
00:10:11,970 --> 00:10:14,930
Once we've done that you're going to log in at your command line.

154
00:10:15,090 --> 00:10:16,880
So let's go ahead and do that.

155
00:10:16,910 --> 00:10:17,110
All right.

156
00:10:17,120 --> 00:10:21,710
So the first thing we need to do is Heroku log in after running this line.

157
00:10:21,720 --> 00:10:24,300
It's going to ask you to enter your e-mail and your password.

158
00:10:24,300 --> 00:10:25,640
So go ahead and do that.

159
00:10:25,650 --> 00:10:27,720
So now you should see that you're logged in.

160
00:10:27,780 --> 00:10:29,690
So I'm going to clear my screen now.

161
00:10:31,020 --> 00:10:35,720
And now that we're logged in make sure you've seeded into your actual project folder.

162
00:10:35,760 --> 00:10:38,300
I'm already located in my diploma example folder.

163
00:10:38,460 --> 00:10:39,790
So I'm good to go there.

164
00:10:39,990 --> 00:10:43,380
Next we want to initiate a get repository.

165
00:10:43,380 --> 00:10:49,230
So I say get space I an I.T. Remember you can basically just copy and paste these lines from that last

166
00:10:49,300 --> 00:10:50,370
website we're on.

167
00:10:50,400 --> 00:10:53,010
So we just initialize an empty repository.

168
00:10:53,010 --> 00:11:01,700
So now what I'm going to do is type out Heroku space get colon remote space dash.

169
00:11:01,890 --> 00:11:09,210
And then the name that I chose from my flask application which was my dash flask that deploy dash them

170
00:11:09,390 --> 00:11:13,890
up yours is going to be slightly different depending on what you actually called your application.

171
00:11:13,890 --> 00:11:18,900
Remember I'm essentially is copying and pasting everything from what Heroku is telling us to do on this

172
00:11:18,900 --> 00:11:19,410
web page.

173
00:11:19,410 --> 00:11:22,050
So again you can always copy and paste that.

174
00:11:22,140 --> 00:11:25,730
So I enter and it looks like we're good to go there.

175
00:11:25,740 --> 00:11:29,280
So the next thing is to actually begin to the player application.

176
00:11:29,280 --> 00:11:31,130
So we have this empty get repository.

177
00:11:31,200 --> 00:11:32,650
We're going to commit our code to it.

178
00:11:33,550 --> 00:11:36,440
We'll say get space at DOT.

179
00:11:36,450 --> 00:11:44,900
So then after that we say get commit space dash am and you can just leave yourself a little message

180
00:11:44,900 --> 00:11:52,080
here and quotes such as first commits or make it better or every happened to type in there they enter.

181
00:11:52,130 --> 00:12:01,330
And that's going to add in those files of the repository and then we'll say get push Heroku master enter

182
00:12:02,380 --> 00:12:05,350
and then it's going to deploy our application.

183
00:12:05,350 --> 00:12:10,240
So notice it's right now installing everything that was in that requirements file.

184
00:12:10,240 --> 00:12:15,250
Once that's done you should see somewhere that has a phrase saying your application has been deployed

185
00:12:15,250 --> 00:12:16,020
to Heroku.

186
00:12:16,180 --> 00:12:20,420
So now actually have this URL I can visit and it should be deployed there.

187
00:12:20,440 --> 00:12:21,670
So let's copy that.

188
00:12:21,730 --> 00:12:23,170
All right click copy.

189
00:12:23,410 --> 00:12:25,190
And let's actually see if it worked.

190
00:12:25,240 --> 00:12:28,720
So I'll copy and paste that in if I come over here.

191
00:12:28,720 --> 00:12:30,040
This is live on the web.

192
00:12:30,040 --> 00:12:34,120
This is no longer local notice it's my last demo app Hiroko outcome.

193
00:12:34,300 --> 00:12:36,150
And I see this is working.

194
00:12:36,490 --> 00:12:37,060
OK.

195
00:12:37,270 --> 00:12:42,020
So that's the application deployment process for flask with Heroku.

196
00:12:42,070 --> 00:12:46,630
Hopefully you saw that it was actually really easy to set up and most importantly it was all free.

197
00:12:46,690 --> 00:12:52,210
So there are paid tiers of Heroku if you intend to have a really large application of a ton of visitors.

198
00:12:52,300 --> 00:12:57,340
But really for very simple applications where you just intended to be visited by just a few people the

199
00:12:57,340 --> 00:12:59,260
free tier could work very well for you.

200
00:12:59,440 --> 00:13:01,600
So keep that in mind if you have any questions.

201
00:13:01,600 --> 00:13:03,690
Definitely check out their fool guides.

202
00:13:03,700 --> 00:13:08,470
What we did here was kind of just a quick guide to the playing of Heroku but rUK Heroku has really full

203
00:13:08,470 --> 00:13:14,570
detailed guides on using things like preexisting databases like a postscript sequel or my sequel database.

204
00:13:14,580 --> 00:13:17,510
They even have guides on how to use an existing get repo.

205
00:13:17,590 --> 00:13:20,550
So if you already had an existing repository you could clone it.

206
00:13:20,680 --> 00:13:22,930
And that's actually the same instructions that are on here.

207
00:13:22,960 --> 00:13:24,990
So remember we just follow these instructions.

208
00:13:25,000 --> 00:13:29,710
But it also has instructions later on if you want to connect to get a hub or even connect to things

209
00:13:29,710 --> 00:13:34,090
like Dropbox so lots of different guides here that documentation is actually really really good and

210
00:13:34,090 --> 00:13:34,740
Heroku.

211
00:13:34,840 --> 00:13:38,500
So it would definitely tell you to check that out if you want to do some more complex tasks.

212
00:13:38,530 --> 00:13:42,850
But for now we've successfully deployed our simple application to the web.

213
00:13:42,910 --> 00:13:45,880
If you have any questions feel free to post the Q&amp;A forums.

214
00:13:45,910 --> 00:13:47,020
We'll see you at the next lecture.
