Skip to content

Commit

Permalink
Merge pull request #1 from ttscience/devel
Browse files Browse the repository at this point in the history
CI/CD and overall API structure
  • Loading branch information
ErdaradunGaztea authored Oct 20, 2023
2 parents a339b78 + aea49bb commit ed1e66e
Show file tree
Hide file tree
Showing 19 changed files with 2,069 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^renv$
^renv\.lock$
^\.github$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
33 changes: 33 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, devel]
pull_request:
branches: [main, devel]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ubuntu-latest

name: Ubuntu (latest)

strategy:
fail-fast: false

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- name: Build image
run: docker build -t unbiased --build-arg github_sha=${{ github.sha }} .

- name: Run tests
run: docker compose -f "docker-compose.test.yaml" up --abort-on-container-exit --exit-code-from tests --attach tests
3 changes: 3 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
build-args: github_sha=${{ github.sha }}

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
Expand Down
29 changes: 27 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
FROM alpine
CMD ["echo", "Hello TTSI!..."]
FROM rocker/r-ver:4.3.1

WORKDIR /src/unbiased

# Install system dependencies
RUN apt update && apt-get install -y --no-install-recommends \
# httpuv
libz-dev \
# sodium
libsodium-dev

ENV RENV_CONFIG_SANDBOX_ENABLED=FALSE

COPY ./renv ./renv
COPY .Rprofile .
COPY renv.lock .

RUN R -e 'renv::restore()'

COPY api/ ./api

EXPOSE 3838

ARG github_sha
ENV GITHUB_SHA=${github_sha}

CMD ["R", "-e", "plumber::plumb(dir = 'api') |> plumber::pr_run(host = '0.0.0.0', port = 3838)"]
10 changes: 10 additions & 0 deletions api/meta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#* Github commit SHA
#*
#* Each release of the API is based on some Github commit. This endpoint allows
#* the user to easily check the SHA of the deployed API version.
#*
#* @get /sha
#* @serializer unboxedJSON
function() {
Sys.getenv("GITHUB_SHA", unset = "")
}
9 changes: 9 additions & 0 deletions api/plumber.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#* @plumber
function(api) {
rand_simple <- plumber::pr("randomize-simple.R")
meta <- plumber::pr("meta.R")

api |>
plumber::pr_mount("/simple", rand_simple) |>
plumber::pr_mount("/meta", meta)
}
11 changes: 11 additions & 0 deletions api/randomize-simple.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#* Return hello world
#*
#* @get /hello
#* @serializer unboxedJSON
function() {
call_hello_world()
}

call_hello_world <- function() {
"Hello TTSI!"
}
24 changes: 24 additions & 0 deletions docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.9"
services:
api:
image: unbiased
container_name: unbiased_api
networks:
- test_net
tests:
image: unbiased
container_name: unbiased_tests
depends_on:
- api
environment:
- CI=true
networks:
- test_net
volumes:
- type: bind
source: ./tests
target: /src/unbiased/tests
command: Rscript tests/testthat.R

networks:
test_net:
Loading

0 comments on commit ed1e66e

Please sign in to comment.