티스토리 뷰

1. Heroku : PaaS(Platform as a Service) cloud database 제공, PostgreSQL

회원가입 및 app 생성 : jinozblog2019

https://dashboard.heroku.com/apps

Heroku CLI 설치

https://devcenter.heroku.com/articles/heroku-cli

$ brew tap heroku/brew && brew install heroku

 

2. GitHub : website에 올릴 파일 관리를 위한 원격 저장소

회원가입 및 Repositories(저장소) 생성

https://github.com/

Repository name : jinozblog2019

Initialize this repository with a README : check -> README.md 파일 생성

Add .gitignore : python 선택

원격저장소 생성

https://github.com/<UserID>/jinozblog2019.git

 

 

3. webhosting service 배포(Deploy)를 위한 설정

1) jinozblog2019/local_settings.py 생성 후 settings.py 내용을 복사해서 개발서버에서 사용했던 설정 backup

2) Heroku PostgreSQL DB 사용을 위한 package 설치

 - dj-database-url

 - psycopg2-binary

$ pip3 install dj-database-url psycopg2-binary

3) jinozblog/jblog/settings.py 수정

 - SECRET_KEY : project 생성 시 부여된 key를 <your secretkey>에 넣는다.

 - DEBUG : False로 놓아야 서버의 에러메세지를 보여주지 않는다.

 - dj_database_url 설정 : DATABASE_URL 환경변수 자동 분석하여 django 설정에 맞게 변환

SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY','<your secretkey>')

DEBUG = bool(os.environ.get('DJANGO_DEBUG','True'))

ALLOWED_HOSTS = ['*']

# settings.py # Heroku: Update database configuration from $DATABASE_URL. 
import dj_database_url 
db_from_env = dj_database_url.config(conn_max_age=500) 
DATABASES['default'].update(db_from_env)

 

4) git 저장소에 불필요한 파일들 제외를 위해 .gitignore 파일을 추가하고 다음과 같이 설정해준다.

--jinozblog2019/.gitignore

# Django stuff:
*.log
*.pyc 
__pycache__/ 
local_settings.py 
db.sqlite3

위의 과정을 수행하고 난 후 tree를 확인해보자

~/jinozblog2019$ tree

.

├── db.sqlite3

├── jblog

│   ├── __init__.py

│   ├── __pycache__

│   │   ├── __init__.cpython-37.pyc

│   │   ├── settings.cpython-37.pyc

│   │   ├── urls.cpython-37.pyc

│   │   └── wsgi.cpython-37.pyc

│   ├── local_settings.py

│   ├── settings.py

│   ├── urls.py

│   └── wsgi.py

├── manage.py

└── post

    ├── __init__.py

    ├── __pycache__

    │   ├── __init__.cpython-37.pyc

    │   ├── admin.cpython-37.pyc

    │   ├── models.cpython-37.pyc

    │   └── views.cpython-37.pyc

    ├── admin.py

    ├── apps.py

    ├── migrations

    │   ├── 0001_initial.py

    │   ├── 0002_post_author.py

    │   ├── __init__.py

    │   └── __pycache__

    │       ├── 0001_initial.cpython-37.pyc

    │       ├── 0002_post_author.cpython-37.pyc

    │       └── __init__.cpython-37.pyc

    ├── models.py

    ├── templates

    │   ├── home.html

    │   ├── post_detail.html

    │   └── post_list.html

    ├── tests.py

    └── views.py

 

회색으로 표기된 __pycache__의 .pyc, 즉 python cache 파일은 개발에 사용한 캐쉬파일로 web에 올릴 필요가 없다.

.gitignore에 명시해 두었기 때문에 git push 시에 제외된다.

website에 배포(공개)를 위해 위치(공간) 개념을 정립해보면, localPC project -> git 저장소 -> Heroku 형태가 된다.

 

4. GitHub push

$ git init

$ git add .

$ git status

On branch master

 

No commits yet

 

Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

new file:   .gitignore

new file:   jblog/__init__.py

new file:   jblog/settings.py

new file:   jblog/urls.py

new file:   jblog/wsgi.py

new file:   manage.py

new file:   post/__init__.py

new file:   post/admin.py

new file:   post/apps.py

new file:   post/migrations/0001_initial.py

new file:   post/migrations/0002_post_author.py

new file:   post/migrations/__init__.py

new file:   post/models.py

new file:   post/templates/home.html

new file:   post/templates/post_detail.html

new file:   post/templates/post_list.html

new file:   post/tests.py

 

$ git commit -m "First git commit Test"

[master (root-commit) a2cec97] First git commit Test

 Committer: JinoMac <jinoz@JinoMacui-MacBookAir.local>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly. Run the

following command and follow the instructions in your editor to edit

your configuration file:

 

    git config --global --edit

 

After doing this, you may fix the identity used for this commit with:

 

    git commit --amend --reset-author

 

 18 files changed, 320 insertions(+)

 create mode 100644 .gitignore

 create mode 100644 jblog/__init__.py

 create mode 100644 jblog/settings.py

 create mode 100644 jblog/urls.py

 create mode 100644 jblog/wsgi.py

 create mode 100755 manage.py

 create mode 100644 post/__init__.py

 create mode 100644 post/admin.py

 create mode 100644 post/apps.py

 create mode 100644 post/migrations/0001_initial.py

 create mode 100644 post/migrations/0002_post_author.py

 create mode 100644 post/migrations/__init__.py

 create mode 100644 post/models.py

 create mode 100644 post/templates/home.html

 create mode 100644 post/templates/post_detail.html

 create mode 100644 post/templates/post_list.html

 create mode 100644 post/tests.py

 create mode 100644 post/views.py

 

$ git remote add origin https://github.com/Jinoz/jinozblog2019.git

$ git remote -v

origin https://github.com/Jinoz/jinozblog2019.git (fetch)

origin https://github.com/Jinoz/jinozblog2019.git (push)

 

$ git push -f origin master

Enumerating objects: 26, done.

Counting objects: 100% (26/26), done.

Delta compression using up to 4 threads

Compressing objects: 100% (25/25), done.

Writing objects: 100% (26/26), 5.62 KiB | 958.00 KiB/s, done.

Total 26 (delta 3), reused 0 (delta 0)

remote: Resolving deltas: 100% (3/3), done.

To https://github.com/<UserID>/jinozblog2019.git

 + 606e708...431cc02 master -> master (forced update)

 

GitHub 저장소를 새로고침하면 다음과 같이 commit된 파일들이 push된 것을 확인할 수 있다.

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함