diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b981332 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git/ +.github/ +.idea/ + +.gitignore \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..f5b1510 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,34 @@ +name: Docker Image CI + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: deployment/Dockerfile + push: true + tags: pearsproject/pears-federated:latest + + - name: Image digest + run: echo ${{ steps.build.outputs.digest }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5867f29 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.DEFAULT_GOAL: help +SHELL := /bin/bash + +PROJECTNAME := "pears-federated" + +.PHONY: help +all: help +help: Makefile + @echo + @echo " Choose a command to run in "$(PROJECTNAME)":" + @echo + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' + @echo note: call scripts from /scripts + +check-%: # detection of required software. + @which ${*} > /dev/null || (echo '*** Please install `${*}` ***' && exit 1) + +## build: Build the container image +build: check-docker + @docker buildx build --no-cache --pull -f deployment/Dockerfile -t ${PROJECTNAME}:local-build . \ No newline at end of file diff --git a/app/indexer/posix.py b/app/indexer/posix.py index 1f9cee6..4ebc146 100644 --- a/app/indexer/posix.py +++ b/app/indexer/posix.py @@ -8,13 +8,13 @@ pod_dir = getenv("PODS_DIR", join(dir_path, 'pods')) def load_posix(contributor, lang, theme): - posix_path = join(dir_path, 'pods', contributor, lang) + posix_path = join(pod_dir, contributor, lang) pod_name = theme+'.u.'+contributor posix = joblib.load(join(posix_path,pod_name+'.pos')) return posix def dump_posix(posindex, contributor, lang, theme): - posix_path = join(dir_path, 'pods', contributor, lang) + posix_path = join(pod_dir, contributor, lang) pod_name = theme+'.u.'+contributor joblib.dump(posindex, join(posix_path,pod_name+'.pos')) diff --git a/app/orchard/mk_urls_file.py b/app/orchard/mk_urls_file.py index 1564859..dab8b83 100644 --- a/app/orchard/mk_urls_file.py +++ b/app/orchard/mk_urls_file.py @@ -14,7 +14,7 @@ def get_url_list_for_users(theme): urls = [] url_theme = theme.replace(' ', '_') - hfile = join(pods_dir, url_theme + ".pears.txt") + hfile = join(pod_dir, url_theme + ".pears.txt") f_out = open(hfile,'w', encoding='utf-8') for url in Urls.query.filter(Urls.pod.contains(theme+'.u.')).all(): if not url.pod.startswith(theme+'.u.'): diff --git a/deployment/Dockerfile b/deployment/Dockerfile new file mode 100644 index 0000000..1f32311 --- /dev/null +++ b/deployment/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.9-slim + +WORKDIR /app + +COPY requirements.txt /tmp/ +RUN pip install --requirement /tmp/requirements.txt + +# Additionally, install Gunicorn +RUN pip install gunicorn + +# Make port 8000 available to the world outside this container +EXPOSE 8000 + +ENV SQLALCHEMY_DATABASE_URI="sqlite:////var/lib/pears/data/app.db" +ENV LOGO_PATH="/var/lib/pears/data" +ENV PODS_DIR="/var/lib/pears/data/pods" +ENV SUGGESTIONS_DIR="/var/lib/pears/data/userdata" + +RUN mkdir -p /var/lib/pears/data/pod /var/lib/pears/data/userdata + +COPY . /app + +RUN chmod +x /app/deployment/entrypoint.sh + +# Set the entrypoint script to be executed +ENTRYPOINT ["/app/deployment/entrypoint.sh"] \ No newline at end of file diff --git a/deployment/entrypoint.sh b/deployment/entrypoint.sh new file mode 100644 index 0000000..c36018d --- /dev/null +++ b/deployment/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# entrypoint.sh + +flask db migrate + +gunicorn -b 0.0.0.0:8000 -w 3 -t 120 app:app \ No newline at end of file