-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from acdh-oeaw/15-dockerize
Dockerizing the application
- Loading branch information
Showing
10 changed files
with
143 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
myenv | ||
env | ||
/env | ||
db.sqlite3 | ||
.env | ||
secret.env | ||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;" |