Skip to content

Commit

Permalink
add docker slides (#10)
Browse files Browse the repository at this point in the history
* add docker slides

* bare bones docker slides

* move content to deploy slides

* add classwork shell

* look at model before prepare_docker

* clean up names
  • Loading branch information
isabelizimm authored Aug 18, 2023
1 parent 1b56040 commit e301ecf
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 1 deletion.
62 changes: 62 additions & 0 deletions class-work/docker.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
format: html
title: Deploying a model with Docker
---

## Choose a pinned model to deploy

```{python}
#| eval: false
import pins
import os
from dotenv import load_dotenv
from vetiver import VetiverModel
load_dotenv()
api_key = os.getenv("CO_API_KEY")
rsc_url = os.getenv("CO_RSC_URL")
board = board_connect(server_url=rsc_url, api_key=api_key, allow_pickle_read = True)
VetiverModel.from_pin(
board,
"isabel.zimmerman/inspection-python",
version = "20220901T144702Z-fd402"
).description
```

## Create artifacts to run a Dockerfile

```{python}
#| eval: false
import vetiver
vetiver.prepare_docker(
board = ___,
pin_name = ___,
version = ___,
host = ___,
port = ___
)
```

What outputs are created?

## Build your container

```bash
docker build -t inpection .
```

## Run your container

```bash
docker run --env-file .env -p 8080:8080 inpection
```

## Make predictions

```{python}
#| eval: false
endpoint = vetiver.vetiver_endpoint(url = ___)
vetiver.predict(endpoint = ___, data = ___)
```
96 changes: 95 additions & 1 deletion slides/03-deploy.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,103 @@ knitr:

- A public or private cloud, using Docker

# {background-color="white" background-image="https://1000logos.net/wp-content/uploads/2021/11/Docker-Logo-1536x864.png" background-size="70%"}

# Docker

tktk
_Containerized environments for your code._

## Why Docker?

::: nonincremental
- Open source
- Reproducible
- Bring your own container philosophy
:::

::: notes
ECR in AWS, etc
huggingface
:::

## Why Docker?

![](https://external-preview.redd.it/aR6WdUcsrEgld5xUlglgKX_0sC_NlryCPTXIHk5qdu8.jpg?auto=webp&s=5fe64dd318eec71711d87805d43def2765dd83cd){fig-align="center"}

## Create Docker artifacts

- Start with a trained and versioned model

## Create Docker artifacts

::: nonincremental
- Dockerfile
- Model dependencies, typically `requirements.txt` or `renv.lock`
- File to serve API, typically `app.py` or `plumber.R`
:::

### R

```{r}
#| eval: false
vetiver_prepare_docker(board, "isabel.zimmerman/inspection-results-r", port = 8080)
```

### Python

```{python}
#| eval: false
vetiver.prepare_docker(
board,
"isabel.zimmerman/inspection-results-python",
version = "20220901T144702Z-fd402",
port = 8080
)
```

## Build your container

```bash
docker build -t inspection .
```

## Run your container

```bash
docker run --env-file .env -p 8080:8080 inspection
```

::: notes
probably .Renv if you are in R
:::

## Make predictions

### R

```{r}
#| eval: false
endpoint <- vetiver_endpoint("http://0.0.0.0:8080/predict")
predict(endpoint, X_test)
```

### Python

```{python}
#| eval: false
endpoint = vetiver.vetiver_endpoint("http://0.0.0.0:8080/predict")
vetiver.predict(endpoint=endpoint, data=X_test)
```

# Demo

## Docker resources

- [Enough Docker to be Dangerous](https://seankross.com/2017/09/17/Enough-Docker-to-be-Dangerous.html)
- [Python Docker](https://zetcode.com/python/docker/)
- [Ten simple rules for writing Dockerfiles for reproducible data science](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1008316)
- [Docker info from Posit Solutions Engineering](https://solutions.posit.co/envs-pkgs/environments/docker/)

# Deploy preprocessors and models together

Expand Down

0 comments on commit e301ecf

Please sign in to comment.