diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f791a79 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +myenv +env +/env +db.sqlite3 +.env +secret.env +/data \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8f8ca38 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..90c9dfd --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index b16d335..d554eac 100644 --- a/README.md +++ b/README.md @@ -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.... \ No newline at end of file +* `docker run -it -p 8020:8020 --rm --env-file docker.env--name defc defc:latest` \ No newline at end of file diff --git a/Readme.md b/Readme.md deleted file mode 100644 index b16d335..0000000 --- a/Readme.md +++ /dev/null @@ -1,30 +0,0 @@ -DEFC-App -===== - -About 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 -------- - -The DEFC-App is based on [Django 1.8](https://www.djangoproject.com/) and was developed and tested with Python 3.4. - -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 ------------------------------- - -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. - -1. more to come.... \ No newline at end of file diff --git a/docker.env b/docker.env new file mode 100644 index 0000000..d0410b5 --- /dev/null +++ b/docker.env @@ -0,0 +1,6 @@ +DEBUG=True +POSTGRES_DB=defc +#POSTGRES_USER=postgres +#POSTGRES_PASSWORD=postgres +POSTGRES_HOST=172.17.0.1 +#PORT=5432 \ No newline at end of file diff --git a/nginx.default b/nginx.default new file mode 100644 index 0000000..b9ae7e2 --- /dev/null +++ b/nginx.default @@ -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; + } +} diff --git a/orea/settings.py b/orea/settings.py index 5ddb76a..2059c77 100644 --- a/orea/settings.py +++ b/orea/settings.py @@ -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/ @@ -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/" diff --git a/orea/wsgi.py b/orea/wsgi.py index 7c27e6a..b37c8b6 100644 --- a/orea/wsgi.py +++ b/orea/wsgi.py @@ -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() diff --git a/start-server.sh b/start-server.sh new file mode 100755 index 0000000..b6c2708 --- /dev/null +++ b/start-server.sh @@ -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;"