Skip to content

Commit

Permalink
base app
Browse files Browse the repository at this point in the history
  • Loading branch information
zabkwak committed May 24, 2022
0 parents commit 646d67c
Show file tree
Hide file tree
Showing 8 changed files with 621 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.RData
.Rhistory
77 changes: 77 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
- test

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: mat-twitter-score-analyzer

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile --build-arg NPM_GITHUB_READ=${{ secrets.CR_PAT }}
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --build-arg NPM_GITHUB_READ=${{ secrets.CR_PAT }}

- name: Log into GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
[ "$VERSION" == "test" ] && VERSION=test
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.RData
.Rhistory
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM rocker/r-ver:latest

ARG NPM_GITHUB_READ
ENV NPM_GITHUB_READ=$NPM_GITHUB_READ
WORKDIR /usr/src/app
COPY . .

RUN apt-get update && apt-get -y install libglu1 libxml2 libglpk-dev

RUN install2.r --error shiny
RUN install2.r --error shinythemes
RUN install2.r --error ade4
RUN install2.r --error vegan
RUN install2.r --error vegan3d
RUN install2.r --error polycor
RUN install2.r --error psych
RUN install2.r --error BayesLCA
RUN install2.r --error igraph

ENV PORT=8080
LABEL org.opencontainers.image.source https://github.com/zabkwak/mat-twitter-score-analyzer
EXPOSE 8080

CMD [ "Rscript", "main.R" ]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# mat-twitter-score-analyzer
The visualization of affinity data from [mat-twitter-downloader](https://github.com/zabkwak/mat-twitter-downloader). It's based on shiny app.

## Development
### Requirements
- R (Rscript)
#### Ubuntu
- libglu1
- libxml2
- libbglpk-dev

### Installation & test run
```bash
git clone [email protected]:zabkwak/mat-twitter-score-analyzer.git
cd mat-twitter-score-analyzer
Rscript -e "install.packages(c('shiny', 'shinythemes', 'ade4', 'vegan', 'vegan3d', 'polycor', 'psych', 'BayesLCA', 'igraph))"
Rscript main.R
```
The app will be accessible on `http://localhost:8080`.

## Settings
No additional configuration is needed.

## Docker
The [image](https://github.com/zabkwak/mat-twitter-score-analyzer/pkgs/container/mat-twitter-score-analyzer) is stored in GitHub packages registry and the app can be run in the docker environment.
```bash
docker pull ghcr.io/zabkwak/mat-twitter-score-analyzer:latest
```

```bash
docker run \
--name=mat-twitter-score-analyzer \
-p 127.0.0.1:8080:8080 \
-d \
--restart=unless-stopped \
--name=mat-twitter-score-analyzer
ghcr.io/zabkwak/mat-twitter-score-analyzer:latest
```
11 changes: 11 additions & 0 deletions main.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library(shiny)

port <- Sys.getenv("PORT")

if (exists(port)) {
port <- strtoi(port)
} else {
port <- 8080
}

shiny::runApp(getwd(), port, FALSE, "0.0.0.0")
Loading

0 comments on commit 646d67c

Please sign in to comment.