From 1f4c03d9422931032e0618dd921aa1f5516cc50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Code=C3=A7o=20Coelho?= Date: Tue, 6 Oct 2020 09:58:26 -0300 Subject: [PATCH 1/2] Initial configuration for Docker, according to issues #2 and #6 --- .gitignore | 188 ++++++++++++++++++++++++++++++++++++++ Dockerfile-postgis | 5 + Dockerfile_R | 15 +++ docker-compose.yml | 22 +++++ postgis_setup/setup_db.sh | 9 ++ 5 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile-postgis create mode 100644 Dockerfile_R create mode 100644 docker-compose.yml create mode 100644 postgis_setup/setup_db.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf92820 --- /dev/null +++ b/.gitignore @@ -0,0 +1,188 @@ +# Created by .ignore support plugin (hsz.mobi) +### R template +# History files +.Rhistory +.Rapp.history + +# Session Data files +.RData + +# User-specific files +.Ruserdata + +# Example code in package build process +*-Ex.R + +# Output files from R CMD build +/*.tar.gz + +# Output files from R CMD check +/*.Rcheck/ + +# RStudio files +.Rproj.user/ + +# produced vignettes +vignettes/*.html +vignettes/*.pdf + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# knitr and R markdown default cache directories +*_cache/ +/cache/ + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# R Environment Variables +.Renviron + +# pkgdown site +docs/ + +# translation temp files +po/*~ + +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + diff --git a/Dockerfile-postgis b/Dockerfile-postgis new file mode 100644 index 0000000..4dee1cc --- /dev/null +++ b/Dockerfile-postgis @@ -0,0 +1,5 @@ +FROM kartoza/postgis:12.0 + +ADD postgres_setup/* /docker-entrypoint-initdb.d/ +#ADD dev_dumps /dumps +#ADD sql /docker-entrypoint-sql \ No newline at end of file diff --git a/Dockerfile_R b/Dockerfile_R new file mode 100644 index 0000000..64f6c17 --- /dev/null +++ b/Dockerfile_R @@ -0,0 +1,15 @@ +FROM rocker/shiny-verse + +#update all packages +RUN apt-get update + +#upgrade +RUN apt-get upgrade -y + +#install additional packages +RUN apt install gpg-agent -y unixodbc apt-utils curl + + + +#copy app to image +COPY shinyapp/ /srv/shiny-server/second_app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6b15288 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.7" +services: + + R-container: + container_name: R-container + dockerfile: Dockerfile_R + ports: + - "3838:3838" + + Postgresql: + container_name: postgresql + build: + context: "." + dockerfile: "Dockerfile-postgis" + env_file: + - .env_db + ports: + - 5432:5432 + volumes: + - pgdata:/var/lib/postgresql/data + restart: always + diff --git a/postgis_setup/setup_db.sh b/postgis_setup/setup_db.sh new file mode 100644 index 0000000..1f52f78 --- /dev/null +++ b/postgis_setup/setup_db.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#echo -e "\nhost all all all peer\nhost all all 127.0.0.1/32 md5" >> "$PGDATA/pg_hba.conf" +#echo "===> Done editing pg_hba.conf" +set -e +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL + CREATE USER $SHINYAPP_SUPERUSER_USERNAME SUPERUSER PASSWORD '$SHINYAPP_SUPERUSER_PASSWORD'; + CREATE DATABASE shapp WITH OWNER $SHINYAPP_SUPERUSER_USERNAME ENCODING 'utf-8'; + GRANT ALL PRIVILEGES ON DATABASE shapp to $SHINYAPP_SUPERUSER_USERNAME; +EOSQL \ No newline at end of file From 9a557aba8ffdfd065d623a75e93b3255be8584d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Code=C3=A7o=20Coelho?= Date: Tue, 6 Oct 2020 11:07:32 -0300 Subject: [PATCH 2/2] created shinyapp directory so that the container builds. fixed docker-compose.yml --- .env_db | 4 ++++ Dockerfile_R | 2 +- docker-compose.yml | 16 +++++++++++----- shinyapp/README.md | 0 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .env_db create mode 100644 shinyapp/README.md diff --git a/.env_db b/.env_db new file mode 100644 index 0000000..f33d0fe --- /dev/null +++ b/.env_db @@ -0,0 +1,4 @@ +POSTGRES_PASSWORD=postgres +POSTGRES_USER=postgres +SHINYAPP_SUPERUSER_PASSWORD=adminpass +SHINYAPP_SUPERUSER_USERNAME=admin \ No newline at end of file diff --git a/Dockerfile_R b/Dockerfile_R index 64f6c17..2641a77 100644 --- a/Dockerfile_R +++ b/Dockerfile_R @@ -12,4 +12,4 @@ RUN apt install gpg-agent -y unixodbc apt-utils curl #copy app to image -COPY shinyapp/ /srv/shiny-server/second_app \ No newline at end of file +COPY shinyapp/ /srv/shiny-server/shiny_app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6b15288..a53622b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,19 @@ version: "3.7" -services: +volumes: + pgdata: - R-container: - container_name: R-container - dockerfile: Dockerfile_R +services: + r_container: + container_name: r_container + build: + context: "." + dockerfile: Dockerfile_R ports: - "3838:3838" + depends_on: + - postgresql - Postgresql: + postgresql: container_name: postgresql build: context: "." diff --git a/shinyapp/README.md b/shinyapp/README.md new file mode 100644 index 0000000..e69de29