aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile15
-rw-r--r--docker-compose.yml34
-rw-r--r--instance/production.py8
-rwxr-xr-xmanager.py7
-rwxr-xr-xwait-for-postgres.sh19
5 files changed, 57 insertions, 26 deletions
diff --git a/Dockerfile b/Dockerfile
index 5d11830c..e8e39ec5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,10 +10,8 @@ RUN apk update && \
libxml2-dev \
libxslt-dev \
libpq \
+ postgresql-client \
postgresql-dev \
- sqlite-dev \
- sqlite \
- sqlite-libs \
npm
RUN pip install poetry
@@ -27,16 +25,11 @@ COPY package.json .
COPY package-lock.json .
COPY pyproject.toml .
COPY poetry.lock .
-COPY instance/sqlite.py .
-COPY instance/sqlite.py instance/
-COPY instance/sqlite.py newspipe/
+COPY wait-for-postgres.sh .
+
+RUN chmod +x ./wait-for-postgres.sh
RUN npm install
COPY node_modules newspipe/static/npm_components
-ENV Newspipe_CONFIG sqlite.py
-
RUN poetry install
-RUN poetry run pybabel compile -d newspipe/translations
-RUN poetry run ./manager.py db_create
-RUN poetry run ./manager.py create_admin admin password
diff --git a/docker-compose.yml b/docker-compose.yml
index eee5ef32..1c176d01 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,18 +1,34 @@
version: '3'
services:
+ db:
+ image: postgres:latest
+ hostname: db
+ restart: always
+ environment:
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=password
+ - POSTGRES_DB=postgres
+ ports:
+ - '5432:5432'
+ expose:
+ - '5432'
+ volumes:
+ - ./docker/postgres/data:/var/lib/postgresql/data
+
newspipe:
- build: .
+ build:
+ context: .
+ dockerfile: ./Dockerfile
tty: true
environment:
- - Newspipe_CONFIG=/newspipe/instance/sqlite.py
- command:
- - /bin/sh
- - -c
- - |
- poetry run pybabel compile -d newspipe/translations
- poetry run ./runserver.py
+ - Newspipe_CONFIG=/newspipe/instance/production.py
volumes:
- - .:/newspipe
+ - .:/newspipe:rw
ports:
- "5000:5000"
+ expose:
+ - '5000'
+ depends_on:
+ - db
+ command: "./wait-for-postgres.sh db"
diff --git a/instance/production.py b/instance/production.py
index d57520b8..d0aebd7e 100644
--- a/instance/production.py
+++ b/instance/production.py
@@ -5,7 +5,7 @@ import os
#
# Webserver
-HOST = "127.0.0.1"
+HOST = "0.0.0.0"
PORT = 5000
DEBUG = False
API_ROOT = "/api/v2.0"
@@ -16,12 +16,12 @@ SECURITY_PASSWORD_SALT = "L8gTsyrpRQEF8jNWQPyvRfv7U5kJkD"
# Database
DB_CONFIG_DICT = {
- "user": "user",
+ "user": "postgres",
"password": "password",
- "host": "localhost",
+ "host": "db",
"port": 5432,
}
-DATABASE_NAME = "newspipe"
+DATABASE_NAME = "postgres"
SQLALCHEMY_DATABASE_URI = "postgres://{user}:{password}@{host}:{port}/{name}".format(
name=DATABASE_NAME, **DB_CONFIG_DICT
)
diff --git a/manager.py b/manager.py
index 2ecdeffc..fcb5d0c5 100755
--- a/manager.py
+++ b/manager.py
@@ -39,8 +39,11 @@ def db_create():
"pwdhash": generate_password_hash(os.environ.get("ADMIN_PASSWORD", "password")),
}
with application.app_context():
- db.create_all()
- UserController(ignore_context=True).create(**admin)
+ try:
+ db.create_all()
+ UserController(ignore_context=True).create(**admin)
+ except Exception as e:
+ print(e)
@manager.command
diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh
new file mode 100755
index 00000000..4cace9bd
--- /dev/null
+++ b/wait-for-postgres.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Used for Docker.
+
+set -e
+
+shift
+
+until (! command -v psql || PGPASSWORD=password psql -h db -U "postgres" -c '\q' )
+do
+ >&2 echo "Postgres is unavailable - sleeping"
+ sleep 1
+done
+
+>&2 echo "Postgres is up - executing command"
+export Newspipe_CONFIG=/newspipe/instance/production.py
+poetry run ./manager.py db_create
+poetry run pybabel compile -d newspipe/translations
+poetry run ./runserver.py
bgstack15