Skip to content

Commit

Permalink
Add CI/CD Pipeline (#1)
Browse files Browse the repository at this point in the history
* feat: docker build (#1)

* fix: switch branch to master

* fix: add renv lock

* fix: udpate the docker file

* functional shiny app (#2)

Co-authored-by: zoey-rw <[email protected]>

* fix: update packages

* fix: update dependencies

* fix: downgrade shiny

* fix: add conflict management

* fix: add conflict package

* fix: update conflicted

* feat: test this app.R file

* fix: use older app file

* feat: add docker compose

* added docker compose. need to run python clean scripts before running init.sql

* updated init file

* delete node files

* feat: add production docker compose

* fix: remove DS Store file

* fix: remove DS store file

* feat: add deployment hook

---------

Co-authored-by: zoey-rw <[email protected]>
Co-authored-by: Asad <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 907b080 commit 2e071bd
Show file tree
Hide file tree
Showing 17 changed files with 163,476 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build & Deploy
on:
workflow_dispatch:
push:
paths:
- comets_shinyapp_example/**
branches:
- master
pull_request:
paths:
- comets_shinyapp_example/**
branches:
- master

jobs:
build:
permissions:
pages: write
id-token: write
contents: read
runs-on: ubuntu-latest
defaults:
run:
working-directory: comets_shinyapp_example
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Docker
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: hicsail/comets_shinyapp
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: ./comets_shinyapp_example
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Push to Production
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: fjogeleit/http-request-action@v1
with:
method: "POST"
url: ${{ secrets.PORTAINER_WEBHOOK }}
preventFailureOnNoResponse: true
58 changes: 58 additions & 0 deletions comets_shinyapp_example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Use the official R image as a base
FROM rocker/shiny:4

# Set environment variables to reduce interactive prompts during installation
ENV DEBIAN_FRONTEND=noninteractive

# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
libxml2-dev \
libcairo2-dev \
libsqlite3-dev \
libmariadbd-dev \
libpq-dev \
libssh2-1-dev \
unixodbc-dev \
libcurl4-openssl-dev \
libssl-dev \
libharfbuzz-dev \
libfribidi-dev \
libfreetype6-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev


## update system libraries
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean


# Install necessary R packages
COPY ./renv.lock /renv.lock

RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::restore()'


# Copy the app files into the image
COPY ./app.R /srv/shiny-server/app.R
COPY ./species_abundance_filt.csv /srv/shiny-server/species_abundance_filt.csv
COPY ./organism_data_to_subset.csv /srv/shiny-server/organism_data_to_subset.csv
COPY ./organism_data_to_print.csv /srv/shiny-server/organism_data_to_print.csv
COPY ./nlcd_key.csv /srv/shiny-server/nlcd_key.csv
COPY ./organism_taxonomy.csv /srv/shiny-server/organism_taxonomy.csv

# Set permissions for the shiny-server directory
RUN chown -R shiny:shiny /srv/shiny-server

# Expose the Shiny app port
EXPOSE 3838

# Switch to the 'shiny' user to improve security
USER shiny

# Run the Shiny app
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server', host = '0.0.0.0', port = 3838)"]
21 changes: 21 additions & 0 deletions comets_shinyapp_example/docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.9'

services:
shiny:
image: hicsail/comets_shinyapp:master
container_name: soil_shiny_app
ports:
- "3838:3838"
restart: unless-stopped
postgres:
image: postgres:13
container_name: soil_db
env_file: ../stack.env
ports:
- "3839:5432"
restart: unless-stopped
volumes:
- soil-volume:/var/lib/postgresql/data

volumes:
soil-volume: ~
20 changes: 20 additions & 0 deletions comets_shinyapp_example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.9'

services:
shiny:
build: .
#image: hicsail/comets_shinyapp:master
container_name: shiny_app
ports:
- "3838:3838"
restart: unless-stopped
postgres:
image: postgres:13
container_name: postgres
environment:
POSTGRES_USER: shiny
POSTGRES_PASSWORD: password
POSTGRES_DB: shiny
ports:
- "5432:5432"
restart: unless-stopped
67 changes: 67 additions & 0 deletions comets_shinyapp_example/renv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"R": {
"Version": "4.4.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://mirror.las.iastate.edu/CRAN"
}
]
},
"Packages": {
"shiny": {
"Package": "shiny",
"Version": "1.8.1.1",
"Source": "Repository",
"Repository": "CRAN"
},
"data.table": {
"Package": "data.table",
"Version": "1.16.2",
"Source": "Repository",
"Repository": "CRAN"
},
"tidyverse": {
"Package": "tidyverse",
"Version": "2.0.0",
"Source": "Repository",
"Repository": "CRAN"
},
"DT": {
"Package": "DT",
"Version": "0.33",
"Source": "Repository",
"Repository": "CRAN"
},
"renv": {
"Package": "renv",
"Version": "1.0.11",
"Source": "Repository",
"Repository": "CRAN"
},
"ggplot2": {
"Package": "ggplot2",
"Version": "3.5.1",
"Source": "Repository",
"Repository": "CRAN"
},
"shinydashboard": {
"Package": "shinydashboard",
"Version": "0.7.2",
"Source": "Repository",
"Repository": "CRAN"
},
"shinyhelper": {
"Package": "shinyhelper",
"Version": "0.3.2",
"Source": "Repository",
"Repository": "CRAN"
},
"conflicted": {
"Package": "conflicted",
"Version": "0.1.2",
"Source": "Repository",
"Repository": "CRAN"
}
}
}
16 changes: 16 additions & 0 deletions microbe-sql-compose/data/clean_organism_taxonomy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd

# Load the CSV file
input_file = "organism_taxonomy.csv"
output_file = "cleaned_organism_taxonomy.csv"

# Read the CSV into a DataFrame
df = pd.read_csv(input_file)

# Replace "NA" with None (interpreted as NULL in PostgreSQL)
df.replace("NA", None, inplace=True)

# Save the cleaned DataFrame to a new CSV file
df.to_csv(output_file, index=False)

print(f"Cleaned CSV saved to {output_file}")
16 changes: 16 additions & 0 deletions microbe-sql-compose/data/clean_species_abundance_filt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd

# Input and output file paths
input_file = "species_abundance_filt.csv"
output_file = "cleaned_species_abundance_filt.csv"

# Load the CSV into a pandas DataFrame
df = pd.read_csv(input_file)

# Replace "NA" or any invalid placeholder with None (interpreted as NULL in PostgreSQL)
df.replace("NA", None, inplace=True)

# Save the cleaned DataFrame to a new CSV file
df.to_csv(output_file, index=False)

print(f"Cleaned CSV saved to {output_file}")
Loading

0 comments on commit 2e071bd

Please sign in to comment.