forked from pythonclub/pythonclub.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-app-django-openshift.html
More file actions
553 lines (449 loc) · 35.6 KB
/
deploy-app-django-openshift.html
File metadata and controls
553 lines (449 loc) · 35.6 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="PythonClub, ">
<meta name="theme-color" content="#101212">
<link rel="alternate" href="http://pythonclub.com.br/feeds/all.atom.xml" type="application/atom+xml" title="PythonClub Full Atom Feed"/>
<link rel="alternate" href="http://pythonclub.com.br/feeds/all.rss.xml" type="application/rss+xml" title="PythonClub Full RSS Feed"/>
<link rel="shortcut icon" href="http://pythonclub.com.br/theme/images/favicon.ico" >
<title>Deploy App Django no Openshift por Elio Duarte // #PythonClub // </title>
<meta property="fb:app_id" content="1487080281503641" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Deploy App Django no Openshift" />
<meta property="og:site_name" content="PythonClub" />
<meta property="og:url" content="http://pythonclub.com.br/deploy-app-django-openshift.html" />
<meta property="og:description" content="Recentemente quis testar o Django no Openshift mas não encontrei nenhum tutorial atualizado sobre o assunto, por isso resolvi escrever um. Nosso objetivo é ter um app bem básico em Django rodando no Openshift Online. Eu utilizei o Ubuntu 14.04 nesse tutorial mas excluindo a parte de instalação do ..." />
<meta property="og:image" content="http://res.cloudinary.com/diu8g9l0s/image/upload/v1400201393/pythonclub/logo_275x130.png" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pure/0.3.0/pure-min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css">
<link rel="stylesheet" href="http://pythonclub.com.br/theme/css/pure.css">
<link rel="stylesheet" href="http://pythonclub.com.br/theme/css/custom.css">
<link rel="stylesheet" href="http://pythonclub.com.br/theme/css/pygments.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-50935105-1', 'pythonclub.com.br');
ga('require', 'linkid', 'linkid.js');
ga('send', 'pageview');
</script>
<!-- transifex -->
<!-- <script type="text/javascript"> -->
<!-- window.liveSettings = { -->
<!-- api_key: "f8fd260a9bdc4e9195c80e31416bb254", -->
<!-- picker: "bottom-right", -->
<!-- detectlang: true, -->
<!-- autocollect: true -->
<!-- }; -->
<!-- </script> -->
<!-- <script type="text/javascript" src="//cdn.transifex.com/live.js"></script> -->
<!-- end transifex -->
<meta name="google-site-verification" content="XQc_QtnTecI9nxAfplXGtECCpZQDwbDRcn7pyDVa1LE" />
</head>
<body>
<div class="pure-g-r" id="layout">
<div class="sidebar sidebar-article pure-u">
<header class="header-article">
<hgroup>
<a href="http://pythonclub.com.br/author/elio-duarte.html" title="See posts by Elio Duarte">
<img class="article-avatar" alt="Elio Duarte" src="http://www.gravatar.com/avatar/4b23f2843f65116efec761fc9c5e964a">
</a>
<h2 class="article-info">Elio Duarte</h2>
<ul class="author-social">
<li>
<a target="_blank" href="https://github.com/eliostvs">
<i class="fa fa-lg fa-fw fa-github"></i>
<strong>Github</strong>
</a>
</li>
</ul>
<h5>Publicado em:</h5>
<p>Fri 05 September 2014</p>
<a href="/">←Home</a>
</hgroup>
</header>
</div>
<div class="pure-u">
<div class="content">
<section class="post">
<header class="post-header">
<h1>Deploy App Django no Openshift</h1>
<p class="post-meta">
// Tags <a class="post-category" href="http://pythonclub.com.br/tag/tutorial.html">tutorial</a>
<a class="post-category" href="http://pythonclub.com.br/tag/django.html">django</a>
<a class="post-category" href="http://pythonclub.com.br/tag/openshift.html">openshift</a>
<a class="post-category" href="http://pythonclub.com.br/tag/paas.html">paas</a>
</p>
</header>
</section>
<p>Recentemente quis testar o Django no Openshift mas não encontrei nenhum tutorial atualizado sobre o assunto, por isso resolvi escrever um.
Nosso objetivo é ter um app bem básico em Django rodando no <a href="https://www.openshift.com/products/online">Openshift Online</a>.
Eu utilizei o Ubuntu 14.04 nesse tutorial mas excluindo a parte de instalação do programa <em>rhc</em>, ele serve para qualquer sistema unix-like.</p>
<h3>O que é?</h3>
<p><a href="http://openshift.github.io/">Openshift Origin</a> é um PaaS opensource mantido pela RedHat.
A empresa também tem um serviço de hospedagem, o <a href="https://www.openshift.com/products/online">Openshift Online</a>, com planos pagos e gratuitos.
No plano gratuito você pode utilizar até três <em>small gears</em>, containers onde a sua aplicação irá rodar.
Cada <em>small gear</em> possui:</p>
<ul>
<li>512MB de RAM</li>
<li>100MB de swap</li>
<li>1GB de espaço em disco</li>
</ul>
<p>Em cada <em>gear</em> você pode ter um ou mais <em>cartridges</em>, funcionalidades que sua app poderá utilizar.
Existem <em>cartridges</em> que habilitam uma linguagem (Python, Ruby, Java), um banco de dados (PostgreSQL, MongoDB), um serviço (Cron, MMS), etc.</p>
<h3>Criação de conta e login</h3>
<p>Você precisa ter uma conta no <a href="https://www.openshift.com/products/online">Openshift Online</a> e o programa <strong>rhc</strong> instalado em sua máquina.</p>
<p>Crie uma conta gratuita clicando <a href="https://www.openshift.com/app/account/new">aqui</a>.</p>
<p>Depois instale o programa <strong>ruby</strong> e o <strong>rhc</strong>:</p>
<div class="highlight"><pre>sudo apt-get update <span class="o">&&</span> apt-get install -y ruby
sudo gem install rhc
</pre></div>
<p>Clique <a href="http://openshift.github.io/documentation/oo_client_tools_installation_guide.html">aqui</a> para ver como instalar o <strong>rhc</strong> em outras plataformas.</p>
<p>Faça o login:</p>
<div class="highlight"><pre>rhc setup
</pre></div>
<p>Por fim confirme que você consegue conectar em sua conta executando:</p>
<div class="highlight"><pre>rhc apps
No applications. Use <span class="s1">'rhc create-app'</span>.
</pre></div>
<h3>Criando um app no Openshift</h3>
<p>Crie um app com nome de <strong>django</strong> usando o <em>cartridge</em> <strong>Python 2.7</strong>:</p>
<div class="highlight"><pre>rhc create-app -a django -t python-2.7
Application Options
-------------------
Domain: stvs
Cartridges: python-2.7
Gear Size: default
Scaling: no
Creating application <span class="s1">'django'</span> ... <span class="k">done</span>
Waiting <span class="k">for</span> your DNS name to be available ... <span class="k">done</span>
Cloning into <span class="s1">'django'</span>...
Your application <span class="s1">'django'</span> is now available.
URL: http://django-stvs.rhcloud.com/
SSH to: 5409ae505973ca58d200015e@django-stvs.rhcloud.com
Git remote: ssh://5409ae505973ca58d200015e@django-stvs.rhcloud.com/~/git/django.git/
Cloned to: /home/usuario/django
</pre></div>
<p>No retorno do comando podemos ver algumas informações básicas do app, inclusive a URL, que já está funcionando.
Acesse o endereço e veja a página padrão que foi criada.</p>
<h3>Definindo dependências</h3>
<p>Acesse o repositório que foi criado ao executar <code>rhc app-create</code>, ele terá o nome do seu app:</p>
<div class="highlight"><pre><span class="nb">cd </span>django/
</pre></div>
<p>Existem duas formas de definir as dependências do seu app Python no Openshift, pelo arquivo <strong>setup.py</strong> ou pelo <strong>requirements.txt</strong>.
Durante o processo de <strong>deploy</strong> o Openshift automaticamente executa <code>python setup.py install</code> e <code>pip -r requirements.txt</code> na raiz do repositório.</p>
<p>Usaremos somente o <strong>requirements.txt</strong>, então exclua o <strong>setup.py</strong>.</p>
<div class="highlight"><pre>rm setup.py
</pre></div>
<p>Faça <em>commit</em> mas não execute <code>git push</code> ainda.</p>
<div class="highlight"><pre>git commit -am <span class="s1">'removido setup.py'</span>
</pre></div>
<p>Adicione o Django no <em>requirements.txt</em>:</p>
<div class="highlight"><pre><span class="nb">echo</span> <span class="s1">'Django==1.7'</span> > requirements.txt
</pre></div>
<p>Crie um virtualenv para testar se o <strong>requirements.txt</strong> está correto:</p>
<div class="highlight"><pre>pyenv virtualenv 2.7.8 openshift
pyenv activate openshift
pip install -r requirements.txt
</pre></div>
<p>Por fim, faça um novo <em>commit</em>.</p>
<h3>Criando o projeto Django</h3>
<p>De agora em diante não direi mais para você fazer o <em>commit</em> o tempo todo mas é uma boa prática que você o faça a cada etapa.</p>
<p>Execute o comando abaixo para criar o arquivo <strong>.gitignore</strong> e adicionar algumas entradas nele.
Esse arquivo irá impedir que alguns arquivos desnecessários sejam adicionados ao git.</p>
<div class="highlight"><pre>cat > .gitignore <span class="s"><<EOF</span>
<span class="s">*.pyc</span>
<span class="s">*.sqlite3</span>
<span class="s">EOF</span>
</pre></div>
<p>Crie um projeto Django com o nome <strong>openshift</strong>:</p>
<div class="highlight"><pre>django-admin.py startproject openshift
</pre></div>
<p>Acesse o projeto e crie um <em>app</em> com nome <strong>exemplo</strong>:</p>
<div class="highlight"><pre><span class="nb">cd </span>openshift
django-admin.py startapp exemplo
</pre></div>
<p>Execute o <em>migrate</em> inicial e depois inicie o servidor de teste:</p>
<div class="highlight"><pre>python manage.py migrate
python manage.py runserver
</pre></div>
<p>Acesse o endereço <em>127.0.0.1:8000</em> e verifique se você consegue ver a mensagem <strong>It worked!</strong></p>
<h3>Configurando o projeto</h3>
<p>Ao executar o <em>deploy</em> da sua aplicação, o Openshift irá procurar pelo WSGI <em>entry-point</em> em alguns arquivos.
Um desses arquivos é o <strong>wsgi.py</strong> na raiz do repositório.
O WSGI <em>entry-point</em> nada mais é do que o <em>callable</em> do servidor WSGI.
No nosso caso usamos uma variável mas poderia ser um método ou uma função, o importante é que ele tenha o nome de <strong>application</strong>.</p>
<p>Execute o comando abaixo para criar o WSGI <em>entry-point</em>:</p>
<div class="highlight"><pre>cat > wsgi.py <span class="s"><<EOF</span>
<span class="s">#!/usr/bin/python</span>
<span class="s">import os</span>
<span class="s">import sys</span>
<span class="s">from django.core.wsgi import get_wsgi_application</span>
<span class="s">sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'openshift'))</span>
<span class="s">os.environ['DJANGO_SETTINGS_MODULE'] = 'openshift.production'</span>
<span class="s">application = get_wsgi_application()</span>
<span class="s">EOF</span>
</pre></div>
<p>Abra o arquivo de configuração padrão do seu projeto Django:</p>
<div class="highlight"><pre>vi openshift/openshift/settings.py
</pre></div>
<p>Adicione o app <strong>exemplo</strong> em <strong>INSTALLED_APPS</strong>:</p>
<div class="highlight"><pre><span class="n">INSTALLED_APPS</span> <span class="o">=</span> <span class="p">(</span>
<span class="s">'django.contrib.admin'</span><span class="p">,</span>
<span class="o">...</span>
<span class="s">'exemplo'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
<p>Salve e depois abra o arquivo de configuração que usaremos em produção.</p>
<div class="highlight"><pre>vi openshift/openshift/production.py
</pre></div>
<p>Comece importando todas as configuração do arquivo de configuração padrão:</p>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">settings</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
<p>Desabilite o modo <strong>debug</strong>:</p>
<div class="highlight"><pre><span class="n">DEBUG</span> <span class="o">=</span> <span class="bp">False</span>
</pre></div>
<p>Existem várias variáveis de ambiente dentro de um <em>gear</em>, utilizaremos as seguintes delas em nossa configuração:</p>
<ul>
<li><strong>OPENSHIFT_APP_DNS</strong>: nome completo do domínio da sua aplicação, no meu caso é <em>http://django-stvs.rhcloud.com/</em>.</li>
<li><strong>OPENSHIFT_DATA_DIR</strong>: diretório para dados persistentes.</li>
<li><strong>OPENSHIFT_REPO_DIR</strong>: diretório onde estão os arquivos do <em>deploy</em> atual.</li>
<li><strong>OPENSHIFT_SECRET_TOKEN</strong>: hash gerado automaticamente quando o <em>gear</em> é criado.</li>
</ul>
<p>Você pode ver outras variáveis disponíveis <a href="https://developers.openshift.com/en/managing-environment-variables.html">aqui</a>.</p>
<p>Copie as configurações:</p>
<div class="highlight"><pre><span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">'OPENSHIFT_SECRET_TOKEN'</span><span class="p">]</span>
<span class="n">ALLOWED_HOSTS</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">'OPENSHIFT_APP_DNS'</span><span class="p">]]</span>
<span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">'default'</span><span class="p">:</span> <span class="p">{</span>
<span class="s">'ENGINE'</span><span class="p">:</span> <span class="s">'django.db.backends.sqlite3'</span><span class="p">,</span>
<span class="s">'NAME'</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">'OPENSHIFT_DATA_DIR'</span><span class="p">],</span> <span class="s">'db.sqlite3'</span><span class="p">),</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Os <em>cartridges</em> padrões de Python, utilizam o diretório <em>wsgi/static</em> para servir arquivos estáticos pelo Apache.
Ele ainda não existe, para criá-lo execute:</p>
<div class="highlight"><pre>mkdir -p wsgi/static
touch wsgi/static/.gitkeep
</pre></div>
<p>Por fim adicione a linha abaixo em sua configuração:</p>
<div class="highlight"><pre><span class="n">STATIC_ROOT</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">'OPENSHIFT_REPO_DIR'</span><span class="p">],</span> <span class="s">'wsgi'</span><span class="p">,</span> <span class="s">'static'</span><span class="p">)</span>
</pre></div>
<h2>Criando uma view simples</h2>
<p>Vamos criar uma <em>view</em> básica somente para testar nosso projeto.</p>
<p>Adicione a url abaixo no arquivo <em>openshift/openshift/urls.py</em>:</p>
<div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">''</span><span class="p">,</span>
<span class="n">url</span><span class="p">(</span><span class="s">r'^$'</span><span class="p">,</span> <span class="s">'exemplo.views.home'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'home'</span><span class="p">),</span>
<span class="o">...</span>
</pre></div>
<p>Depois crie a <em>view</em> em <em>openshift/exemplo/views.py</em>:</p>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponse</span>
<span class="k">def</span> <span class="nf">home</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
<span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s">'Hello World!'</span><span class="p">)</span>
</pre></div>
<p>Execute novamente o servidor de teste, acesse o endereço '127.0.0.1:8000/' e confirme que a mensagem <strong>Hello World!</strong> aparece.</p>
<h2>Fazendo deploy</h2>
<p>Na raiz do repositório, existe um diretório oculto chamado <strong>.openshift</strong>.
Vamos listar seu conteúdo:</p>
<div class="highlight"><pre><span class="nb">cd</span> .openshift
tree
.
├── action_hooks
│ └── README.md
├── cron
│ ├── daily
│ ├── hourly
│ ├── minutely
│ ├── monthly
│ ├── README.cron
│ └── weekly
│ ├── chrono.dat
│ ├── chronograph
│ ├── jobs.allow
│ ├── jobs.deny
│ └── README
├── markers
│ └── README.md
└── README.md
</pre></div>
<p>Cada diretório dentro dele tem uma função especial.</p>
<h4>Cron</h4>
<p>Essa pasta serve para agendar a execução de scripts.
Ela funciona igual aos diretórios <strong>cron</strong> em qualquer distribuição Linux.
Você precisa adicionar o <em>cartridge</em> <strong>cron</strong> ao seu app para que os agendamentos funcionem.</p>
<div class="highlight"><pre>rhc cartridge add -a django -c cron-1.4
</pre></div>
<h4>Markers</h4>
<p>Nesta pasta você pode criar arquivos que alteram o comportamento do Openshift durante algumas ações.
Por exemplo, se você criar o arquivo <strong>hot_deploy</strong> o servidor Apache não será reiniciado durante o processo de <strong>build</strong>.
Outras <strong>markers</strong> disponíveis estão detalhadas <a href="http://openshift.github.io/documentation/oo_cartridge_guide.html#markers-7">aqui</a>.</p>
<h4>Action Hooks</h4>
<p>O funcionamento dessa pasta é bem parecido com o da pasta <strong>markers</strong>.
Em algumas ações o Openshift vai procurar determinados arquivos dentro dela e executá-los em uma determinada ordem.
Para listar quais são as ações disponíveis execute o comando <code>rhc app --help</code>:</p>
<div class="highlight"><pre>rhc app --help
Usage: rhc app <action>
Creates and controls an OpenShift application. To see the list of all applications use the rhc domain show command. Note that delete is not reversible
and will stop your application and <span class="k">then</span> remove the application and repo from the remote server. No <span class="nb">local </span>changes are made.
List of Actions
configure Configure several properties that apply to an application
create Create an application
delete Delete an application from the server
deploy Deploy a git reference or binary file of an application
force-stop Stops all application processes
reload Reload the application<span class="s1">'s configuration</span>
<span class="s1">restart Restart the application</span>
<span class="s1">scale-down Scale down the application'</span>s web cartridge
scale-up Scale up the application<span class="s1">'s web cartridge</span>
<span class="s1">show Show information about an application</span>
<span class="s1">start Start the application</span>
<span class="s1">stop Stop the application</span>
<span class="s1">tidy Clean out the application'</span>s logs and tmp directories and tidy up the git repo on the server
</pre></div>
<p>Por exemplo, na ação <strong>build</strong>, os arquivos serão procurados e executados na seguinte ordem:</p>
<ul>
<li>pre_build</li>
<li>build</li>
<li>prepare</li>
<li>deploy</li>
<li>post_deploy</li>
</ul>
<p>Não é preciso que nenhum arquivo exista, essa é só uma forma de controlar o comportamento do seu app.
Para saber mais sobre <em>action hooks</em> clique <a href="http://openshift.github.io/documentation/oo_user_guide.html#cartridge-control-action-hooks">aqui</a>.</p>
<p>No nosso caso, só vamos usar o arquivo <strong>deploy</strong>:</p>
<div class="highlight"><pre>touch .openshift/action_hooks/deploy
</pre></div>
<p>É preciso que o arquivo seja executável, então:</p>
<div class="highlight"><pre>chmod +x .openshift/action_hooks/deploy
</pre></div>
<p>Em nosso <em>deploy</em>, apenas vamos atualizar o schema do banco e recolher os arquivos estáticos.
Note que precisamos informar o arquivo de configuração que usaremos em produção, que é diferente daquele que está no arquivo <strong>manage.py</strong>.</p>
<div class="highlight"><pre>cat > .openshift/action_hooks/deploy <span class="s"><<EOF</span>
<span class="s">PYTHONPATH=\$OPENSHIFT_REPO_DIR/openshift</span>
<span class="s">django-admin.py migrate --settings='openshift.production' --pythonpath=\$PYTHONPATH</span>
<span class="s">python \$PYTHONPATH/manage.py collectstatic -c --noinput --settings='openshift.production' --pythonpath=\$PYTHONPATH</span>
<span class="s">EOF</span>
</pre></div>
<p>Feito isso, faça <em>commit</em> e depois execute <code>git push</code>.
O <em>push</em> irá disparar o processo de <strong>build</strong>.
Você verá varias mensagens em seu terminal mas no final irá aparecer:</p>
<div class="highlight"><pre>...
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
...
</pre></div>
<p>Essa saída mostra que o <strong>deploy</strong> foi executado com sucesso.
Se você acessar a URL da sua app aparecerá <strong>'Hello World!'</strong>.
Pronto seu projeto Django está rodando no Openshift!</p>
<p>Aguardo feedback com dúvidas, sugestões, correções etc nos comentários.</p>
<p>Abraços e bons projetos!</p>
<h2>Bonus</h2>
<ul>
<li>Execute o <code>rhc tail</code> para visualizar o arquivos de log do seu app, ótimo para visualizar problemas.</li>
<li>Acesse a <a href="http://openshift.github.io/documentation/">documentação oficial</a> para saber mais detalhes sobre o Openshift.</li>
<li><a href="https://github.com/eliostvs/django-kb-example">Aqui</a> tem um <em>quickstart</em> de uma base de conhecimento para você utilizar no Openshift.</li>
</ul>
<div class="licence">
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Licença Creative Commons"
style="border-width:0"
src="http://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png"/></a><br/><a
xmlns:dct="http://purl.org/dc/terms/" property="dct:title"
href="http://pythonclub.com.br/deploy-app-django-openshift.html">"Deploy App Django no Openshift"</a> de <a
xmlns:cc="http://creativecommons.org/ns#" href="http://pythonclub.com.br/author/elio-duarte.html"
property="cc:attributionName" rel="cc:attributionURL">"Elio Duarte"</a> está licenciado com uma Licença
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons -
Atribuição-NãoComercial-SemDerivações 4.0 Internacional</a>.
</div>
<div class="sharing">
<!-- Facebook sharing -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&appId=1487080281503641&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button" data-href="http://pythonclub.com.br/deploy-app-django-openshift.html" data-type="button_count"></div>
<!-- Google+ sharing -->
<div class="g-plus alinhar" data-action="share" data-annotation="bubble" data-href="http://pythonclub.com.br/deploy-app-django-openshift.html"></div>
<!-- Twitter sharing -->
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="pt" style="margin-bottom: -4px !important;">Tweetar</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div class="hr"></div>
<a href="#" class="go-top">Topo</a>
<div class="comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: THIS CODE IS ONLY AN EXAMPLE * * */
var disqus_shortname = 'pythonclub'; // Required - Replace example with your forum shortname
var disqus_identifier = 'deploy-app-django-openshift.html';
var disqus_title = 'Deploy App Django no Openshift';
var disqus_url = 'http://pythonclub.com.br/deploy-app-django-openshift.html';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<footer class="footer">
<p>© PythonClub –
Built with <a href="https://github.com/PurePelicanTheme/pure">Pure Theme</a>
for <a href="http://blog.getpelican.com/">Pelican</a>
</p>
</footer> </div>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://pythonclub.com.br/theme/js/dynamic_random_articles.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/fitvids/1.0.1/jquery.fitvids.min.js"></script>
<script>
$(document).ready(function(){
$(".content").fitVids();
});
$(window).load(function(){
$("iframe").css("margin-bottom", "-6px")
$("#twitter-widget-0").css("margin-bottom", "-5px");
$("#twitter-widget-0").css("margin-left", "-1px");
});
</script>
<script type="text/javascript" src="https://apis.google.com/js/platform.js">
{lang: 'pt-BR'}
</script>
<script>
var $top = $('.go-top');
// Show or hide the sticky footer button
$(window).scroll(function() {
if ($(this).scrollTop() > 200) {
$top.fadeIn(200);
} else {
$top.fadeOut(200);
}
});
// Animate the scroll to top
$top.click(function(event) {
event.preventDefault();
$('html, body').animate({scrollTop: 0}, 300);
})
// Makes sure that the href="#" attached to the <a> elements
// don't scroll you back up the page.
$('body').on('click', 'a[href="#"]', function(event) {
event.preventDefault();
});
$(function(){
show_random_articles($('#random-articles'), [{"url": "http://pythonclub.com.br/django-introducao-queries.html", "title": "Como otimizar suas consultas no Django - De N a 1 em 20 minutos"}, {"url": "http://pythonclub.com.br/django-overview-10-minutos.html", "title": "Django - 3 anos em 10 minutos"}, {"url": "http://pythonclub.com.br/configurando-ambiente-django-com-apache-e-mod-wsgi.html", "title": "Configurando ambiente Django com Apache e mod_wsgi"}, {"url": "http://pythonclub.com.br/tuplas-mutantes-em-python.html", "title": "Tuplas mutantes em Python"}, {"url": "http://pythonclub.com.br/postgresql-e-django.html", "title": "PostgreSql e Django - parte 3"}, {"url": "http://pythonclub.com.br/postgresql-e-python3.html", "title": "PostgreSql e Python3 - parte 2"}, {"url": "http://pythonclub.com.br/microframework-contra-baterias-incluidas.html", "title": "Microframework contra "Baterias Inclu\u00eddas""}, {"url": "http://pythonclub.com.br/debugging-em-python-sem-ide.html", "title": "Debugging em python (sem IDE)"}, {"url": "http://pythonclub.com.br/tutorial-postgresql.html", "title": "Tutorial PostgreSql - parte 1"}, {"url": "http://pythonclub.com.br/conteinerizando-suas-aplicacoes-django-com-docker-e-fig.html", "title": "Conteinerizando suas aplica\u00e7\u00f5es django com docker e fig"}, {"url": "http://pythonclub.com.br/publicando-seu-hello-world-no-heroku.html", "title": "Publicando seu Hello World no Heroku"}, {"url": "http://pythonclub.com.br/entrevista-henrique-bastos.html", "title": "Entrevista com Henrique Bastos"}, {"url": "http://pythonclub.com.br/testes-de-carga-com-o-locust.html", "title": "Testes de carga com o Locust"}, {"url": "http://pythonclub.com.br/tutorial-django-17.html", "title": "Tutorial Django 1.7"}, {"url": "http://pythonclub.com.br/integrando-django-com-cloudinary.html", "title": "Integrando o Django com Cloudinary"}, {"url": "http://pythonclub.com.br/bottle-framework-full-stack-sem-django.html", "title": "Bottle Framework full stack sem Django"}, {"url": "http://pythonclub.com.br/desenvolvendo-com-bottle-parte-1.html", "title": "Desenvolvendo com Bottle - Parte 1"}, {"url": "http://pythonclub.com.br/gerenciando-banco-dados-sqlite3-python-parte2.html", "title": "Gerenciando banco de dados SQLite3 com Python - Parte 2"}, {"url": "http://pythonclub.com.br/solucao-quase-definitiva-para-permissoes-em-projetos-django.html", "title": "Solu\u00e7\u00e3o (quase) definitiva para permiss\u00f5es em projetos Django"}, {"url": "http://pythonclub.com.br/gerenciando-assets-com-django-pipeline.html", "title": "Gerenciando assets com django-pipeline"}, {"url": "http://pythonclub.com.br/deploy-app-django-openshift.html", "title": "Deploy App Django no Openshift"}, {"url": "http://pythonclub.com.br/criando-sites-estaticos-com-pelican.html", "title": "Criando sites est\u00e1ticos com Pelican Framework"}, {"url": "http://pythonclub.com.br/selenium-parte-4.html", "title": "Selenium - O que voc\u00ea deveria saber - Parte 4"}, {"url": "http://pythonclub.com.br/configurando-um-servidor-de-producao-para-aplicacoes-python.html", "title": "Configurando um servidor de produ\u00e7\u00e3o para aplica\u00e7\u00f5es Python"}, {"url": "http://pythonclub.com.br/what-the-flask-pt-2-flask-patterns-boas-praticas-na-estrutura-de-aplicacoes-flask.html", "title": "What the Flask? Pt-2 Flask Patterns - boas pr\u00e1ticas na estrutura de aplica\u00e7\u00f5es Flask"}, {"url": "http://pythonclub.com.br/gerenciando-banco-dados-sqlite3-python-parte1.html", "title": "Gerenciando banco de dados SQLite3 com Python - Parte 1"}, {"url": "http://pythonclub.com.br/introducao-classes-metodos-python-basico.html", "title": "Introdu\u00e7\u00e3o a Classes e M\u00e9todos em Python (b\u00e1sico)"}, {"url": "http://pythonclub.com.br/pyftpdlib-criando-um-servidor-ftp-simples-com-python.html", "title": "pyftpdlib - Criando um servidor FTP simples com python"}, {"url": "http://pythonclub.com.br/usando-redis-cache-django.html", "title": "Usando Redis para cache e sess\u00e3o do Django"}, {"url": "http://pythonclub.com.br/aprendendo-e-ensinando-python.html", "title": "Aprendendo e Ensinando Python"}, {"url": "http://pythonclub.com.br/selenium-parte-3.html", "title": "Selenium - O que voc\u00ea deveria saber - Parte 3"}, {"url": "http://pythonclub.com.br/what-the-flask-pt-1-introducao-ao-desenvolvimento-web-com-python.html", "title": "What the Flask? Pt-1 Introdu\u00e7\u00e3o ao desenvolvimento web com Python"}, {"url": "http://pythonclub.com.br/selenium-parte-2.html", "title": "Selenium - O que voc\u00ea deveria saber - Parte 2"}, {"url": "http://pythonclub.com.br/guia-rapido-comandos-sqlite3.html", "title": "Guia r\u00e1pido de comandos SQLite3"}, {"url": "http://pythonclub.com.br/editando-o-admin-do-django.html", "title": "Editando o Admin do Django"}, {"url": "http://pythonclub.com.br/instalacao-python-django-windows.html", "title": "Instalando e Configurando o Python e Django no Windows"}, {"url": "http://pythonclub.com.br/criar-site-com-form-lista-30-min.html", "title": "Como criar um site com formul\u00e1rio e lista em 30 minutos?"}, {"url": "http://pythonclub.com.br/principais-duvidas-de-quem-quer-aprender-django.html", "title": "Principais d\u00favidas de quem quer aprender Django"}, {"url": "http://pythonclub.com.br/parseando-sites-com-beautifulsoup.html", "title": "Exemplo de como "Parsear" Sites com BeautifulSoup"}, {"url": "http://pythonclub.com.br/deploy-com-django-fagungis.html", "title": "Publica\u00e7\u00e3o de projetos com o Django-Fagungis"}, {"url": "http://pythonclub.com.br/como-fazer-fork-clone-push-pull-request-no-github.html", "title": "Como fazer fork, clone, push pull-request no Github"}, {"url": "http://pythonclub.com.br/primeiro-projeto-django-no-linux-com-sublime.html", "title": "Seu primeiro projeto Django com Sublime Text no Linux"}, {"url": "http://pythonclub.com.br/introducao-a-testes-funcionais-com-selenium-e-python.html", "title": "Introdu\u00e7\u00e3o a testes funcionais com Selenium e Python"}, {"url": "http://pythonclub.com.br/selenium-parte-1.html", "title": "Selenium - O que voc\u00ea deveria saber - Parte 1"}, {"url": "http://pythonclub.com.br/5-django-apps-que-nao-vivo-se.html", "title": "5 Django Apps que n\u00e3o vivo sem"}, {"url": "http://pythonclub.com.br/sobre-o-six-e-como-ele-ajuda-a-escrever-codigo-compativel-com-python-2-e-3.html", "title": "Sobre o six e como ele ajuda a escrever c\u00f3digo compat\u00edvel com python 2 e 3"}, {"url": "http://pythonclub.com.br/como_colaborar_com_projetos_open_source.html", "title": "Como colaborar na tradu\u00e7\u00e3o do Djangobook sem conhecer programa\u00e7\u00e3o"}], 10);
});
</script>
<div id="spot-im-root"></div>
<script type="text/javascript">!function(t,o,p){function e(){var t=o.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"==o.location.protocol?"https":"http")+":"+p,o.body.appendChild(t)}t.spotId="3de816246c80a51757bb01c5b8c95cda",t.spotName="",t.allowDesktop=!0,t.allowMobile=!1,t.containerId="spot-im-root",e()}(window.SPOTIM={},document,"//www.spot.im/embed/scripts/launcher.js");</script>
</body>
</html>