1
00:00:00,389 --> 00:00:01,924
- [Narrator] Hi, welcome
back to the course.

2
00:00:01,924 --> 00:00:03,371
In this video we're going to look at

3
00:00:03,371 --> 00:00:05,075
a better workflow for working

4
00:00:05,075 --> 00:00:08,716
with Heroku and automated deployments.

5
00:00:08,716 --> 00:00:10,422
Imagine that you wanted your app

6
00:00:10,422 --> 00:00:12,542
to always have automated deployments

7
00:00:12,542 --> 00:00:14,126
just so you can make sure that

8
00:00:14,126 --> 00:00:16,030
it's always working when you make

9
00:00:16,030 --> 00:00:19,253
a deploy or when you're making a commit.

10
00:00:19,253 --> 00:00:22,324
Well, we can activate
automated deployments

11
00:00:22,324 --> 00:00:26,491
by going over to our dashboard,
go on over to deploy,

12
00:00:28,098 --> 00:00:32,774
and then selecting enable
automatic deploys from GitHub.

13
00:00:32,774 --> 00:00:35,078
So, you have to select the branch

14
00:00:35,078 --> 00:00:37,214
that you wanna deploy from.

15
00:00:37,214 --> 00:00:38,904
In this case, we've only
got a master branch,

16
00:00:38,904 --> 00:00:42,425
but this is a good branch to
setup automatic deploys from,

17
00:00:42,425 --> 00:00:45,919
and then enable automatic deploys.

18
00:00:45,919 --> 00:00:49,408
Whenever a commit arrives at master,

19
00:00:49,408 --> 00:00:51,548
it's going to deploy to GitHub.

20
00:00:51,548 --> 00:00:53,686
Now, what that means is that while

21
00:00:53,686 --> 00:00:56,606
you are working on some new code,

22
00:00:56,606 --> 00:01:00,273
you don't want to work
on the master branch.

23
00:01:01,567 --> 00:01:03,520
Let's go over to the terminal.

24
00:01:03,520 --> 00:01:05,463
I'm going to clear it.

25
00:01:05,463 --> 00:01:09,630
And now, if we do get status,
we are on branch master.

26
00:01:12,285 --> 00:01:14,792
For example, say we
wanna add some new code.

27
00:01:14,792 --> 00:01:17,399
A new thing we're working on,

28
00:01:17,399 --> 00:01:20,418
such as a new resource
or something like that.

29
00:01:20,418 --> 00:01:23,120
We don't want to work
on the master branch,

30
00:01:23,120 --> 00:01:25,486
because while we're adding the resource,

31
00:01:25,486 --> 00:01:27,454
our code might break.

32
00:01:27,454 --> 00:01:30,268
So what we want to do is we want to do

33
00:01:30,268 --> 00:01:32,684
git branch and create a new branch.

34
00:01:32,684 --> 00:01:36,267
For example, feature
slash item categories.

35
00:01:40,399 --> 00:01:41,607
This creates a new branch,

36
00:01:41,607 --> 00:01:44,421
and then we have to tell
git to use that branch.

37
00:01:44,421 --> 00:01:48,588
So we do git checkout feature
slash item categories.

38
00:01:50,516 --> 00:01:52,623
Okay and now if we do git status,

39
00:01:52,623 --> 00:01:54,411
we can see we are on the branch

40
00:01:54,411 --> 00:01:58,071
feature slash item categories, okay?

41
00:01:58,071 --> 00:02:00,215
Then we would go over to Atom,

42
00:02:00,215 --> 00:02:03,363
and we would add our new code.

43
00:02:03,363 --> 00:02:04,867
And in this case, for example,

44
00:02:04,867 --> 00:02:07,950
I'm just going to add a read me file,

45
00:02:08,893 --> 00:02:11,329
which is not a feature evidently, but,

46
00:02:11,329 --> 00:02:13,232
and this wouldn't break your code,

47
00:02:13,232 --> 00:02:15,119
but nevertheless I'm
going to add this here,

48
00:02:15,119 --> 00:02:19,202
so I can show you what
the process would be like.

49
00:02:21,666 --> 00:02:24,999
This is built with flask, flask restful,

50
00:02:28,296 --> 00:02:30,963
flask JWT, and flask SQLAlchemy.

51
00:02:37,282 --> 00:02:39,184
Okay, so a simple read me app.

52
00:02:39,184 --> 00:02:40,353
It's not very useful, you may want

53
00:02:40,353 --> 00:02:42,109
to put some more details in it.

54
00:02:42,109 --> 00:02:44,846
But nevertheless, it's
the read me file there.

55
00:02:44,846 --> 00:02:48,103
Now, when we go back to our terminal,

56
00:02:48,103 --> 00:02:49,635
and we do git status, we see that

57
00:02:49,635 --> 00:02:52,627
that file is new there, we can add it,

58
00:02:52,627 --> 00:02:56,952
and then we can commit
it, added read me file,

59
00:02:56,952 --> 00:02:59,954
and then as always we can do git push.

60
00:02:59,954 --> 00:03:03,538
Notice that this fails, so we have to do

61
00:03:03,538 --> 00:03:05,817
git push set upstream, blah, blah, blah,

62
00:03:05,817 --> 00:03:09,283
so we can then copy that, put it in there.

63
00:03:09,283 --> 00:03:12,423
And that is going to send our branch

64
00:03:12,423 --> 00:03:14,745
feature slash item
categories, which is now

65
00:03:14,745 --> 00:03:17,315
a really bad name, since
it's only a read me,

66
00:03:17,315 --> 00:03:19,651
into the origin remote repository,

