Chapter 19: Deployment on Docker Containers (v0.19)
This commit is contained in:
		
							parent
							
								
									e80c561ff0
								
							
						
					
					
						commit
						e12bb28199
					
				| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					FROM python:3.6-alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN adduser -D microblog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					WORKDIR /home/microblog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COPY requirements.txt requirements.txt
 | 
				
			||||||
 | 
					RUN python -m venv venv
 | 
				
			||||||
 | 
					RUN venv/bin/pip install -r requirements.txt
 | 
				
			||||||
 | 
					RUN venv/bin/pip install gunicorn pymysql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COPY app app
 | 
				
			||||||
 | 
					COPY migrations migrations
 | 
				
			||||||
 | 
					COPY microblog.py config.py boot.sh ./
 | 
				
			||||||
 | 
					RUN chmod a+x boot.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENV FLASK_APP microblog.py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN chown -R microblog:microblog ./
 | 
				
			||||||
 | 
					USER microblog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXPOSE 5000
 | 
				
			||||||
 | 
					ENTRYPOINT ["./boot.sh"]
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					# this script is used to boot a Docker container
 | 
				
			||||||
 | 
					source venv/bin/activate
 | 
				
			||||||
 | 
					while true; do
 | 
				
			||||||
 | 
					    flask db upgrade
 | 
				
			||||||
 | 
					    if [[ "$?" == "0" ]]; then
 | 
				
			||||||
 | 
					        break
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    echo Deploy command failed, retrying in 5 secs...
 | 
				
			||||||
 | 
					    sleep 5
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					flask translate compile
 | 
				
			||||||
 | 
					exec gunicorn -b :5000 --access-logfile - --error-logfile - microblog:app
 | 
				
			||||||
| 
						 | 
					@ -35,5 +35,5 @@ Werkzeug==0.14.1
 | 
				
			||||||
WTForms==2.1
 | 
					WTForms==2.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# requirements for Heroku
 | 
					# requirements for Heroku
 | 
				
			||||||
psycopg2==2.7.3.1
 | 
					#psycopg2==2.7.3.1
 | 
				
			||||||
gunicorn==19.7.1
 | 
					#gunicorn==19.7.1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue