deployment/heroku

[heroku] streamlit 이용한 웹 어플리케이션 배포[파이썬 환경]

hojung 2022. 6. 26.
728x90
반응형

1. heroku

============================================================================================

슬프게도 2022.11.28일 이후로 heroku에서 무료 배포를 지원하지 않는다...

이 글에서 이용한 streamlit 라이브러리의 경우  streamlit share라는 무료 배포 서비스를 제공하니 그것을 이용하도록 하자

https://incheonhousepriceprediction.streamlit.app/

https://www.heroku.com/

 

Cloud Application Platform | Heroku

Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.

www.heroku.com

heroku를 통해 배포를 해 볼 것이다. 

1. 회원 가입

우선 회원 가입을 하고 계정을 생성한다.

2. heroku cli 설치하기 

https://devcenter.heroku.com/articles/getting-started-with-python#set-up

 

Getting Started on Heroku with Python | Heroku Dev Center

This tutorial will have you deploying a Python app (a simple Django app) in minutes. Hang on for a few more minutes to learn how it all works, so you can make the most out of Heroku. The Heroku CLI requires Git, the popular version control system. If you d

devcenter.heroku.com

각자 환경에 맞는 heroku cli를 설치해준다. 

3. cmd에서 heroku login

heroku cli를 설치했으면 cmd에서 heroku 명령어를 사용할 수 있다. 따라서 cmd에서 다음과 같은 명령어를 입력한다. 

로그인에 성공하면 다음과 같은 화면이 나올 것이다. 

4. 배포를 위한 파일 생성

배포를 위해 필요한 파일은 다음 3개이다. 

1. Procfile

여기서 중요한 점은 Procfile에서 p가 무조건 대문자여야 한다는 점이다. 소문자라면 heroku error h14를 일으킨다. 

web: sh setup.sh && streamlit run [앱 이름].py

2. setup.sh

mkdir -p ~/.streamlit/

echo "\
[server]\n\
port = $PORT\n\
enableCORS = false\n\
headless = true\n\
\n\
" > ~/.streamlit/config.toml

3. requirments.txt

해당 파일은 우리가 만든 웹을 실행하기 위해 어떤 라이브러리들이 어떤 버전으로 필요한지 알려주는 파일이다. 나의 경우 

pip list로 확인하여 작성해주었다. 

requirement.txt의 모습

 

파일들을 생성해 주었으면 가장 중요한 점이 있다. heroku는 git을 통해 배포가 진행되므로 git init명령어를 통해 무조건 폴더 내에 git폴더가 존재해야한다. 

5. heroku 앱 만들기

heroku create [앱 이름]

다음과 같은 명령어를 아까 heroku login한 터미널에 입력하면 heroku app이 생성된다. 

위와 같은 명령어를 입력하면 

heroku 웹사이트에서도 다음과 같은 앱이 생성된 것을 확인할 수 있다. 나는 앱 이름을 incheon-house로 설정해주었다. 

그 후 깃허브 레포지토리를 연결해준다. 

 

git add . 
git commit -m "first commit"
git push heroku main

다음과 같은 명령어를 설정해주면 자동으로 앱을 배포해준다. 

그 후 remote repository를 확인하면 다음과 같이 heroku로 설정된 레포지토리가 존재함을 볼 수 있다. 

배포가 완료된 후 다음과 같은 명령어를 입력하면 log도 확인할 수 있다. 

내 배포된 사이트의 주소는 다음과 같다. 

http://incheon-house.herokuapp.com/

 

 

728x90
반응형

댓글