diff --git a/.devcontainer/Dockerfile.website b/.devcontainer/Dockerfile.website new file mode 100644 index 0000000..e0c98f1 --- /dev/null +++ b/.devcontainer/Dockerfile.website @@ -0,0 +1,26 @@ +FROM python:latest +WORKDIR /home/plakplaats + +# Install build dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libpq-dev gcc +RUN rm -rf /var/lib/apt/lists/* + +# Install required python packages +COPY requirements.txt ./ +RUN pip install -r requirements.txt --no-cache-dir + +# Copy over remaining files +COPY . . + +# Document which ports will be used +EXPOSE 3000 + +# Give a warm welcome +ENV SHELL="/bin/bash" +RUN echo "echo 'You are in the plakplaats devcontainer!'" >> /etc/bash.bashrc +RUN echo "echo 'Start the server with: python src/server.py'" >> /etc/bash.bashrc + +# Do not run anything, but do not close the container either +CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4c0ad61 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,18 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Plakplaats devcontainer", + "workspaceFolder": "/home/plakplaats", + "dockerComposeFile": "docker-compose.yml", + "service": "website-dev", + "forwardPorts": [3000], + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-azuretools.vscode-docker" + ] + } + }, + "runServices": ["website-dev"] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..6226bcf --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,14 @@ +# Inherit but overwrite production configs with development configs + +include: + - path: ../docker-compose.yml + +services: + website-dev: + build: + context: .. + dockerfile: .devcontainer/Dockerfile.website + ports: + - "3000:3000" + depends_on: + - postgres_db \ No newline at end of file diff --git a/.gitignore b/.gitignore index 11b0027..969149c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,88 +1,6 @@ .env -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -# .NET -obj/ -bin/ - # Ignore user uploads uploads/ -__pycache__ \ No newline at end of file +__pycache__ diff --git a/Dockerfile.website b/Dockerfile.website new file mode 100644 index 0000000..9bb027e --- /dev/null +++ b/Dockerfile.website @@ -0,0 +1,21 @@ +FROM python:alpine +WORKDIR /home/plakplaats + +# Install build dependencies +RUN apk add --no-cache postgresql-libs +RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev + +# Copy the files responsible for listing dependencies +COPY requirements.txt ./ + +# Cache the python dependencies +RUN python3 -m pip install -r requirements.txt --no-cache-dir + +# Remove previously installed build dependencies, they are not needed anymore +RUN apk del .build-deps + +# Copy the source code +COPY src src + +EXPOSE 3000 +CMD ["python", "src/server.py"] diff --git a/dependencies.md b/dependencies.md deleted file mode 100644 index db31da1..0000000 --- a/dependencies.md +++ /dev/null @@ -1,2 +0,0 @@ - - flask (`pip install flask`) - - waitress (`pip install waitress`) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3fa45f8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + website: + build: + dockerfile: Dockerfile.website + ports: + - "3000:3000" + depends_on: + - postgres_db + + postgres_db: + image: postgres:latest + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: plakplaats-db + ports: + - "5432:5432" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7728920 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +flask +waitress +requests +psycopg2 +python-dotenv diff --git a/server.py b/server.py index 2890799..6817277 100644 --- a/server.py +++ b/server.py @@ -416,4 +416,4 @@ def checkFileName(name): # only runs when executed as script, not when used as module if __name__ == "__main__": from waitress import serve - serve(app, host='0.0.0.0', port='7050') + serve(app, host='0.0.0.0', port='3000')