Skip to content

Commit

Permalink
Merge pull request #58 from ropensci-review-tools/ollama
Browse files Browse the repository at this point in the history
fix ollama & docker container for #49
  • Loading branch information
mpadge authored Oct 28, 2024
2 parents 941fd87 + 8f5aa0a commit 86b1e20
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
schedule:
- cron: "0 0 1 * *"
- cron: "0 0 1 * *" # 1st day of each month

jobs:

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkgmatch
Title: Find R Packages Matching Either Descriptions or Other R Packages
Version: 0.4.0.074
Version: 0.4.0.077
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM ollama/ollama:latest
FROM ubuntu
MAINTAINER Mark Padgham <[email protected]>

RUN apt-get update && apt-get install -y curl

RUN curl -fsSL https://ollama.com/install.sh | sh

RUN nohup bash -c "ollama serve &" \
&& sleep 5 \
&& ollama pull jina/jina-embeddings-v2-base-en \
&& ollama pull ordis/jina-embeddings-v2-base-code

EXPOSE 11434

CMD ["serve"]
CMD ["ollama", "serve"]
25 changes: 24 additions & 1 deletion R/ollama.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@ is_docker_sudo <- function () {
error = function (e) NULL
)
)
any (grepl ("root\\s", out))
chk <- any (grepl ("root\\s", out))
if (chk) {
# Retain 'TRUE' only if current user in not in "docker" group:
cmd <- "grep /etc/group -e 'docker'"
suppressWarnings (
out <- tryCatch (
system (cmd, intern = TRUE, ignore.stderr = TRUE),
error = function (e) NULL
)
)
if (!is.null (out)) {
user_docker <- gsub ("^.*\\:", "", out)
suppressWarnings (
user_current <- tryCatch (
system ("echo $USER", intern = TRUE, ignore.stderr = TRUE),
error = function (e) NULL
)
)
if (user_current == user_docker) {
chk <- FALSE
}
}
}
return (chk)
}

has_ollama <- function (sudo = is_docker_sudo ()) {
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/pkgmatch",
"issueTracker": "https://github.com/ropensci-review-tools/pkgmatch/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.4.0.074",
"version": "0.4.0.077",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
30 changes: 26 additions & 4 deletions vignettes/ollama.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,36 @@ output of `ollama list`.
## Docker

This package comes with a "Dockerfile" containing all code needed to build and
run the necessary ollama models within a docker container. To do this, download
the [Dockerfile from this
run the necessary ollama models within a docker container. This can be either
built locally, or downloaded from the GitHub container registry.

### Building the Docker container locally

To build the container locally, download the [Dockerfile from this
link](https://github.com/ropensci-review-tools/pkgmatch/blob/main/Dockerfile).
Then from the same directory as that file, run these lines:

``` bash
docker build . -t ollama-models
docker run --rm -p 11434:11434 ollama-models &
docker build . -t pkgmatch-ollama
```

### Downloading the pre-build Docker container

Alternatively, the Docker container including the ollama models used to run
this package is stored in the GitHub container registry, and can be downloaded
by running this line:

``` bash
docker pull ghcr.io/ropensci-review-tools/pkgmatch-ollama:latest
```

### Running the Docker container

Whether you've locally built the Docker container, or downloaded the pre-built
version, the container needs to be started with the following command:

``` bash
docker run --rm -d -p 11434:11434 ollama-models
```

The running container can be stopped by calling `docker stop` followed the the
Expand Down

0 comments on commit 86b1e20

Please sign in to comment.