Skip to content

Commit

Permalink
Merge pull request #68 from ScilifelabDataCentre/feature/shinyproxy
Browse files Browse the repository at this point in the history
Feature/shinyproxy
  • Loading branch information
sandstromviktor authored Oct 11, 2023
2 parents 5de277d + 5bfa909 commit ec1b50a
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/serve-shinyproxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Serve-Shinyproxy workflow

on:
push:
paths:
- "serve-shinyproxy/**"

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main

- name: 'Build test image'
run: |
docker build -t ghcr.io/scilifelabdatacentre/serve-shinyproxy:latest ./serve-shinyproxy
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: 'ghcr.io/scilifelabdatacentre/serve-shinyproxy:latest'
format: 'table'
severity: 'CRITICAL,HIGH'
timeout: '30m0s'
exit-code: '0'

- name: 'Run tests'
env:
IMAGE_NAME: ghcr.io/scilifelabdatacentre/serve-shinyproxy:latest
run: |
pip install -r ./serve-shinyproxy/tests/requirements.txt
python3 -m pytest ./serve-shinyproxy
push:
if: |
github.ref == 'refs/heads/main' &&
github.repository == 'scilifelabdatacentre/serve-images'
needs: build_and_test
runs-on: ubuntu-latest
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
permissions:
contents: read
packages: write

steps:
- name: 'Checkout github action'
uses: actions/checkout@main

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/scilifelabdatacentre/serve-shinyproxy
tags: |
type=raw,value={{date 'YYMMDD-HHmm' tz='Europe/Stockholm'}}
- name: 'Login to GHCR'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Publish image to GHCR
uses: docker/build-push-action@v3
with:
file: ./serve-shinyproxy/Dockerfile
context: ./serve-shinyproxy
push: true
build-args: version=${{ github.ref_name }}
tags: |
${{ steps.meta.outputs.tags }}
ghcr.io/scilifelabdatacentre/serve-shinyproxy:latest
labels: ${{ steps.meta.outputs.labels }}
11 changes: 11 additions & 0 deletions dev_scripts/run_shinyproxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -o errexit

docker build -t shinyproxy-dev-img ../serve-shinyproxy
python3 -m venv venv
source ./venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r ../serve-shinyproxy/tests/requirements.txt
export IMAGE_NAME=shinyproxy-dev-img
python3 -m pytest ../serve-shinyproxy/
9 changes: 9 additions & 0 deletions serve-shinyproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openanalytics/shinyproxy:3.0.2

ENV SHINY_USER shinyproxy
RUN chown $SHINY_USER:$SHINY_USER /opt/shinyproxy/

WORKDIR /opt/shinyproxy
USER $SHINY_USER

CMD ["java", "-noverify", "-jar", "/opt/shinyproxy/shinyproxy.jar", "--spring.jmx.enabled=false", "--spring.config.location=/opt/shinyproxy/application.yml"]
2 changes: 2 additions & 0 deletions serve-shinyproxy/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker
pytest
61 changes: 61 additions & 0 deletions serve-shinyproxy/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import requests
import docker
import time

PORT = 8080 # Shinyproxy port
TIMEOUT_CALL = 5 # the timeout in seconds of the client request call

client = docker.from_env()
container = client.containers.run(
image=os.environ["IMAGE_NAME"],
ports={f"{PORT}/tcp": PORT},
detach=True,
)
time.sleep(10) # Update this somehow.
container.reload()


def test_container_status():
"""Test that the Shinyproxy container is running."""
assert container.status == "running"


def test_container_ports():
"""Test of the expected container port."""
assert len(container.ports) == 1, "There should be 1 port"
assert container.ports[f"{PORT}/tcp"][0]["HostPort"] == str(PORT)


def test_login():
url = _get_url(container) + "/login"
max_attempts = 50

for attempt in range(1, max_attempts + 1):
try:
print("URL is: ", url)
response = requests.get(url, timeout=TIMEOUT_CALL)
if response.status_code == 200:
print("Shinyproxy is up and running!")
assert True
break
except:
pass

if attempt == max_attempts:
RuntimeError(
f"Shinyproxy did not become ready after {max_attempts} attempts"
)
assert False

print(
f"Attempt {attempt} failed, waiting for 10 seconds before trying again..."
)
time.sleep(10)


def _get_url(container):
"""Gets the URL of the container."""
ip = container.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"]
url = "http://{}:{}".format(ip, PORT)
return url

0 comments on commit ec1b50a

Please sign in to comment.