Skip to content

Commit

Permalink
Slides aula 12
Browse files Browse the repository at this point in the history
  • Loading branch information
dunossauro committed Jul 21, 2024
1 parent a1ae22b commit 86656e7
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 13 deletions.
45 changes: 34 additions & 11 deletions slides/brutos/aula_12.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,66 @@ theme: rose-pine

---

## Deploy

A ultima parte do processo do código, **colocar em produção**.

No caso da nossa API, é "soltar ela no mundo" para que as outras pessoas usar. Liberar na internet.

---

## Fly.io

> Um blah sobre o fly
O Fly.io é uma plataforma de deploy que nos permite fazer o lançamento nossas aplicações na nuvem e que oferece serviços para diversas linguagens de programação e frameworks como Python e Django, PHP e Laravel, Ruby e Rails, Elixir e Phoenix, etc.

Ao mesmo tempo, em que permite que o deploy de aplicações em containers docker também possam ser utilizadas, como é o nosso caso. Além disso, o Fly disponibiliza bancos de dados para serem usados em nossas aplicações, como PostgreSQL e Redis.

---

## PaaS
## Mas, Fly.io?

A ideia de usar o fly.io é que ele oferece uma plataforma simplificada para deploy. Sendo necessário nos preocuparmos somente o container Docker da nossa aplicação.

> Um blah sobre o PaaS
O restante das configurações fica a encargo deles.

---

## Uma notícia incrível <3
## PaaS - Platform as a service

Temos um cumpom de crédito para usar o fly:
https://fly.io/fastapi-do-zero-2024
Uma plataforma como serviço significa que contratamos um serviço de plataforma.

Por plataforma entenda que o serviço contratado vai cuidar de:

Obrigado de mais Kátia Nakamura <3 <3 <3
- Segurança
- Rede
- Disponibilidade
- Atualizações / Manutenção
- ...

Entregamos container ao serviço e damos "play"

---

## Deploy
## Uma notícia incrível <3

> Um blah sobre o Deploy
Temos um cumpom de crédito para usar o fly:
https://fly.io/fastapi-do-zero-2024


Obrigado de mais Kátia Nakamura <3 <3 <3

---

## Flyctl

> Um blah sobre o flyctl
O flyctl é um CLI do fly que podemos usar para fazer as funções administrativas da aplicação pelo terminal:

```bash
flyctl version
```

