From aeb7c490687551347e743e3be64c30085537b5e9 Mon Sep 17 00:00:00 2001 From: Chris Kiriakou Date: Fri, 21 Mar 2025 19:07:30 +0100 Subject: [PATCH] Create improved Dockerfile with volume mounts for storing data * Add volume mounts to Dockerfile to enable persisten storing of database and tokens when using docker * Makefile helps with cleanup and building the Dockerfile * Startup fires the predictify runtime inside the container * `.dockerignore` contains files that are not needed by the docker, e.g. files that would otherwise slow build process down --- .dockerignore | 11 +++++++++++ Makefile | 19 +++++++++++++++++++ docker/Dockerfile | 35 +++++++++++++++++++++++++++++++++++ docker/startup.sh | 5 +++++ 4 files changed, 70 insertions(+) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 docker/Dockerfile create mode 100755 docker/startup.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..99bd07d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +logs/ +data/ +src/__pycache__/ +.git +*.md +.venv +LICENSE +MAKEFILE +pytest.ini +test/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89a5710 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: all dockerfile clean + +TAG="unstable" +PROJ_NAME="predictify" + +all: install dockerfile + +install: + mkdir -p ./data + +dockerfile: ./docker/Dockerfile + docker build \ + --tag "$(PROJ_NAME):$(TAG)" \ + --build-arg PROJ_NAME=$(PROJ_NAME) \ + --file ./docker/Dockerfile \ + . + +clean: ./spotify_scraped.db + rm -r ./data/spotify_scraped.db diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..5e86c2c --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,35 @@ +FROM alpine:3.21.3 + +# Set environment variables +ARG PROJ_NAME +ENV PROJ_NAME=${PROJ_NAME} + +RUN mkdir -p /app/${PROJ_NAME} + +# The following steps are executed from the specified directory below +WORKDIR /app/${PROJ_NAME} + +# Install all necessary software +RUN apk add --no-cache python3 sqlite + +# Create the directories, needed for persistent storage (e.g. database, tokens) +RUN mkdir ./data ./src ./config + +# Create mount points for logs, data, src and config +VOLUME /var/log ./data ./src ./config + +# Copy the application source code +COPY ./src/ ./src/ + +# Create a seperate venv inside the container & install requirements +COPY ./requirements.txt ./requirements.txt +RUN \ + python -m venv .venv && \ + source .venv/bin/activate && \ + ./.venv/bin/pip install -r ./requirements.txt && \ + deactivate + +COPY ./docker/startup.sh ./startup.sh + +# When starting the contianer the following is executed +ENTRYPOINT ["./startup.sh"] diff --git a/docker/startup.sh b/docker/startup.sh new file mode 100755 index 0000000..f6092ad --- /dev/null +++ b/docker/startup.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# +# Startup predictify. Don't use this. This is for docker specifically. +source .venv/bin/activate +.venv/bin/python src/runtime.py