Nov
DEC
Jan
31
2020
2021
2022
About this capture
T h e W a y b a c k M a c h i n e - h t t p : / / w e b . a r c h i v e . o r g / w e b / 2 0 2 1 1 2 3 1 0 9 0 5 2 7 / h t t p s : / / r e a l p y t h o n . c o m / p y t h o n - c o n t i n u o u s - i n t e g r a t i o n /
●
S t a r t H e r e
●
L e a r n P y t h o n
P y t h o n T u t o r i a l s →
I n - d e p t h a r t i c l e s a n d t u t o r i a l s
V i d e o C o u r s e s →
S t e p - b y - s t e p v i d e o l e s s o n s
Q u i z z e s →
C h e c k y o u r l e a r n i n g p r o g r e s s
L e a r n i n g P a t h s →
G u i d e d s t u d y p l a n s f o r a c c e l e r a t e d l e a r n i n g
C o m m u n i t y →
L e a r n w i t h o t h e r P y t h o n i s t a s
T o p i c s →
F o c u s o n a s p e c i f i c a r e a o r s k i l l l e v e l
U n l o c k A l l C o n t e n t
●
S t o r e
R P M e m b e r s h i p
P y t h o n B a s i c s B o o k
P y t h o n T r i c k s B o o k
C P y t h o n I n t e r n a l s B o o k
T h e R e a l P y t h o n C o u r s e
M a n a g i n g P y t h o n D e p e n d e n c i e s
S u b l i m e T e x t + P y t h o n S e t u p
P y t h o n i c W a l l p a p e r s P a c k
P y t h o n M u g s , T - S h i r t s , a n d M o r e
P y t h o n i s t a C a f e C o m m u n i t y
B r o w s e A l l »
●
M o r e
P y t h o n N e w s l e t t e r
P y t h o n P o d c a s t
P y t h o n J o b B o a r d
M e e t t h e T e a m
B e c o m e a T u t o r i a l A u t h o r
B e c o m e a V i d e o I n s t r u c t o r
●
S e a r c h
●
J o i n
●
S i g n ‑ I n
C o n t i n u o u s I n t e g r a t i o n W i t h P y t h o n : A n I n t r o d u c t i o n
by K r i s t i j a n I v a n c i c
b e s t - p r a c t i c e s
d e v o p s
i n t e r m e d i a t e
t e s t i n g
M a r k a s C o m p l e t e d
S h a r e
E m a i l
T a b l e o f C o n t e n t s
● W h a t I s C o n t i n u o u s I n t e g r a t i o n ?
● W h y S h o u l d I C a r e ?
● C o r e C o n c e p t s
● S i n g l e S o u r c e R e p o s i t o r y
● A u t o m a t i n g t h e B u i l d
● A u t o m a t e d T e s t i n g
● U s i n g a n E x t e r n a l C o n t i n u o u s I n t e g r a t i o n S e r v i c e
● T e s t i n g i n a S t a g i n g E n v i r o n m e n t
● Y o u r T u r n !
● P r o b l e m D e f i n i t i o n
● C r e a t e a R e p o
● S e t U p a W o r k i n g E n v i r o n m e n t
● W r i t e a S i m p l e P y t h o n E x a m p l e
● W r i t e U n i t T e s t s
● C o n n e c t t o C i r c l e C I
● M a k e C h a n g e s
● N o t i f i c a t i o n s
● N e x t S t e p s
● G i t W o r k f l o w s
● D e p e n d e n c y M a n a g e m e n t a n d V i r t u a l E n v i r o n m e n t s
● T e s t i n g
● P a c k a g i n g
● C o n t i n u o u s I n t e g r a t i o n
● C o n t i n u o u s D e p l o y m e n t
● O v e r v i e w o f C o n t i n u o u s I n t e g r a t i o n S e r v i c e s
● C o n c l u s i o n
R e m o v e a d s
W a t c h N o w T h i s t u t o r i a l h a s a r e l a t e d v i d e o c o u r s e c r e a t e d b y t h e R e a l P y t h o n t e a m . W a t c h i t t o g e t h e r w i t h t h e w r i t t e n t u t o r i a l t o d e e p e n y o u r u n d e r s t a n d i n g : C o n t i n u o u s I n t e g r a t i o n W i t h P y t h o n
W h e n w r i t i n g c o d e o n y o u r o w n , t h e o n l y p r i o r i t y i s m a k i n g i t w o r k . H o w e v e r , w o r k i n g i n a t e a m o f p r o f e s s i o n a l s o f t w a r e d e v e l o p e r s b r i n g s a p l e t h o r a o f c h a l l e n g e s . O n e o f t h o s e c h a l l e n g e s i s c o o r d i n a t i n g m a n y p e o p l e w o r k i n g o n t h e s a m e c o d e .
H o w d o p r o f e s s i o n a l t e a m s m a k e d o z e n s o f c h a n g e s p e r d a y w h i l e m a k i n g s u r e e v e r y o n e i s c o o r d i n a t e d a n d n o t h i n g i s b r o k e n ? E n t e r c o n t i n u o u s i n t e g r a t i o n !
I n t h i s t u t o r i a l y o u ’ l l :
● L e a r n t h e c o r e c o n c e p t s b e h i n d c o n t i n u o u s i n t e g r a t i o n
● U n d e r s t a n d t h e b e n e f i t s o f c o n t i n u o u s i n t e g r a t i o n
● S e t u p a b a s i c c o n t i n u o u s i n t e g r a t i o n s y s t e m
● C r e a t e a s i m p l e P y t h o n e x a m p l e a n d c o n n e c t i t t o t h e c o n t i n u o u s i n t e g r a t i o n s y s t e m
F r e e B o n u s : 5 T h o u g h t s O n P y t h o n M a s t e r y , a f r e e c o u r s e f o r P y t h o n d e v e l o p e r s t h a t s h o w s y o u t h e r o a d m a p a n d t h e m i n d s e t y o u ’ l l n e e d t o t a k e y o u r P y t h o n s k i l l s t o t h e n e x t l e v e l .
W h a t I s C o n t i n u o u s I n t e g r a t i o n ?
C o n t i n u o u s i n t e g r a t i o n ( CI ) i s t h e p r a c t i c e o f f r e q u e n t l y b u i l d i n g a n d t e s t i n g e a c h c h a n g e d o n e t o y o u r c o d e a u t o m a t i c a l l y a n d a s e a r l y a s p o s s i b l e . P r o l i f i c d e v e l o p e r a n d a u t h o r M a r t i n F o w l e r d e f i n e s C I a s f o l l o w s :
“ C o n t i n u o u s I n t e g r a t i o n i s a s o f t w a r e d e v e l o p m e n t p r a c t i c e w h e r e m e m b e r s o f a t e a m i n t e g r a t e t h e i r w o r k f r e q u e n t l y , u s u a l l y e a c h p e r s o n i n t e g r a t e s a t l e a s t d a i l y - l e a d i n g t o m u l t i p l e i n t e g r a t i o n s p e r d a y . E a c h i n t e g r a t i o n i s v e r i f i e d b y a n a u t o m a t e d b u i l d ( i n c l u d i n g t e s t ) t o d e t e c t i n t e g r a t i o n e r r o r s a s q u i c k l y a s p o s s i b l e . ” ( S o u r c e )
L e t ’ s u n p a c k t h i s .
P r o g r a m m i n g i s i t e r a t i v e . T h e s o u r c e c o d e l i v e s i n a r e p o s i t o r y t h a t i s s h a r e d b y a l l m e m b e r s o f t h e t e a m . I f y o u w a n t t o w o r k o n t h a t p r o d u c t , y o u m u s t o b t a i n a c o p y . Y o u w i l l m a k e c h a n g e s , t e s t t h e m , a n d i n t e g r a t e t h e m b a c k i n t o t h e m a i n r e p o . R i n s e a n d r e p e a t .
N o t s o l o n g a g o , t h e s e i n t e g r a t i o n s w e r e b i g a n d w e e k s ( o r m o n t h s ) a p a r t , c a u s i n g h e a d a c h e s , w a s t i n g t i m e , a n d l o s i n g m o n e y . A r m e d w i t h e x p e r i e n c e , d e v e l o p e r s s t a r t e d m a k i n g m i n o r c h a n g e s a n d i n t e g r a t i n g t h e m m o r e f r e q u e n t l y . T h i s r e d u c e s t h e c h a n c e s o f i n t r o d u c i n g c o n f l i c t s t h a t y o u n e e d t o r e s o l v e l a t e r .
A f t e r e v e r y i n t e g r a t i o n , y o u n e e d t o b u i l d t h e s o u r c e c o d e . B u i l d i n g m e a n s t r a n s f o r m i n g y o u r h i g h - l e v e l c o d e i n t o a f o r m a t y o u r c o m p u t e r k n o w s h o w t o r u n . F i n a l l y , t h e r e s u l t i s s y s t e m a t i c a l l y t e s t e d t o e n s u r e y o u r c h a n g e s d i d n o t i n t r o d u c e e r r o r s .
R e m o v e a d s
W h y S h o u l d I C a r e ?
O n a p e r s o n a l l e v e l , c o n t i n u o u s i n t e g r a t i o n i s r e a l l y a b o u t h o w y o u a n d y o u r c o l l e a g u e s s p e n d y o u r t i m e .
U s i n g C I , y o u ’ l l s p e n d l e s s t i m e :
● W o r r y i n g a b o u t i n t r o d u c i n g a b u g e v e r y t i m e y o u m a k e c h a n g e s
● F i x i n g t h e m e s s s o m e o n e e l s e m a d e s o y o u c a n i n t e g r a t e y o u r c o d e
● M a k i n g s u r e t h e c o d e w o r k s o n e v e r y m a c h i n e , o p e r a t i n g s y s t e m , a n d b r o w s e r
C o n v e r s e l y , y o u ’ l l s p e n d m o r e t i m e :
● S o l v i n g i n t e r e s t i n g p r o b l e m s
● W r i t i n g a w e s o m e c o d e w i t h y o u r t e a m
● C o - c r e a t i n g a m a z i n g p r o d u c t s t h a t p r o v i d e v a l u e t o u s e r s
H o w d o e s t h a t s o u n d ?
O n a t e a m l e v e l , i t a l l o w s f o r a b e t t e r e n g i n e e r i n g c u l t u r e , w h e r e y o u d e l i v e r v a l u e e a r l y a n d o f t e n . C o l l a b o r a t i o n i s e n c o u r a g e d , a n d b u g s a r e c a u g h t m u c h s o o n e r . C o n t i n u o u s i n t e g r a t i o n w i l l :
● M a k e y o u a n d y o u r t e a m f a s t e r
● G i v e y o u c o n f i d e n c e t h a t y o u ’ r e b u i l d i n g s t a b l e s o f t w a r e w i t h f e w e r b u g s
● E n s u r e t h a t y o u r p r o d u c t w o r k s o n o t h e r m a c h i n e s , n o t j u s t y o u r l a p t o p
● E l i m i n a t e a l o t o f t e d i o u s o v e r h e a d a n d l e t y o u f o c u s o n w h a t m a t t e r s
● R e d u c e t h e t i m e s p e n t r e s o l v i n g c o n f l i c t s ( w h e n d i f f e r e n t p e o p l e m o d i f y t h e s a m e c o d e )
C o r e C o n c e p t s
T h e r e a r e s e v e r a l k e y i d e a s a n d p r a c t i c e s t h a t y o u n e e d t o u n d e r s t a n d t o w o r k e f f e c t i v e l y w i t h c o n t i n u o u s i n t e g r a t i o n . A l s o , t h e r e m i g h t b e s o m e w o r d s a n d p h r a s e s y o u a r e n ’ t f a m i l i a r w i t h b u t a r e u s e d o f t e n w h e n y o u ’ r e t a l k i n g a b o u t C I . T h i s c h a p t e r w i l l i n t r o d u c e y o u t o t h e s e c o n c e p t s a n d t h e j a r g o n t h a t c o m e s w i t h t h e m .
S i n g l e S o u r c e R e p o s i t o r y
I f y o u a r e c o l l a b o r a t i n g w i t h o t h e r s o n a s i n g l e c o d e b a s e , i t ’ s t y p i c a l t o h a v e a s h a r e d r e p o s i t o r y o f s o u r c e c o d e . E v e r y d e v e l o p e r w o r k i n g o n t h e p r o j e c t c r e a t e s a l o c a l c o p y a n d m a k e s c h a n g e s . O n c e t h e y a r e s a t i s f i e d w i t h t h e c h a n g e s , t h e y m e r g e t h e m b a c k i n t o t h e c e n t r a l r e p o s i t o r y .
I t h a s b e c o m e a s t a n d a r d t o u s e v e r s i o n c o n t r o l s y s t e m s ( V C S ) l i k e G i t t o h a n d l e t h i s w o r k f l o w f o r y o u . T e a m s t y p i c a l l y u s e a n e x t e r n a l s e r v i c e t o h o s t t h e i r s o u r c e c o d e a n d h a n d l e a l l t h e m o v i n g p a r t s . T h e m o s t p o p u l a r a r e G i t H u b , B i t B u c k e t , a n d G i t L a b .
G i t a l l o w s y o u t o c r e a t e m u l t i p l e b r a n c h e s o f a r e p o s i t o r y . E a c h b r a n c h i s a n i n d e p e n d e n t c o p y o f t h e s o u r c e c o d e a n d c a n b e m o d i f i e d w i t h o u t a f f e c t i n g o t h e r b r a n c h e s . T h i s i s a n e s s e n t i a l f e a t u r e , a n d m o s t t e a m s h a v e a m a i n l i n e b r a n c h ( o f t e n c a l l e d a m a s t e r b r a n c h ) t h a t r e p r e s e n t s t h e c u r r e n t s t a t e o f t h e p r o j e c t .
I f y o u w a n t t o a d d o r m o d i f y c o d e , y o u s h o u l d c r e a t e a c o p y o f t h e m a i n b r a n c h a n d w o r k i n y o u r n e w , d e v e l o p m e n t b r a n c h . O n c e y o u a r e d o n e , m e r g e t h o s e c h a n g e s b a c k i n t o t h e m a s t e r b r a n c h .
G i t b r a n c h i n g
V e r s i o n c o n t r o l h o l d s m o r e t h a n j u s t c o d e . D o c u m e n t a t i o n a n d t e s t s c r i p t s a r e u s u a l l y s t o r e d a l o n g w i t h t h e s o u r c e c o d e . S o m e p r o g r a m s l o o k f o r e x t e r n a l f i l e s u s e d t o c o n f i g u r e t h e i r p a r a m e t e r s a n d i n i t i a l s e t t i n g s . O t h e r a p p l i c a t i o n s n e e d a d a t a b a s e s c h e m a . A l l t h e s e f i l e s s h o u l d g o i n t o y o u r r e p o s i t o r y .
I f y o u h a v e n e v e r u s e d G i t o r n e e d a r e f r e s h e r , c h e c k o u t o u r I n t r o d u c t i o n t o G i t a n d G i t H u b f o r P y t h o n D e v e l o p e r s .
A u t o m a t i n g t h e B u i l d
A s p r e v i o u s l y m e n t i o n e d , b u i l d i n g y o u r c o d e m e a n s t a k i n g t h e r a w s o u r c e c o d e , a n d e v e r y t h i n g n e c e s s a r y f o r i t s e x e c u t i o n , a n d t r a n s l a t i n g i t i n t o a f o r m a t t h a t c o m p u t e r s c a n r u n d i r e c t l y . P y t h o n i s a n i n t e r p r e t e d l a n g u a g e , s o i t s “ b u i l d ” m a i n l y r e v o l v e s a r o u n d t e s t e x e c u t i o n r a t h e r t h a n c o m p i l a t i o n .
R u n n i n g t h o s e s t e p s m a n u a l l y a f t e r e v e r y s m a l l c h a n g e i s t e d i o u s a n d t a k e s v a l u a b l e t i m e a n d a t t e n t i o n f r o m t h e a c t u a l p r o b l e m - s o l v i n g y o u ’ r e t r y i n g t o d o . A b i g p a r t o f c o n t i n u o u s i n t e g r a t i o n i s a u t o m a t i n g t h a t p r o c e s s a n d m o v i n g i t o u t o f s i g h t ( a n d o u t o f m i n d ) .
W h a t d o e s t h a t m e a n f o r P y t h o n ? T h i n k a b o u t a m o r e c o m p l i c a t e d p i e c e o f c o d e y o u h a v e w r i t t e n . I f y o u u s e d a l i b r a r y , p a c k a g e , o r f r a m e w o r k t h a t d o e s n ’ t c o m e w i t h t h e P y t h o n s t a n d a r d l i b r a r y ( t h i n k a n y t h i n g y o u n e e d e d t o i n s t a l l w i t h p i p or c o n d a ) , P y t h o n n e e d s t o k n o w a b o u t t h a t , s o t h e p r o g r a m k n o w s w h e r e t o l o o k w h e n i t f i n d s c o m m a n d s t h a t i t d o e s n ’ t r e c o g n i z e .
Y o u s t o r e a l i s t o f t h o s e p a c k a g e s in r e q u i r e m e n t s . t x t o r a P i p f i l e . T h e s e a r e t h e d e p e n d e n c i e s o f y o u r c o d e a n d a r e n e c e s s a r y f o r a s u c c e s s f u l b u i l d .
Y o u w i l l o f t e n h e a r t h e p h r a s e “ b r e a k i n g t h e b u i l d . ” W h e n y o u b r e a k t h e b u i l d , i t m e a n s y o u i n t r o d u c e d a c h a n g e t h a t r e n d e r e d t h e f i n a l p r o d u c t u n u s a b l e . D o n ’ t w o r r y . I t h a p p e n s t o e v e r y o n e , e v e n b a t t l e - h a r d e n e d s e n i o r d e v e l o p e r s . Y o u w a n t t o a v o i d t h i s p r i m a r i l y b e c a u s e i t w i l l b l o c k e v e r y o n e e l s e f r o m w o r k i n g .
T h e w h o l e p o i n t o f C I i s t o h a v e e v e r y o n e w o r k i n g o n a k n o w n s t a b l e b a s e . I f t h e y c l o n e a r e p o s i t o r y t h a t i s b r e a k i n g t h e b u i l d , t h e y w i l l w o r k w i t h a b r o k e n v e r s i o n o f t h e c o d e a n d w o n ’ t b e a b l e t o i n t r o d u c e o r t e s t t h e i r c h a n g e s . W h e n y o u b r e a k t h e b u i l d , t h e t o p p r i o r i t y i s f i x i n g i t s o e v e r y o n e c a n r e s u m e w o r k .
I n t r o d u c i n g a b r e a k i n g c h a n g e t o t h e m a s t e r b r a n c h
W h e n t h e b u i l d i s a u t o m a t e d , y o u a r e e n c o u r a g e d t o c o m m i t f r e q u e n t l y , u s u a l l y m u l t i p l e t i m e s p e r d a y . I t a l l o w s p e o p l e t o q u i c k l y f i n d o u t a b o u t c h a n g e s a n d n o t i c e i f t h e r e ’ s a c o n f l i c t b e t w e e n t w o d e v e l o p e r s . I f t h e r e a r e n u m e r o u s s m a l l c h a n g e s i n s t e a d o f a f e w m a s s i v e u p d a t e s , i t ’ s m u c h e a s i e r t o l o c a t e w h e r e t h e e r r o r o r i g i n a t e d . I t w i l l a l s o e n c o u r a g e y o u t o b r e a k y o u r w o r k d o w n i n t o s m a l l e r c h u n k s , w h i c h i s e a s i e r t o t r a c k a n d t e s t .
R e m o v e a d s
A u t o m a t e d T e s t i n g
S i n c e e v e r y o n e i s c o m m i t t i n g c h a n g e s m u l t i p l e t i m e s p e r d a y , i t ’ s i m p o r t a n t t o k n o w t h a t y o u r c h a n g e d i d n ’ t b r e a k a n y t h i n g e l s e i n t h e c o d e o r i n t r o d u c e b u g s . I n m a n y c o m p a n i e s , t e s t i n g i s n o w a r e s p o n s i b i l i t y o f e v e r y d e v e l o p e r . I f y o u w r i t e c o d e , y o u s h o u l d w r i t e t e s t s . A t a b a r e m i n i m u m , y o u s h o u l d c o v e r e v e r y n e w f u n c t i o n w i t h a u n i t t e s t .
R u n n i n g t e s t s a u t o m a t i c a l l y , w i t h e v e r y c h a n g e c o m m i t t e d , i s a g r e a t w a y t o c a t c h b u g s . A f a i l i n g t e s t a u t o m a t i c a l l y c a u s e s t h e b u i l d t o f a i l . I t w i l l d r a w y o u r a t t e n t i o n t o t h e p r o b l e m s r e v e a l e d b y t e s t i n g , a n d t h e f a i l e d b u i l d w i l l m a k e y o u f i x t h e b u g y o u i n t r o d u c e d . T e s t s d o n ’ t g u a r a n t e e t h a t y o u r c o d e i s f r e e o f b u g s , b u t i t d o e s g u a r d a g a i n s t a l o t o f c a r e l e s s c h a n g e s .
A u t o m a t i n g t e s t e x e c u t i o n g i v e s y o u s o m e p e a c e o f m i n d b e c a u s e y o u k n o w t h e s e r v e r w i l l t e s t y o u r c o d e e v e r y t i m e y o u c o m m i t , e v e n i f y o u f o r g o t t o d o i t l o c a l l y .
U s i n g a n E x t e r n a l C o n t i n u o u s I n t e g r a t i o n S e r v i c e
I f s o m e t h i n g w o r k s o n y o u r c o m p u t e r , w i l l i t w o r k o n e v e r y c o m p u t e r ? P r o b a b l y n o t . I t ’ s a c l i c h é e x c u s e a n d a s o r t o f i n s i d e j o k e a m o n g d e v e l o p e r s t o s a y , “ W e l l , i t w o r k e d o n m y m a c h i n e ! ” M a k i n g t h e c o d e w o r k l o c a l l y i s n o t t h e e n d o f y o u r r e s p o n s i b i l i t y .
T o t a c k l e t h i s p r o b l e m , m o s t c o m p a n i e s u s e a n e x t e r n a l s e r v i c e t o h a n d l e i n t e g r a t i o n , m u c h l i k e u s i n g G i t H u b f o r h o s t i n g y o u r s o u r c e c o d e r e p o s i t o r y . E x t e r n a l s e r v i c e s h a v e s e r v e r s w h e r e t h e y b u i l d c o d e a n d r u n t e s t s . T h e y a c t a s m o n i t o r s f o r y o u r r e p o s i t o r y a n d s t o p a n y o n e f r o m m e r g i n g t o t h e m a s t e r b r a n c h i f t h e i r c h a n g e s b r e a k t h e b u i l d .
M e r g i n g c h a n g e s t r i g g e r s t h e C I s e r v e r
T h e r e a r e m a n y s u c h s e r v i c e s o u t t h e r e , w i t h v a r i o u s f e a t u r e s a n d p r i c i n g . M o s t h a v e a f r e e t i e r s o t h a t y o u c a n e x p e r i m e n t w i t h o n e o f y o u r r e p o s i t o r i e s . Y o u w i l l u s e a s e r v i c e c a l l e d C i r c l e C I i n a n e x a m p l e l a t e r i n t h e t u t o r i a l .
T e s t i n g i n a S t a g i n g E n v i r o n m e n t
A p r o d u c t i o n e n v i r o n m e n t i s w h e r e y o u r s o f t w a r e w i l l u l t i m a t e l y r u n . E v e n a f t e r s u c c e s s f u l l y b u i l d i n g a n d t e s t i n g y o u r a p p l i c a t i o n , y o u c a n ’ t b e s u r e t h a t y o u r c o d e w i l l w o r k o n t h e t a r g e t c o m p u t e r . T h a t ’ s w h y t e a m s d e p l o y t h e f i n a l p r o d u c t i n a n e n v i r o n m e n t t h a t m i m i c s t h e p r o d u c t i o n e n v i r o n m e n t . O n c e y o u a r e s u r e e v e r y t h i n g w o r k s , t h e a p p l i c a t i o n i s d e p l o y e d i n t h e p r o d u c t i o n e n v i r o n m e n t .
N o t e : T h i s s t e p i s m o r e r e l e v a n t t o a p p l i c a t i o n c o d e t h a n l i b r a r y c o d e . A n y P y t h o n l i b r a r i e s y o u w r i t e s t i l l n e e d t o b e t e s t e d o n a b u i l d s e r v e r , t o e n s u r e t h e y w o r k i n e n v i r o n m e n t s d i f f e r e n t f r o m y o u r l o c a l c o m p u t e r .
Y o u w i l l h e a r p e o p l e t a l k i n g a b o u t t h i s c l o n e o f t h e p r o d u c t i o n e n v i r o n m e n t u s i n g t e r m s l i k e d e v e l o p m e n t e n v i r o n m e n t , s t a g i n g e n v i r o n m e n t , o r t e s t i n g e n v i r o n m e n t . I t ’ s c o m m o n t o u s e a b b r e v i a t i o n s l i k e D E V f o r t h e d e v e l o p m e n t e n v i r o n m e n t a n d P R O D f o r t h e p r o d u c t i o n e n v i r o n m e n t .
T h e d e v e l o p m e n t e n v i r o n m e n t s h o u l d r e p l i c a t e p r o d u c t i o n c o n d i t i o n s a s c l o s e l y a s p o s s i b l e . T h i s s e t u p i s o f t e n c a l l e d D E V / P R O D p a r i t y . K e e p t h e e n v i r o n m e n t o n y o u r l o c a l c o m p u t e r a s s i m i l a r a s p o s s i b l e t o t h e D E V a n d P R O D e n v i r o n m e n t s t o m i n i m i z e a n o m a l i e s w h e n d e p l o y i n g a p p l i c a t i o n s .
T e s t i n a c l o n e o f t h e p r o d u c t i o n e n v i r o n m e n t
W e m e n t i o n t h i s t o i n t r o d u c e y o u t o t h e v o c a b u l a r y , b u t c o n t i n u o u s l y d e p l o y i n g s o f t w a r e t o D E V a n d P R O D i s a w h o l e o t h e r t o p i c . T h e p r o c e s s i s c a l l e d , u n s u r p r i s i n g l y , c o n t i n u o u s d e p l o y m e n t ( CD ) . Y o u c a n f i n d m o r e r e s o u r c e s a b o u t i t i n t h e N e x t S t e p s s e c t i o n o f t h i s a r t i c l e .
Y o u r T u r n !
T h e b e s t w a y t o l e a r n i s b y d o i n g . Y o u n o w u n d e r s t a n d a l l t h e e s s e n t i a l p r a c t i c e s o f c o n t i n u o u s i n t e g r a t i o n , s o i t ’ s t i m e t o g e t y o u r h a n d s d i r t y a n d c r e a t e t h e w h o l e c h a i n o f s t e p s n e c e s s a r y t o u s e C I . T h i s c h a i n i s o f t e n c a l l e d a C I p i p e l i n e .
T h i s i s a h a n d s - o n t u t o r i a l , s o f i r e u p y o u r e d i t o r a n d g e t r e a d y t o w o r k t h r o u g h t h e s e s t e p s a s y o u r e a d !
W e a s s u m e t h a t y o u k n o w t h e b a s i c s o f P y t h o n a n d G i t . W e w i l l u s e G i t h u b a s o u r h o s t i n g s e r v i c e a n d C i r c l e C I a s o u r e x t e r n a l c o n t i n u o u s i n t e g r a t i o n s e r v i c e . I f y o u d o n ’ t h a v e a c c o u n t s w i t h t h e s e s e r v i c e s , g o a h e a d a n d r e g i s t e r . B o t h o f t h e s e h a v e f r e e t i e r s !
R e m o v e a d s
P r o b l e m D e f i n i t i o n
R e m e m b e r , y o u r f o c u s h e r e i s a d d i n g a n e w t o o l t o y o u r u t i l i t y b e l t , c o n t i n u o u s i n t e g r a t i o n . F o r t h i s e x a m p l e , t h e P y t h o n c o d e i t s e l f w i l l b e s t r a i g h t f o r w a r d . Y o u w a n t t o s p e n d t h e b u l k o f y o u r t i m e i n t e r n a l i z i n g t h e s t e p s o f b u i l d i n g a p i p e l i n e , i n s t e a d o f w r i t i n g c o m p l i c a t e d c o d e .
I m a g i n e y o u r t e a m i s w o r k i n g o n a s i m p l e c a l c u l a t o r a p p . Y o u r t a s k i s t o w r i t e a l i b r a r y o f b a s i c m a t h e m a t i c a l f u n c t i o n s : a d d i t i o n , s u b t r a c t i o n , m u l t i p l i c a t i o n , a n d d i v i s i o n . Y o u d o n ’ t c a r e a b o u t t h e a c t u a l a p p l i c a t i o n , b e c a u s e t h a t ’ s w h a t y o u r p e e r s w i l l b e d e v e l o p i n g , u s i n g f u n c t i o n s f r o m y o u r l i b r a r y .
C r e a t e a R e p o
L o g i n t o y o u r G i t H u b a c c o u n t , c r e a t e a n e w r e p o s i t o r y a n d c a l l i t C a l c u l a t o r L i b r a r y . A d d a R E A D M E a n d . g i t i g n o r e , t h e n c l o n e t h e r e p o s i t o r y t o y o u r l o c a l m a c h i n e . I f y o u n e e d m o r e h e l p w i t h t h i s p r o c e s s , h a v e a l o o k a t G i t H u b ’ s w a l k t h r o u g h o n c r e a t i n g a n e w r e p o s i t o r y .
S e t U p a W o r k i n g E n v i r o n m e n t
F o r o t h e r s ( a n d t h e C I s e r v e r ) t o r e p l i c a t e y o u r w o r k i n g c o n d i t i o n s , y o u n e e d t o s e t u p a n e n v i r o n m e n t . C r e a t e a v i r t u a l e n v i r o n m e n t s o m e w h e r e o u t s i d e y o u r r e p o a n d a c t i v a t e i t :
$ # Create virtual environment
$ python3 -m venv calculator
$ # Activate virtual environment (Mac and Linux)
$ . calculator/bin/activate
T h e p r e v i o u s c o m m a n d s w o r k o n m a c O S a n d L i n u x . I f y o u a r e a W i n d o w s u s e r , c h e c k t h e P l a t f o r m s t a b l e i n t h e o f f i c i a l d o c u m e n t a t i o n . T h i s w i l l c r e a t e a d i r e c t o r y t h a t c o n t a i n s a P y t h o n i n s t a l l a t i o n a n d t e l l t h e i n t e r p r e t e r t o u s e i t . N o w w e c a n i n s t a l l p a c k a g e s k n o w i n g t h a t i t w i l l n o t i n f l u e n c e y o u r s y s t e m ’ s d e f a u l t P y t h o n i n s t a l l a t i o n .
W r i t e a S i m p l e P y t h o n E x a m p l e
C r e a t e a n e w f i l e c a l l e d c a l c u l a t o r . p y i n t h e t o p - l e v e l d i r e c t o r y o f y o u r r e p o s i t o r y , a n d c o p y t h e f o l l o w i n g c o d e :
"""
Calculator library containing basic math operations.
"""
def add ( first_term , second_term ):
return first_term + second_term
def subtract ( first_term , second_term ):
return first_term - second_term
T h i s i s a b a r e - b o n e s e x a m p l e c o n t a i n i n g t w o o f t h e f o u r f u n c t i o n s w e w i l l b e w r i t i n g . O n c e w e h a v e o u r C I p i p e l i n e u p a n d r u n n i n g , y o u w i l l a d d t h e r e m a i n i n g t w o f u n c t i o n s .
G o a h e a d a n d c o m m i t t h o s e c h a n g e s :
$ # Make sure you are in the correct directory
$ cd CalculatorLibrary
$ git add calculator.py
$ git commit -m "Add functions for addition and subtraction"
Y o u r C a l c u l a t o r L i b r a r y f o l d e r s h o u l d h a v e t h e f o l l o w i n g f i l e s r i g h t n o w :
CalculatorLibrary/
|
├── .git
├── .gitignore
├── README.md
└── calculator.py
G r e a t , y o u h a v e c o m p l e t e d o n e p a r t o f t h e r e q u i r e d f u n c t i o n a l i t y . T h e n e x t s t e p i s a d d i n g t e s t s t o m a k e s u r e y o u r c o d e w o r k s t h e w a y i t ’ s s u p p o s e d t o .
W r i t e U n i t T e s t s
Y o u w i l l t e s t y o u r c o d e i n t w o s t e p s .
T h e f i r s t s t e p i n v o l v e s l i n t i n g — r u n n i n g a p r o g r a m , c a l l e d a l i n t e r , t o a n a l y z e c o d e f o r p o t e n t i a l e r r o r s . f l a k e 8 i s c o m m o n l y u s e d t o c h e c k i f y o u r c o d e c o n f o r m s t o t h e s t a n d a r d P y t h o n c o d i n g s t y l e . L i n t i n g m a k e s s u r e y o u r c o d e i s e a s y t o r e a d f o r t h e r e s t o f t h e P y t h o n c o m m u n i t y .
T h e s e c o n d s t e p i s u n i t t e s t i n g . A u n i t t e s t i s d e s i g n e d t o c h e c k a s i n g l e f u n c t i o n , o r u n i t , o f c o d e . P y t h o n c o m e s w i t h a s t a n d a r d u n i t t e s t i n g l i b r a r y , b u t o t h e r l i b r a r i e s e x i s t a n d a r e v e r y p o p u l a r . T h i s e x a m p l e u s e s p y t e s t .
A s t a n d a r d p r a c t i c e t h a t g o e s h a n d i n h a n d w i t h t e s t i n g i s c a l c u l a t i n g c o d e c o v e r a g e . C o d e c o v e r a g e i s t h e p e r c e n t a g e o f s o u r c e c o d e t h a t i s “ c o v e r e d ” b y y o u r t e s t s . p y t e s t h a s a n e x t e n s i o n , p y t e s t - c o v , t h a t h e l p s y o u u n d e r s t a n d y o u r c o d e c o v e r a g e .
T h e s e a r e e x t e r n a l d e p e n d e n c i e s , a n d y o u n e e d t o i n s t a l l t h e m :
$ pip install flake8 pytest pytest-cov
T h e s e a r e t h e o n l y e x t e r n a l p a c k a g e s y o u w i l l u s e . M a k e s u r e t o s t o r e t h o s e d e p e n d e n c i e s i n a r e q u i r e m e n t s . t x t f i l e s o o t h e r s c a n r e p l i c a t e y o u r e n v i r o n m e n t :
$ pip freeze > requirements.txt
T o r u n y o u r l i n t e r , e x e c u t e t h e f o l l o w i n g :
$ flake8 --statistics
./calculator.py:3:1: E302 expected 2 blank lines, found 1
./calculator.py:6:1: E302 expected 2 blank lines, found 1
2 E302 expected 2 blank lines, found 1
T h e - - s t a t i s t i c s o p t i o n g i v e s y o u a n o v e r v i e w o f h o w m a n y t i m e s a p a r t i c u l a r e r r o r h a p p e n e d . H e r e w e h a v e t w o P E P 8 v i o l a t i o n s , b e c a u s e f l a k e 8 e x p e c t s t w o b l a n k l i n e s b e f o r e a f u n c t i o n d e f i n i t i o n i n s t e a d o f o n e . G o a h e a d a n d a d d a n e m p t y l i n e b e f o r e e a c h f u n c t i o n s d e f i n i t i o n . R u n f l a k e 8 a g a i n t o c h e c k t h a t t h e e r r o r m e s s a g e s n o l o n g e r a p p e a r .
N o w i t ’ s t i m e t o w r i t e t h e t e s t s . C r e a t e a f i l e c a l l e d t e s t _ c a l c u l a t o r . p y i n t h e t o p - l e v e l d i r e c t o r y o f y o u r r e p o s i t o r y a n d c o p y t h e f o l l o w i n g c o d e :
"""
Unit tests for the calculator library
"""
import calculator
class TestCalculator :
def test_addition ( self ):
assert 4 == calculator . add ( 2 , 2 )
def test_subtraction ( self ):
assert 2 == calculator . subtract ( 4 , 2 )
T h e s e t e s t s m a k e s u r e t h a t o u r c o d e w o r k s a s e x p e c t e d . I t i s f a r f r o m e x t e n s i v e b e c a u s e y o u h a v e n ’ t t e s t e d f o r p o t e n t i a l m i s u s e o f y o u r c o d e , b u t k e e p i t s i m p l e f o r n o w .
T h e f o l l o w i n g c o m m a n d r u n s y o u r t e s t :
$ pytest -v --cov
collected 2 items
test_calculator.py::TestCalculator::test_addition PASSED [50%]
test_calculator.py::TestCalculator::test_subtraction PASSED [100%]
---------- coverage: platform darwin, python 3.6.6-final-0 -----------
Name Stmts Miss Cover
---------------------------------------------------------------------
calculator.py 4 0 100%
test_calculator.py 6 0 100%
/Users/kristijan.ivancic/code/learn/__init__.py 0 0 100%
---------------------------------------------------------------------
TOTAL 10 0 100%
p y t e s t i s e x c e l l e n t a t t e s t d i s c o v e r y . B e c a u s e y o u h a v e a f i l e w i t h t h e p r e f i x t e s t , p y t e s t k n o w s i t w i l l c o n t a i n u n i t t e s t s f o r i t t o r u n . T h e s a m e p r i n c i p l e s a p p l y t o t h e c l a s s a n d m e t h o d n a m e s i n s i d e t h e f i l e .
T h e - v f l a g g i v e s y o u a n i c e r o u t p u t , t e l l i n g y o u w h i c h t e s t s p a s s e d a n d w h i c h f a i l e d . I n o u r c a s e , b o t h t e s t s p a s s e d . T h e - - c o v f l a g m a k e s s u r e p y t e s t - c o v r u n s a n d g i v e s y o u a c o d e c o v e r a g e r e p o r t f o r c a l c u l a t o r . p y .
Y o u h a v e c o m p l e t e d t h e p r e p a r a t i o n s . C o m m i t t h e t e s t f i l e a n d p u s h a l l t h o s e c h a n g e s t o t h e m a s t e r b r a n c h :
$ git add test_calculator.py
$ git commit -m "Add unit tests for calculator"
$ git push
A t t h e e n d o f t h i s s e c t i o n , y o u r C a l c u l a t o r L i b r a r y f o l d e r s h o u l d h a v e t h e f o l l o w i n g f i l e s :
CalculatorLibrary/
|
├── .git
├── .gitignore
├── README.md
├── calculator.py
├── requirements.txt
└── test_calculator.py
E x c e l l e n t , b o t h y o u r f u n c t i o n s a r e t e s t e d a n d w o r k c o r r e c t l y .
R e m o v e a d s
C o n n e c t t o C i r c l e C I
A t l a s t , y o u a r e r e a d y t o s e t u p y o u r c o n t i n u o u s i n t e g r a t i o n p i p e l i n e !
C i r c l e C I n e e d s t o k n o w h o w t o r u n y o u r b u i l d a n d e x p e c t s t h a t i n f o r m a t i o n t o b e s u p p l i e d i n a p a r t i c u l a r f o r m a t . I t r e q u i r e s a . c i r c l e c i f o l d e r w i t h i n y o u r r e p o a n d a c o n f i g u r a t i o n f i l e i n s i d e i t . A c o n f i g u r a t i o n f i l e c o n t a i n s i n s t r u c t i o n s f o r a l l t h e s t e p s t h a t t h e b u i l d s e r v e r n e e d s t o e x e c u t e . C i r c l e C I e x p e c t s t h i s f i l e t o b e c a l l e d c o n f i g . y m l .
A . y m l f i l e u s e s a d a t a s e r i a l i z a t i o n l a n g u a g e , Y A M L , a n d i t h a s i t s o w n s p e c i f i c a t i o n . T h e g o a l o f Y A M L i s t o b e h u m a n r e a d a b l e a n d t o w o r k w e l l w i t h m o d e r n p r o g r a m m i n g l a n g u a g e s f o r c o m m o n , e v e r y d a y t a s k s .
I n a Y A M L f i l e , t h e r e a r e t h r e e b a s i c w a y s t o r e p r e s e n t d a t a :
● M a p p i n g s ( k e y - v a l u e p a i r s )
● S e q u e n c e s ( l i s t s )
● S c a l a r s ( s t r i n g s o r n u m b e r s )
I t i s v e r y s i m p l e t o r e a d :
● I n d e n t a t i o n m a y b e u s e d f o r s t r u c t u r e .
● C o l o n s s e p a r a t e k e y - v a l u e p a i r s .
● D a s h e s a r e u s e d t o c r e a t e l i s t s .
C r e a t e t h e . c i r c l e c i f o l d e r i n y o u r r e p o a n d a c o n f i g . y m l f i l e w i t h t h e f o l l o w i n g c o n t e n t :
# Python CircleCI 2.0 configuration file
version : 2
jobs :
build :
docker :
- image : circleci/python:3.7
working_directory : ~/repo
steps :
# Step 1: obtain repo from GitHub
- checkout
# Step 2: create virtual env and install dependencies
- run :
name : install dependencies
command : |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
# Step 3: run linter and tests
- run :
name : run tests
command : |
. venv/bin/activate
flake8 --exclude=venv* --statistics
pytest -v --cov=calculator
S o m e o f t h e s e w o r d s a n d c o n c e p t s m i g h t b e u n f a m i l i a r t o y o u . F o r e x a m p l e , w h a t i s D o c k e r , a n d w h a t a r e i m a g e s ? L e t ’ s g o b a c k i n t i m e a b i t .
R e m e m b e r t h e p r o b l e m p r o g r a m m e r s f a c e w h e n s o m e t h i n g w o r k s o n t h e i r l a p t o p b u t n o w h e r e e l s e ? B e f o r e , d e v e l o p e r s u s e d t o c r e a t e a p r o g r a m t h a t i s o l a t e s a p a r t o f t h e c o m p u t e r ’ s p h y s i c a l r e s o u r c e s ( m e m o r y , h a r d d r i v e , a n d s o o n ) a n d t u r n s t h e m i n t o a v i r t u a l m a c h i n e .
A v i r t u a l m a c h i n e p r e t e n d s t o b e a w h o l e c o m p u t e r o n i t s o w n . I t w o u l d e v e n h a v e i t s o w n o p e r a t i n g s y s t e m . O n t h a t o p e r a t i n g s y s t e m , y o u d e p l o y y o u r a p p l i c a t i o n o r i n s t a l l y o u r l i b r a r y a n d t e s t i t .
V i r t u a l m a c h i n e s t a k e u p a l o t o f r e s o u r c e s , w h i c h s p a r k e d t h e i n v e n t i o n o f c o n t a i n e r s . T h e i d e a i s a n a l o g o u s t o s h i p p i n g c o n t a i n e r s . B e f o r e s h i p p i n g c o n t a i n e r s w e r e i n v e n t e d , m a n u f a c t u r e r s h a d t o s h i p g o o d s i n a w i d e v a r i e t y o f s i z e s , p a c k a g i n g , a n d m o d e s ( t r u c k s , t r a i n s , s h i p s ) .
B y s t a n d a r d i z i n g t h e s h i p p i n g c o n t a i n e r , t h e s e g o o d s c o u l d b e t r a n s f e r r e d b e t w e e n d i f f e r e n t s h i p p i n g m e t h o d s w i t h o u t a n y m o d i f i c a t i o n . T h e s a m e i d e a a p p l i e s t o s o f t w a r e c o n t a i n e r s .
C o n t a i n e r s a r e a l i g h t w e i g h t u n i t o f c o d e a n d i t s r u n t i m e d e p e n d e n c i e s , p a c k a g e d i n a s t a n d a r d i z e d w a y , s o t h e y c a n q u i c k l y b e p l u g g e d i n a n d r u n o n t h e L i n u x O S . Y o u d o n ’ t n e e d t o c r e a t e a w h o l e v i r t u a l o p e r a t i n g s y s t e m , a s y o u w o u l d w i t h a v i r t u a l m a c h i n e .
C o n t a i n e r s o n l y r e p l i c a t e p a r t s o f t h e o p e r a t i n g s y s t e m t h e y n e e d i n o r d e r t o w o r k . T h i s r e d u c e s t h e i r s i z e a n d g i v e s t h e m a b i g p e r f o r m a n c e b o o s t .
D o c k e r i s c u r r e n t l y t h e l e a d i n g c o n t a i n e r p l a t f o r m , a n d i t ’ s e v e n a b l e t o r u n L i n u x c o n t a i n e r s o n W i n d o w s a n d m a c O S . T o c r e a t e a D o c k e r c o n t a i n e r , y o u n e e d a D o c k e r i m a g e . I m a g e s p r o v i d e b l u e p r i n t s f o r c o n t a i n e r s m u c h l i k e c l a s s e s p r o v i d e b l u e p r i n t s f o r o b j e c t s . Y o u c a n r e a d m o r e a b o u t D o c k e r i n t h e i r G e t S t a r t e d g u i d e .
C i r c l e C I m a i n t a i n s p r e - b u i l t D o c k e r i m a g e s f o r s e v e r a l p r o g r a m m i n g l a n g u a g e s . I n t h e a b o v e c o n f i g u r a t i o n f i l e , y o u h a v e s p e c i f i e d a L i n u x i m a g e t h a t h a s P y t h o n a l r e a d y i n s t a l l e d . T h a t i m a g e w i l l c r e a t e a c o n t a i n e r i n w h i c h e v e r y t h i n g e l s e h a p p e n s .
L e t ’ s l o o k a t e a c h l i n e o f t h e c o n f i g u r a t i o n f i l e i n t u r n :
v e r s i o n : E v e r y c o n f i g . y m l s t a r t s w i t h t h e C i r c l e C I v e r s i o n n u m b e r , u s e d t o i s s u e w a r n i n g s a b o u t b r e a k i n g c h a n g e s .
j o b s : J o b s r e p r e s e n t a s i n g l e e x e c u t i o n o f t h e b u i l d a n d a r e d e f i n e d b y a c o l l e c t i o n o f s t e p s . I f y o u h a v e o n l y o n e j o b , i t m u s t b e c a l l e d b u i l d .
b u i l d : A s m e n t i o n e d b e f o r e , b u i l d i s t h e n a m e o f y o u r j o b . Y o u c a n h a v e m u l t i p l e j o b s , i n w h i c h c a s e t h e y n e e d t o h a v e u n i q u e n a m e s .
d o c k e r : T h e s t e p s o f a j o b o c c u r i n a n e n v i r o n m e n t c a l l e d a n e x e c u t o r . T h e c o m m o n e x e c u t o r i n C i r c l e C I i s a D o c k e r c o n t a i n e r . I t i s a c l o u d - h o s t e d e x e c u t i o n e n v i r o n m e n t b u t o t h e r o p t i o n s e x i s t , l i k e a m a c O S e n v i r o n m e n t .
i m a g e : A D o c k e r i m a g e i s a f i l e u s e d t o c r e a t e a r u n n i n g D o c k e r c o n t a i n e r . W e a r e u s i n g a n i m a g e t h a t h a s P y t h o n 3 . 7 p r e i n s t a l l e d .
w o r k i n g _ d i r e c t o r y : Y o u r r e p o s i t o r y h a s t o b e c h e c k e d o u t s o m e w h e r e o n t h e b u i l d s e r v e r . T h e w o r k i n g d i r e c t o r y r e p r e s e n t s t h e f i l e p a t h w h e r e t h e r e p o s i t o r y w i l l b e s t o r e d .
s t e p s : T h i s k e y m a r k s t h e s t a r t o f a l i s t o f s t e p s t o b e p e r f o r m e d b y t h e b u i l d s e r v e r .
c h e c k o u t : T h e f i r s t s t e p t h e s e r v e r n e e d s t o d o i s c h e c k t h e s o u r c e c o d e o u t t o t h e w o r k i n g d i r e c t o r y . T h i s i s p e r f o r m e d b y a s p e c i a l s t e p c a l l e d c h e c k o u t .
r u n : E x e c u t i n g c o m m a n d - l i n e p r o g r a m s o r c o m m a n d s i s d o n e i n s i d e t h e c o m m a n d k e y . T h e a c t u a l s h e l l c o m m a n d s w i l l b e n e s t e d w i t h i n .
n a m e : T h e C i r c l e C I u s e r i n t e r f a c e s h o w s y o u e v e r y b u i l d s t e p i n t h e f o r m o f a n e x p a n d a b l e s e c t i o n . T h e t i t l e o f t h e s e c t i o n i s t a k e n f r o m t h e v a l u e a s s o c i a t e d w i t h t h e n a m e k e y .
c o m m a n d : T h i s k e y r e p r e s e n t s t h e c o m m a n d t o r u n v i a t h e s h e l l . T h e | s y m b o l s p e c i f i c e s t h a t w h a t f o l l o w s i s a l i t e r a l s e t o f c o m m a n d s , o n e p e r l i n e , e x a c t l y l i k e y o u ’ d s e e i n a s h e l l / b a s h s c r i p t .
Y o u c a n r e a d t h e C i r c l e C I c o n f i g u r a t i o n r e f e r e n c e d o c u m e n t f o r m o r e i n f o r m a t i o n .
O u r p i p e l i n e i s v e r y s i m p l e a n d c o n s i s t s o f 3 s t e p s :
(一) C h e c k i n g o u t t h e r e p o s i t o r y
(二) I n s t a l l i n g t h e d e p e n d e n c i e s i n a v i r t u a l e n v i r o n m e n t
(三) R u n n i n g t h e l i n t e r a n d t e s t s w h i l e i n s i d e t h e v i r t u a l e n v i r o n m e n t
W e n o w h a v e e v e r y t h i n g w e n e e d t o s t a r t o u r p i p e l i n e . L o g i n t o y o u r C i r c l e C I a c c o u n t a n d c l i c k o n A d d P r o j e c t s . F i n d y o u r C a l c u l a t o r L i b r a r y r e p o a n d c l i c k S e t U p P r o j e c t . S e l e c t P y t h o n a s y o u r l a n g u a g e . S i n c e w e a l r e a d y h a v e a c o n f i g . y m l , w e c a n s k i p t h e n e x t s t e p s a n d c l i c k S t a r t b u i l d i n g .
C i r c l e C I w i l l t a k e y o u t o t h e e x e c u t i o n d a s h b o a r d f o r y o u r j o b . I f y o u f o l l o w e d a l l t h e s t e p s c o r r e c t l y , y o u s h o u l d s e e y o u r j o b s u c c e e d .
T h e f i n a l v e r s i o n o f y o u r C a l c u l a t o r L i b r a r y f o l d e r s h o u l d l o o k l i k e t h i s :
CalculatorRepository/
|
├── .circleci
├── .git
├── .gitignore
├── README.md
├── calculator.py
├── requirements.txt
└── test_calculator.py
C o n g r a t u l a t i o n s ! Y o u h a v e c r e a t e d y o u r f i r s t c o n t i n u o u s i n t e g r a t i o n p i p e l i n e . N o w , e v e r y t i m e y o u p u s h t o t h e m a s t e r b r a n c h , a j o b w i l l b e t r i g g e r e d . Y o u c a n s e e a l i s t o f y o u r c u r r e n t a n d p a s t j o b s b y c l i c k i n g o n J o b s i n t h e C i r c l e C I s i d e b a r .
R e m o v e a d s
M a k e C h a n g e s
T i m e t o a d d m u l t i p l i c a t i o n t o o u r c a l c u l a t o r l i b r a r y .
T h i s t i m e , w e w i l l f i r s t a d d a u n i t t e s t w i t h o u t w r i t i n g t h e f u n c t i o n . W i t h o u t t h e c o d e , t h e t e s t w i l l f a i l , w h i c h w i l l a l s o f a i l t h e C i r c l e C I j o b . A d d t h e f o l l o w i n g c o d e t o t h e e n d o f y o u r t e s t _ c a l c u l a t o r . p y :
def test_multiplication ( self ):
assert 100 == calculator . multiply ( 10 , 10 )
P u s h t h e c o d e t o t h e m a s t e r b r a n c h a n d s e e t h e j o b f a i l i n C i r c l e C I . T h i s s h o w s t h a t c o n t i n u o u s i n t e g r a t i o n w o r k s a n d w a t c h e s y o u r b a c k i f y o u m a k e a m i s t a k e .
N o w a d d t h e c o d e t o c a l c u l a t o r . p y t h a t w i l l m a k e t h e t e s t p a s s :
def multiply ( first_term , second_term ):
return first_term * second_term
M a k e s u r e t h e r e a r e t w o e m p t y s p a c e s b e t w e e n t h e m u l t i p l i c a t i o n f u n c t i o n a n d t h e p r e v i o u s o n e , o r e l s e y o u r c o d e w i l l f a i l t h e l i n t e r c h e c k .
T h e j o b s h o u l d b e s u c c e s s f u l t h i s t i m e . T h i s w o r k f l o w o f w r i t i n g a f a i l i n g t e s t f i r s t a n d t h e n a d d i n g t h e c o d e t o p a s s t h e t e s t i s c a l l e d t e s t d r i v e n d e v e l o p m e n t ( T D D ) . I t ’ s a g r e a t w a y t o w o r k b e c a u s e i t m a k e s y o u t h i n k a b o u t y o u r c o d e s t r u c t u r e i n a d v a n c e .
N o w t r y i t o n y o u r o w n . A d d a t e s t f o r t h e d i v i s i o n f u n c t i o n , s e e i t f a i l , a n d w r i t e t h e f u n c t i o n t o m a k e t h e t e s t p a s s .
N o t i f i c a t i o n s
W h e n w o r k i n g o n b i g a p p l i c a t i o n s t h a t h a v e a l o t o f m o v i n g p a r t s , i t c a n t a k e a w h i l e f o r t h e c o n t i n u o u s i n t e g r a t i o n j o b t o r u n . M o s t t e a m s s e t u p a n o t i f i c a t i o n p r o c e d u r e t o l e t t h e m k n o w i f o n e o f t h e i r j o b s f a i l . T h e y c a n c o n t i n u e w o r k i n g w h i l e w a i t i n g f o r t h e j o b t o r u n .
T h e m o s t p o p u l a r o p t i o n s a r e :
● S e n d i n g a n e m a i l f o r e a c h f a i l e d b u i l d
● S e n d i n g f a i l u r e n o t i f i c a t i o n s t o a S l a c k c h a n n e l
● D i s p l a y i n g f a i l u r e s o n a d a s h b o a r d v i s i b l e t o e v e r y o n e
B y d e f a u l t , C i r c l e C I s h o u l d s e n d y o u a n e m a i l w h e n a j o b f a i l s .
N e x t S t e p s
Y o u h a v e u n d e r s t o o d t h e b a s i c s o f c o n t i n u o u s i n t e g r a t i o n a n d p r a c t i c e d s e t t i n g u p a p i p e l i n e f o r a s i m p l e P y t h o n p r o g r a m . T h i s i s a b i g s t e p f o r w a r d i n y o u r j o u r n e y a s a d e v e l o p e r . Y o u m i g h t b e a s k i n g y o u r s e l f , “ W h a t n o w ? ”
T o k e e p t h i n g s s i m p l e , t h i s t u t o r i a l s k i m m e d o v e r s o m e b i g t o p i c s . Y o u c a n g r o w y o u r s k i l l s e t i m m e n s e l y b y s p e n d i n g s o m e t i m e g o i n g m o r e i n - d e p t h i n t o e a c h s u b j e c t . H e r e a r e s o m e t o p i c s y o u c a n l o o k i n t o f u r t h e r .
G i t W o r k f l o w s
T h e r e i s m u c h m o r e t o G i t t h a n w h a t y o u u s e d h e r e . E a c h d e v e l o p e r t e a m h a s a w o r k f l o w t a i l o r e d t o t h e i r s p e c i f i c n e e d s . M o s t o f t h e m i n c l u d e b r a n c h i n g s t r a t e g i e s a n d s o m e t h i n g c a l l e d p e e r r e v i e w . T h e y m a k e c h a n g e s o n b r a n c h e s s e p a r a t e f r o m t h e m a s t e r b r a n c h . W h e n y o u w a n t t o m e r g e t h o s e c h a n g e s w i t h m a s t e r , o t h e r d e v e l o p e r s m u s t f i r s t l o o k a t y o u r c h a n g e s a n d a p p r o v e t h e m b e f o r e y o u ’ r e a l l o w e d t o m e r g e .
N o t e : I f y o u w a n t t o l e a r n m o r e a b o u t d i f f e r e n t w o r k f l o w s t e a m s u s e , h a v e a l o o k a t t h e t u t o r i a l s o n G i t H u b a n d B i t B u c k e t .
I f y o u w a n t t o s h a r p e n y o u r G i t s k i l l s , w e h a v e a n a r t i c l e c a l l e d A d v a n c e d G i t T i p s f o r P y t h o n D e v e l o p e r s .
R e m o v e a d s
D e p e n d e n c y M a n a g e m e n t a n d V i r t u a l E n v i r o n m e n t s
A p a r t f r o m v i r t u a l e n v , t h e r e a r e o t h e r p o p u l a r p a c k a g e a n d e n v i r o n m e n t m a n a g e r s . S o m e o f t h e m d e a l w i t h j u s t v i r t u a l e n v i r o n m e n t s , w h i l e s o m e h a n d l e b o t h p a c k a g e i n s t a l l a t i o n a n d e n v i r o n m e n t m a n a g e m e n t . O n e o f t h e m i s C o n d a :
“ C o n d a i s a n o p e n s o u r c e p a c k a g e m a n a g e m e n t s y s t e m a n d e n v i r o n m e n t m a n a g e m e n t s y s t e m t h a t r u n s o n W i n d o w s , m a c O S , a n d L i n u x . C o n d a q u i c k l y i n s t a l l s , r u n s a n d u p d a t e s p a c k a g e s a n d t h e i r d e p e n d e n c i e s . C o n d a e a s i l y c r e a t e s , s a v e s , l o a d s a n d s w i t c h e s b e t w e e n e n v i r o n m e n t s o n y o u r l o c a l c o m p u t e r . I t w a s d e s i g n e d f o r P y t h o n p r o g r a m s , b u t i t c a n p a c k a g e a n d d i s t r i b u t e s o f t w a r e f o r a n y l a n g u a g e . ” ( S o u r c e )
A n o t h e r o p t i o n i s P i p e n v , a y o u n g e r c o n t e n d e r t h a t i s r i s i n g i n p o p u l a r i t y a m o n g a p p l i c a t i o n d e v e l o p e r s . P i p e n v b r i n g s t o g e t h e r p i p a n d v i r t u a l e n v i n t o a s i n g l e t o o l a n d u s e s a P i p f i l e i n s t e a d o f r e q u i r e m e n t s . t x t . P i p f i l e s o f f e r d e t e r m i n i s t i c e n v i r o n m e n t s a n d m o r e s e c u r i t y . T h i s i n t r o d u c t i o n d o e s n ’ t d o i t j u s t i c e , s o c h e c k o u t P i p e n v : A G u i d e t o t h e N e w P y t h o n P a c k a g i n g T o o l .
T e s t i n g
S i m p l e u n i t t e s t s w i t h p y t e s t a r e o n l y t h e t i p o f t h e i c e b e r g . T h e r e ’ s a w h o l e w o r l d o u t t h e r e t o e x p l o r e ! S o f t w a r e c a n b e t e s t e d o n m a n y l e v e l s , i n c l u d i n g i n t e g r a t i o n t e s t i n g , a c c e p t a n c e t e s t i n g , r e g r e s s i o n t e s t i n g , a n d s o f o r t h . T o t a k e y o u r k n o w l e d g e o f t e s t i n g P y t h o n c o d e t o t h e n e x t l e v e l , h e a d o v e r t o G e t t i n g S t a r t e d W i t h T e s t i n g i n P y t h o n .
P a c k a g i n g
I n t h i s t u t o r i a l , y o u s t a r t e d t o b u i l d a l i b r a r y o f f u n c t i o n s f o r o t h e r d e v e l o p e r s t o u s e i n t h e i r p r o j e c t . Y o u n e e d t o p a c k a g e t h a t l i b r a r y i n t o a f o r m a t t h a t i s e a s y t o d i s t r i b u t e a n d i n s t a l l u s i n g , f o r e x a m p l e p i p .
C r e a t i n g a n i n s t a l l a b l e p a c k a g e r e q u i r e s a d i f f e r e n t l a y o u t a n d s o m e a d d i t i o n a l f i l e s l i k e _ _ i n i t _ _ . p y a n d s e t u p . p y . R e a d P y t h o n A p p l i c a t i o n L a y o u t s : A R e f e r e n c e f o r m o r e i n f o r m a t i o n o n s t r u c t u r i n g y o u r c o d e .
T o l e a r n h o w t o t u r n y o u r r e p o s i t o r y i n t o a n i n s t a l l a b l e P y t h o n p a c k a g e , r e a d P a c k a g i n g P y t h o n P r o j e c t s b y t h e P y t h o n P a c k a g i n g A u t h o r i t y .
C o n t i n u o u s I n t e g r a t i o n
Y o u c o v e r e d a l l t h e b a s i c s o f C I i n t h i s t u t o r i a l , u s i n g a s i m p l e e x a m p l e o f P y t h o n c o d e . I t ’ s c o m m o n f o r t h e f i n a l s t e p o f a C I p i p e l i n e t o c r e a t e a d e p l o y a b l e a r t i f a c t . A n a r t i f a c t r e p r e s e n t s a f i n i s h e d , p a c k a g e d u n i t o f w o r k t h a t i s r e a d y t o b e d e p l o y e d t o u s e r s o r i n c l u d e d i n c o m p l e x p r o d u c t s .
F o r e x a m p l e , t o t u r n y o u r c a l c u l a t o r l i b r a r y i n t o a d e p l o y a b l e a r t i f a c t , y o u w o u l d o r g a n i z e i t i n t o a n i n s t a l l a b l e p a c k a g e . F i n a l l y , y o u w o u l d a d d a s t e p i n C i r c l e C I t o p a c k a g e t h e l i b r a r y a n d s t o r e t h a t a r t i f a c t w h e r e o t h e r p r o c e s s e s c a n p i c k i t u p .
F o r m o r e c o m p l e x a p p l i c a t i o n s , y o u c a n c r e a t e a w o r k f l o w t o s c h e d u l e a n d c o n n e c t m u l t i p l e C I j o b s i n t o a s i n g l e e x e c u t i o n . F e e l f r e e t o e x p l o r e t h e C i r c l e C I d o c u m e n t a t i o n .
C o n t i n u o u s D e p l o y m e n t
Y o u c a n t h i n k o f c o n t i n u o u s d e p l o y m e n t a s a n e x t e n s i o n o f C I . O n c e y o u r c o d e i s t e s t e d a n d b u i l t i n t o a d e p l o y a b l e a r t i f a c t , i t i s d e p l o y e d t o p r o d u c t i o n , m e a n i n g t h e l i v e a p p l i c a t i o n i s u p d a t e d w i t h y o u r c h a n g e s . O n e o f t h e g o a l s i s t o m i n i m i z e l e a d t i m e , t h e t i m e e l a p s e d b e t w e e n w r i t i n g a n e w l i n e o f c o d e a n d p u t t i n g i t i n f r o n t o f u s e r s .
N o t e : T o a d d a b i t o f c o n f u s i o n t o t h e m i x , t h e a c r o n y m C D i s n o t u n i q u e . I t c a n a l s o m e a n C o n t i n u o u s D e l i v e r y , w h i c h i s a l m o s t t h e s a m e a s c o n t i n u o u s d e p l o y m e n t b u t h a s a m a n u a l v e r i f i c a t i o n s t e p b e t w e e n i n t e g r a t i o n a n d d e p l o y m e n t . Y o u c a n i n t e g r a t e y o u r c o d e a t a n y t i m e b u t h a v e t o p u s h a b u t t o n t o r e l e a s e i t t o t h e l i v e a p p l i c a t i o n .
M o s t c o m p a n i e s u s e C I / C D i n t a n d e m , s o i t ’ s w o r t h y o u r t i m e t o l e a r n m o r e a b o u t C o n t i n u o u s D e l i v e r y / D e p l o y m e n t .
O v e r v i e w o f C o n t i n u o u s I n t e g r a t i o n S e r v i c e s
Y o u h a v e u s e d C i r c l e C I , o n e o f t h e m o s t p o p u l a r c o n t i n u o u s i n t e g r a t i o n s e r v i c e s . H o w e v e r , t h i s i s a b i g m a r k e t w i t h a l o t o f s t r o n g c o n t e n d e r s . C I p r o d u c t s f a l l i n t o t w o b a s i c c a t e g o r i e s : r e m o t e a n d s e l f - h o s t e d s e r v i c e s .
J e n k i n s i s t h e m o s t p o p u l a r s e l f - h o s t e d s o l u t i o n . I t i s o p e n - s o u r c e a n d f l e x i b l e , a n d t h e c o m m u n i t y h a s d e v e l o p e d a l o t o f e x t e n s i o n s .
I n t e r m s o f r e m o t e s e r v i c e s , t h e r e a r e m a n y p o p u l a r o p t i o n s l i k e T r a v i s C I , C o d e S h i p , a n d S e m a p h o r e . B i g e n t e r p r i s e s o f t e n h a v e t h e i r c u s t o m s o l u t i o n s , a n d t h e y s e l l t h e m a s a s e r v i c e , s u c h a s A W S C o d e P i p e l i n e , M i c r o s o f t T e a m F o u n d a t i o n S e r v e r , a n d O r a c l e ’ s H u d s o n .
W h i c h o p t i o n y o u c h o o s e d e p e n d s o n t h e p l a t f o r m a n d f e a t u r e s y o u a n d y o u r t e a m n e e d . F o r a m o r e d e t a i l e d b r e a k d o w n , h a v e a l o o k a t B e s t C I S o f t w a r e b y G 2 C r o w d .
R e m o v e a d s
C o n c l u s i o n
W i t h t h e k n o w l e d g e f r o m t h i s t u t o r i a l u n d e r y o u r b e l t , y o u c a n n o w a n s w e r t h e f o l l o w i n g q u e s t i o n s :
● W h a t i s c o n t i n u o u s i n t e g r a t i o n ?
● W h y i s c o n t i n u o u s i n t e g r a t i o n i m p o r t a n t ?
● W h a t a r e t h e c o r e p r a c t i c e s o f c o n t i n u o u s i n t e g r a t i o n ?
● H o w c a n I s e t u p c o n t i n u o u s i n t e g r a t i o n f o r m y P y t h o n p r o j e c t ?
Y o u h a v e a c q u i r e d a p r o g r a m m i n g s u p e r p o w e r ! U n d e r s t a n d i n g t h e p h i l o s o p h y a n d p r a c t i c e o f c o n t i n u o u s i n t e g r a t i o n w i l l m a k e y o u a v a l u a b l e m e m b e r o f a n y t e a m . A w e s o m e w o r k !
M a r k a s C o m p l e t e d
W a t c h N o w T h i s t u t o r i a l h a s a r e l a t e d v i d e o c o u r s e c r e a t e d b y t h e R e a l P y t h o n t e a m . W a t c h i t t o g e t h e r w i t h t h e w r i t t e n t u t o r i a l t o d e e p e n y o u r u n d e r s t a n d i n g : C o n t i n u o u s I n t e g r a t i o n W i t h P y t h o n
🐍 P y t h o n T r i c k s 💌
G e t a s h o r t & s w e e t P y t h o n T r i c k d e l i v e r e d t o y o u r i n b o x e v e r y c o u p l e o f d a y s . N o s p a m e v e r . U n s u b s c r i b e a n y t i m e . C u r a t e d b y t h e R e a l P y t h o n t e a m .
Send Me Python Tricks »
A b o u t K r i s t i j a n I v a n c i c
H e y , I ' m K r i s t i j a n ! I ' m a C V / M L e n g i n e e r a n d m e m b e r o f t h e R e a l P y t h o n t u t o r i a l t e a m .
» M o r e a b o u t K r i s t i j a n
E a c h t u t o r i a l a t R e a l P y t h o n i s c r e a t e d b y a t e a m o f d e v e l o p e r s s o t h a t i t m e e t s o u r h i g h q u a l i t y s t a n d a r d s . T h e t e a m m e m b e r s w h o w o r k e d o n t h i s t u t o r i a l a r e :
A l d r e n
B r a d
J o a n n a
M a s t e r R e a l - W o r l d P y t h o n S k i l l s W i t h U n l i m i t e d A c c e s s t o R e a l P y t h o n
J o i n u s a n d g e t a c c e s s t o h u n d r e d s o f t u t o r i a l s , h a n d s - o n v i d e o c o u r s e s , a n d a c o m m u n i t y o f e x p e r t P y t h o n i s t a s :
L e v e l U p Y o u r P y t h o n S k i l l s »
M a s t e r R e a l - W o r l d P y t h o n S k i l l s
W i t h U n l i m i t e d A c c e s s t o R e a l P y t h o n
J o i n u s a n d g e t a c c e s s t o h u n d r e d s o f t u t o r i a l s , h a n d s - o n v i d e o c o u r s e s , a n d a c o m m u n i t y o f e x p e r t P y t h o n i s t a s :
L e v e l U p Y o u r P y t h o n S k i l l s »
W h a t D o Y o u T h i n k ?
S h a r e
E m a i l
R e a l P y t h o n C o m m e n t P o l i c y : T h e m o s t u s e f u l c o m m e n t s a r e t h o s e w r i t t e n w i t h t h e g o a l o f l e a r n i n g f r o m o r h e l p i n g o u t o t h e r r e a d e r s — a f t e r r e a d i n g t h e w h o l e a r t i c l e a n d a l l t h e e a r l i e r c o m m e n t s . C o m p l a i n t s a n d i n s u l t s g e n e r a l l y w o n ’ t m a k e t h e c u t h e r e .
W h a t ’ s y o u r # 1 t a k e a w a y o r f a v o r i t e t h i n g y o u l e a r n e d ? H o w a r e y o u g o i n g t o p u t y o u r n e w f o u n d s k i l l s t o u s e ? L e a v e a c o m m e n t b e l o w a n d l e t u s k n o w .
K e e p L e a r n i n g
R e l a t e d T u t o r i a l C a t e g o r i e s :
b e s t - p r a c t i c e s
d e v o p s
i n t e r m e d i a t e
t e s t i n g
R e c o m m e n d e d V i d e o C o u r s e : C o n t i n u o u s I n t e g r a t i o n W i t h P y t h o n
K e e p r e a d i n g R e a l P y t h o n b y c r e a t i n g a f r e e a c c o u n t o r s i g n i n g i n :
C o n t i n u e »
A l r e a d y h a v e a n a c c o u n t ? S i g n - I n
Get Python Tricks »
🔒 No spam. Unsubscribe any time.
A l l T u t o r i a l T o p i c s
a d v a n c e d
a p i
b a s i c s
b e s t - p r a c t i c e s
c o m m u n i t y
d a t a b a s e s
d a t a - s c i e n c e
d e v o p s
d j a n g o
d o c k e r
f l a s k
f r o n t - e n d
g a m e d e v
g u i
i n t e r m e d i a t e
m a c h i n e - l e a r n i n g
p r o j e c t s
p y t h o n
t e s t i n g
t o o l s
w e b - d e v
w e b - s c r a p i n g
T a b l e o f C o n t e n t s
● W h a t I s C o n t i n u o u s I n t e g r a t i o n ?
● W h y S h o u l d I C a r e ?
● C o r e C o n c e p t s
● S i n g l e S o u r c e R e p o s i t o r y
● A u t o m a t i n g t h e B u i l d
● A u t o m a t e d T e s t i n g
● U s i n g a n E x t e r n a l C o n t i n u o u s I n t e g r a t i o n S e r v i c e
● T e s t i n g i n a S t a g i n g E n v i r o n m e n t
● Y o u r T u r n !
● P r o b l e m D e f i n i t i o n
● C r e a t e a R e p o
● S e t U p a W o r k i n g E n v i r o n m e n t
● W r i t e a S i m p l e P y t h o n E x a m p l e
● W r i t e U n i t T e s t s
● C o n n e c t t o C i r c l e C I
● M a k e C h a n g e s
● N o t i f i c a t i o n s
● N e x t S t e p s
● G i t W o r k f l o w s
● D e p e n d e n c y M a n a g e m e n t a n d V i r t u a l E n v i r o n m e n t s
● T e s t i n g
● P a c k a g i n g
● C o n t i n u o u s I n t e g r a t i o n
● C o n t i n u o u s D e p l o y m e n t
● O v e r v i e w o f C o n t i n u o u s I n t e g r a t i o n S e r v i c e s
● C o n c l u s i o n
M a r k a s C o m p l e t e d
S h a r e
E m a i l
R e c o m m e n d e d V i d e o C o u r s e
C o n t i n u o u s I n t e g r a t i o n W i t h P y t h o n
A l m o s t t h e r e ! C o m p l e t e t h i s f o r m a n d c l i c k t h e b u t t o n b e l o w t o g a i n i n s t a n t a c c e s s :
×
5 T h o u g h t s O n P y t h o n M a s t e r y
Start the Class »
R e m o v e a d s
© 2 0 1 2 – 2 0 2 1 R e a l P y t h o n ⋅ N e w s l e t t e r ⋅ P o d c a s t ⋅ Y o u T u b e ⋅ T w i t t e r ⋅ F a c e b o o k ⋅ I n s t a g r a m ⋅ P y t h o n T u t o r i a l s ⋅ S e a r c h ⋅ P r i v a c y P o l i c y ⋅ E n e r g y P o l i c y ⋅ A d v e r t i s e ⋅ C o n t a c t
❤ ️ H a p p y P y t h o n i n g !