> Caso precise instalar o [flyctl](https://fly.io/docs/flyctl/)
---

## Autenticação via CLI
Expand Down
103 changes: 101 additions & 2 deletions slides/html/aula_12.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,112 @@

/* Code blok */div#\:\$p>svg>foreignObject>section .hljs-bullet{color:var(--text)}div#\:\$p>svg>foreignObject>section .hljs-comment{color:var(--muted)}div#\:\$p>svg>foreignObject>section .hljs-attr{color:var(--foam)}div#\:\$p>svg>foreignObject>section .hljs-punctuation{color:var(--subtle)}div#\:\$p>svg>foreignObject>section .hljs-string{color:var(--gold)}div#\:\$p>svg>foreignObject>section .hljs-title{color:var(--foam)}div#\:\$p>svg>foreignObject>section .hljs-keyword{color:var(--pine)}div#\:\$p>svg>foreignObject>section .hljs-variable{color:var(--text)}div#\:\$p>svg>foreignObject>section .hljs-literal{color:var(--rose)}div#\:\$p>svg>foreignObject>section .hljs-type{color:var(--love)}div#\:\$p>svg>foreignObject>section .hljs-number{color:var(--gold)}div#\:\$p>svg>foreignObject>section .hljs-built_in{color:var(--love)}div#\:\$p>svg>foreignObject>section .hljs-params{color:var(--iris)}div#\:\$p>svg>foreignObject>section .hljs-symbol{color:var(--foam)}div#\:\$p>svg>foreignObject>section .hljs-meta{color:var(--subtle)}div#\:\$p>svg>foreignObject>section .hljs-subst{color:var(--subtle)}div#\:\$p>svg>foreignObject>section blockquote{font-size:20px}div#\:\$p>svg>foreignObject>section blockquote p{font-size:20px}div#\:\$p>svg>foreignObject>section blockquote p a{font-size:30px}div#\:\$p>svg>foreignObject>section div.mermaid{text-align:center}div#\:\$p>svg>foreignObject>section img[alt~=center]{display:block;margin:0 auto}div#\:\$p>svg>foreignObject>section .columns{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:calc(var(--marpit-root-font-size, 1rem) * 1)}

/* @theme wocl7k64ubdnkd9hydgr59hqpqgsr88lmmwx2wj7t7lh */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-theme="wocl7k64ubdnkd9hydgr59hqpqgsr88lmmwx2wj7t7lh" lang="en-US" style="--theme:wocl7k64ubdnkd9hydgr59hqpqgsr88lmmwx2wj7t7lh;">
/* @theme cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h1 id="fazendo-deploy-no-flyio">Fazendo deploy no Fly.io</h1>
<blockquote>
<p><a href="https://fastapidozero.dunossauro.com/12/">https://fastapidozero.dunossauro.com/12/</a></p>
</blockquote>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-theme="wocl7k64ubdnkd9hydgr59hqpqgsr88lmmwx2wj7t7lh" lang="en-US" style="--theme:wocl7k64ubdnkd9hydgr59hqpqgsr88lmmwx2wj7t7lh;">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="objetivos-dessa-aula">Objetivos dessa aula</h2>
<ul>
<li>Entender o que é o Fly.io e como usar sua CLI</li>
<li>Aprender a fazer o deploy de uma aplicação Docker no Fly.io</li>
<li>Configurar uma instância do PostgreSQL no Fly.io</li>
<li>Configurar as variáveis de ambiente</li>
<li>Rodar as migrações em produção</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="deploy">Deploy</h2>
<p>A ultima parte do processo do código, <strong>colocar em produção</strong>.</p>
<p>No caso da nossa API, é &quot;soltar ela no mundo&quot; para que as outras pessoas usar. Liberar na internet.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="flyio">Fly.io</h2>
<p>O Fly.io é uma plataforma de deploy que nos permite fazer o lançamento nossas aplicações na nuvem e que oferece serviços para diversas linguagens de programação e frameworks como Python e Django, PHP e Laravel, Ruby e Rails, Elixir e Phoenix, etc.</p>
<p>Ao mesmo tempo, em que permite que o deploy de aplicações em containers docker também possam ser utilizadas, como é o nosso caso. Além disso, o Fly disponibiliza bancos de dados para serem usados em nossas aplicações, como PostgreSQL e Redis.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="mas-flyio">Mas, Fly.io?</h2>
<p>A ideia de usar o fly.io é que ele oferece uma plataforma simplificada para deploy. Sendo necessário nos preocuparmos somente o container Docker da nossa aplicação.</p>
<p>O restante das configurações fica a encargo deles.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="paas---platform-as-a-service">PaaS - Platform as a service</h2>
<p>Uma plataforma como serviço significa que contratamos um serviço de plataforma.</p>
<p>Por plataforma entenda que o serviço contratado vai cuidar de:</p>
<ul>
<li>Segurança</li>
<li>Rede</li>
<li>Disponibilidade</li>
<li>Atualizações / Manutenção</li>
<li>...</li>
</ul>
<p>Entregamos container ao serviço e damos &quot;play&quot;</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="uma-not%C3%ADcia-incr%C3%ADvel-3">Uma notícia incrível &lt;3</h2>
<p>Temos um cumpom de crédito para usar o fly:<br />
<a href="https://fly.io/fastapi-do-zero-2024">https://fly.io/fastapi-do-zero-2024</a></p>
<p>Obrigado de mais Kátia Nakamura &lt;3 &lt;3 &lt;3</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="flyctl">Flyctl</h2>
<p>O flyctl é um CLI do fly que podemos usar para fazer as funções administrativas da aplicação pelo terminal:</p>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">flyctl version
</code></pre>
<blockquote>
<p>Caso precise instalar o <a href="https://fly.io/docs/flyctl/">flyctl</a></p>
</blockquote>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="autentica%C3%A7%C3%A3o-via-cli">Autenticação via CLI</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">flyctl auth login
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="configura%C3%A7%C3%A3o-para-o-deploy">Configuração para o deploy</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">flyctl launch --no-deploy
</code></pre>
<p>Responda um absoluto Y aqui:</p>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash"><span class="hljs-comment"># ...</span>
? Do you want to tweak these settings before proceeding? (y/N)
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="manuzeando-nossa-vari%C3%A1veis-de-ambiente">Manuzeando nossa variáveis de ambiente</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">flyctl secrets list
flyctl secrets <span class="hljs-built_in">set</span> DATABASE_URL=???
flyctl secrets <span class="hljs-built_in">set</span> ALGORITHM=<span class="hljs-string">&quot;HS256&quot;</span>
flyctl secrets <span class="hljs-built_in">set</span> SECRET_KEY=<span class="hljs-string">&quot;your-secret-key&quot;</span>
flyctl secrets <span class="hljs-built_in">set</span> ACCESS_TOKEN_EXPIRE_MINUTES=30
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="fazendo-o-deploy">Fazendo o deploy</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">fly deploy --local-only --ha=<span class="hljs-literal">false</span>

<span class="hljs-comment"># ...</span>

Visit your newly deployed app at https://fastzeroapp.fly.dev/
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="executando-as-migra%C3%A7%C3%B5es">Executando as migrações</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">flyctl ssh console -a fastzeroapp -C <span class="hljs-string">&quot;poetry run alembic upgrade head&quot;</span>
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="quiz">Quiz</h2>
<p>Não esqueça de responder ao <a href="https://fastapidozero.dunossauro.com/quizes/aula_12/">quiz</a> dessa aula!</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-theme="cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h" lang="en-US" style="--theme:cnyvyre85co2tlykyibcer7khleg0sqdhm9ndxz31m9h;">
<h2 id="commit">Commit</h2>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-bash">git add .
git commit -m <span class="hljs-string">&quot;Adicionando arquivos gerados pelo Fly&quot;</span>
git push
</code></pre>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true,theme:'dark'});</script>
</section>
Expand Down
Binary file modified slides/pdf/aula_12.pdf
Binary file not shown.

0 comments on commit 86656e7

Please sign in to comment.