Skip to content

Commit

Permalink
Merge pull request #16 from acdh-oeaw/15-dockerize
Browse files Browse the repository at this point in the history
Dockerizing the application
  • Loading branch information
csae8092 authored Nov 7, 2023
2 parents e7f7f42 + 3a6f80f commit 11a86f7
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 65 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
myenv
env
/env
db.sqlite3
.env
secret.env
/data
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and publish Docker image

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.11-buster

# install nginx posgtes and gdal
RUN apt-get update -y && apt-get upgrade -y && apt-get install nginx vim \
postgresql-common libpq-dev python3-gdal -y
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

COPY nginx.default /etc/nginx/sites-available/default
# copy source and install dependencies

RUN mkdir -p /opt/app
COPY requirements.txt start-server.sh /opt/app/
RUN pip install -U pip \
&& pip install -r /opt/app/requirements.txt --no-cache-dir \
&& pip install gunicorn --no-cache-dir
COPY . /opt/app
WORKDIR /opt/app
RUN chown -R www-data:www-data /opt/app

# start server
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["/opt/app/start-server.sh"]
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
DEFC-App
=====

About DEFC-App
--------------
# DEFC-App

DEFC stands for Digitizing Early Farming Cultures, a project conducted by the [Austrian Academy of
Sciences](http://www.orea.oeaw.ac.at/go-digital.html). The DEFC-App is an application for curating, exploring, and retrieving archaeological datasets.

Install
-------
## install

* clone the repo
* change into the project's root directory e.g. `cd defc-app`
* create a virtual environment e.g. `virutalenv env` and activate it `source env/bin/activate`
* install required packages `pip install -r requirements_dev.txt`
* run migrations `python manage.py migrate`
* start the dev sever `python manage.py runserver`
* go to [http://127.0.0.1:8000](http://127.0.0.1:8000/) and check if everything works


## Docker

At the ACDH-CH we use a centralized database-server. So instead of spawning a database for each service our services are talking to a database on this centralized db-server. This setup is reflected in the dockerized setting as well, meaning it expects an already existing database (either on your host, e.g. accessible via 'localhost' or some remote one)

### building the image

The DEFC-App is based on [Django 1.8](https://www.djangoproject.com/) and was developed and tested with Python 3.4.
* `docker build -t defc:latest .`
* `docker build -t defc:latest --no-cache .`

1. Clone the repository and check out the master branch which holds the latest stable version.
2. Change to the project´s root directory.
3. Create a virtual environment.
4. Run `pip install -r requirements.txt` to install all required packages.
5. Change directory into `orea/settings/` and adept `dummysettings.py` according to your custom database.
6. Open a terminal, change to the project´s root directory.
7. Run `python manage.py runserver --settings=orea.settings.dummysettings`
8. Open a browser of your choice and enter [http://127.0.0.1:8000/defcdb/](http://127.0.0.1:8000/defcdb/).
9. If everything worked out, you should see something like on this [demo-page](http://defc.eos.arz.oeaw.ac.at/defcdb/)

Import controlled vocabularies
------------------------------
### running the image

On of the main assets of the DEFC-App is its carefully curtated controlled vocabulary which helps keeping the different datasets as homogeneous as possible.
To run the image you should provide an `.env` file to pass in needed environment variables; see example below:

1. more to come....
* `docker run -it -p 8020:8020 --rm --env-file docker.env--name defc defc:latest`
30 changes: 0 additions & 30 deletions Readme.md

This file was deleted.

6 changes: 6 additions & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEBUG=True
POSTGRES_DB=defc
#POSTGRES_USER=postgres
#POSTGRES_PASSWORD=postgres
POSTGRES_HOST=172.17.0.1
#PORT=5432
20 changes: 20 additions & 0 deletions nginx.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 8020;
client_max_body_size 10M;

location /static/ {
autoindex on;
alias /opt/app/staticfiles/;
}

location /media/ {
autoindex on;
alias /opt/app/media/;
}

location / {
proxy_pass http://127.0.0.1:8010;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
5 changes: 3 additions & 2 deletions orea/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@
"exclude": {"auth": ["user"]},
}

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

Expand All @@ -149,4 +147,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles/")
STATIC_URL = "/static/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
MEDIA_URL = "/media/"
14 changes: 2 additions & 12 deletions orea/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
"""
WSGI config for orea project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ["DJANGO_SETTINGS_MODULE"] = "orea.settings.server"
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") #thats the default settings

os.environ["DJANGO_SETTINGS_MODULE"] = "orea.settings"
application = get_wsgi_application()
13 changes: 13 additions & 0 deletions start-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# start-server.sh
echo "Hello from Project DEFC"
python manage.py collectstatic --no-input
if [ -n "$MIGRATE" ] ; then
(echo "making migrations and running them"
python manage.py makemigrations --no-input
python manage.py migrate --no-input)
fi
if [ -n "$DJANGO_SUPERUSER_USERNAME" ] && [ -n "$DJANGO_SUPERUSER_PASSWORD" ] ; then
(echo "creating superuser ${DJANGO_SUPERUSER_USERNAME}" && python manage.py createsuperuser --no-input --noinput --email 'blank@email.com')
fi
gunicorn orea.wsgi --user www-data --bind 0.0.0.0:8010 --workers 3 & nginx -g "daemon off;"

0 comments on commit 11a86f7

Please sign in to comment.