67
00:03:19,651 --> 00:03:22,908
and it's going to create
that branch there as well.

68
00:03:22,908 --> 00:03:25,247
So now both the local and
the remote repositories

69
00:03:25,247 --> 00:03:26,997
have this new branch.

70
00:03:28,370 --> 00:03:30,123
Okay, and then what you would do,

71
00:03:30,123 --> 00:03:32,167
is you would run your app locally.

72
00:03:32,167 --> 00:03:34,866
You would test it to make
sure everything works,

73
00:03:34,866 --> 00:03:36,317
and then once you're confident that

74
00:03:36,317 --> 00:03:39,817
your new things works, you would merge it.

75
00:03:41,930 --> 00:03:45,371
So you would do git checkout master.

76
00:03:45,371 --> 00:03:47,759
It would go back to the master branch,

77
00:03:47,759 --> 00:03:51,926
and then you do git merge
feature slash item categories.

78
00:03:53,384 --> 00:03:55,444
Okay, and then of course, once you've

79
00:03:55,444 --> 00:03:58,444
merged it, you have to push it over.

80
00:04:02,038 --> 00:04:04,876
So what's happened there
is we created a new branch,

81
00:04:04,876 --> 00:04:06,646
and then we've added our changes there,

82
00:04:06,646 --> 00:04:09,516
then you would test your API carefully,

83
00:04:09,516 --> 00:04:10,953
and finally at the end you would go back

84
00:04:10,953 --> 00:04:13,376
to the mater branch and
bring in all the changes

85
00:04:13,376 --> 00:04:16,098
from the other branch into master.

86
00:04:16,098 --> 00:04:20,265
And once this happens, the
automatic deploy is triggered.

87
00:04:21,659 --> 00:04:24,851
And so this is probably in the activity

88
00:04:24,851 --> 00:04:26,884
section here, deploying right now.

89
00:04:26,884 --> 00:04:29,607
And as you can see it is deployed,

90
00:04:29,607 --> 00:04:31,678
but it is deploying now, and not when

91
00:04:31,678 --> 00:04:35,845
we committed originally to
the feature branch, okay?

92
00:04:38,344 --> 00:04:40,418
Now once you're done with the feature,

93
00:04:40,418 --> 00:04:42,814
you can do git branch slash D,

94
00:04:42,814 --> 00:04:45,314
feature slash item categories.

95
00:04:46,187 --> 00:04:48,139
And that deletes the
branch, just to make sure

96
00:04:48,139 --> 00:04:50,786
that you don't go back to it.

97
00:04:50,786 --> 00:04:53,575
Once you've merged it
with the master branch,

98
00:04:53,575 --> 00:04:56,467
you want to stop committing to that branch

99
00:04:56,467 --> 00:04:58,019
and you want to create another one.

100
00:04:58,019 --> 00:05:00,154
If you want to keep working
on the feature branch,

101
00:05:00,154 --> 00:05:02,906
don't merge it until the code is finished.

102
00:05:02,906 --> 00:05:05,379
If you do merge it and
then you wanna add more,

103
00:05:05,379 --> 00:05:08,270
then create a new branch for that.

104
00:05:08,270 --> 00:05:13,017
This way, you can always
keep the master branch clean.

105
00:05:13,017 --> 00:05:15,502
And that's what it's
called, keeping it clean.

106
00:05:15,502 --> 00:05:18,504
So the master branch is always deployed

107
00:05:18,504 --> 00:05:20,443
and is always working.

108
00:05:20,443 --> 00:05:22,998
You never merge anything into master

109
00:05:22,998 --> 00:05:25,748
that isn't working, and that way,

110
00:05:26,939 --> 00:05:28,843
your application is always working,

111
00:05:28,843 --> 00:05:30,794
your users, if you have any users,

112
00:05:30,794 --> 00:05:34,370
can always access it
and so on and so forth.

113
00:05:34,370 --> 00:05:36,372
So generally a good thing to activate

114
00:05:36,372 --> 00:05:38,613
automatic deploys, but
you have to be careful

115
00:05:38,613 --> 00:05:41,946
that you're not working on untested code

116
00:05:43,053 --> 00:05:45,183
on the master branch, just make sure

117
00:05:45,183 --> 00:05:47,836
that you work on separate branches.

118
00:05:47,836 --> 00:05:49,809
Similarly if you create another branch,

119
00:05:49,809 --> 00:05:52,544
which is often done, a
branch called production.

120
00:05:52,544 --> 00:05:56,834
Git branch, production, and you
can enable automatic deploys

121
00:05:56,834 --> 00:06:01,001
on that branch instead of
on master, if you prefer.

122
00:06:01,931 --> 00:06:03,318
Okay, so that's everything for this video.

123
00:06:03,318 --> 00:06:04,700
I just wanted to show you quickly,

124
00:06:04,700 --> 00:06:06,708
a sort of workflow that you can follow

125
00:06:06,708 --> 00:06:10,046
to develop the final
project for this course,

126
00:06:10,046 --> 00:06:11,607
when we deploy it from Heroku.

127
00:06:11,607 --> 00:06:14,248
We will be following this sort of method,

128
00:06:14,248 --> 00:06:18,141
and, so yeah, hope you
enjoy that final project.

129
00:06:18,141 --> 00:06:22,589
In the next section we're
going to be looking at

130
00:06:22,589 --> 00:06:25,089
deploying to your own server,

131
00:06:25,089 --> 00:06:27,728
which is also gonna be very interesting.

132
00:06:27,728 --> 00:06:30,790
So without further ado, I'll
see you in the next video.

