Implement docker
This commit is contained in:
parent
64a89d2a82
commit
39648c17bf
12
Dockerfile
12
Dockerfile
@ -1,11 +1,13 @@
|
||||
FROM alpine:3.8
|
||||
|
||||
RUN apk add --update --no-cache python3 && \
|
||||
pip3 install flask requests && \
|
||||
ADD ["./requirements.txt", "/requirements.txt"]
|
||||
RUN apk add --update --no-cache python3 postgresql-dev py3-psycopg2 && \
|
||||
pip3 install -r /requirements.txt && \
|
||||
rm /requirements.txt && \
|
||||
adduser -D app
|
||||
ADD ["ics_merger.py","/"]
|
||||
ADD ["src","/"]
|
||||
|
||||
CMD ["python3", "-u", "/ics_merger.py"]
|
||||
CMD ["python3", "-u", "/main.py"]
|
||||
|
||||
EXPOSE 8080
|
||||
EXPOSE 5000
|
||||
USER app
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
db_net:
|
||||
external: true
|
||||
|
||||
services:
|
||||
ics_merger:
|
||||
build: .
|
||||
image: docker.wiai.de/fswiai/ics_merger:0.1
|
||||
ports:
|
||||
- 8080:8080
|
||||
codimd_note_overview:
|
||||
build: .
|
||||
image: docker.wiai.de/fswiai/codimd_notes_overview:0.1
|
||||
ports:
|
||||
- 8080:5000
|
||||
networks:
|
||||
- db_net
|
||||
|
||||
27
main.py
27
main.py
@ -1,27 +0,0 @@
|
||||
import psycopg2
|
||||
from flask import Flask, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt" FROM "Notes" ORDER BY "lastchangeAt" DESC;'
|
||||
DB_HOST = '192.168.0.3'
|
||||
DB_Name = 'hackmd'
|
||||
DB_USER = 'hackmd'
|
||||
DB_PASSWORD = 'osHx34e4aDazGsER'
|
||||
CODI_URL = "https://hackmd.wiai.de"
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def main():
|
||||
conn = psycopg2.connect(host=DB_HOST, database=DB_Name, user=DB_USER, password=DB_PASSWORD)
|
||||
cur = conn.cursor()
|
||||
cur.execute(sql_statement)
|
||||
notes = cur.fetchall()
|
||||
cur.close()
|
||||
conn.close()
|
||||
return render_template('index.html', notes=notes, host=CODI_URL)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
26
src/main.py
Normal file
26
src/main.py
Normal file
@ -0,0 +1,26 @@
|
||||
import psycopg2
|
||||
import config
|
||||
from flask import Flask, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt" FROM "Notes" ORDER BY "lastchangeAt" DESC;'
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def main():
|
||||
try:
|
||||
conn = psycopg2.connect(host=config.DB_HOST, database=config.DB_Name, user=config.DB_USER, password=config.DB_PASSWORD)
|
||||
cur = conn.cursor()
|
||||
cur.execute(sql_statement)
|
||||
notes = cur.fetchall()
|
||||
cur.close()
|
||||
conn.close()
|
||||
return render_template('index.html', notes=notes, host=config.CODI_URL)
|
||||
except Exception as e:
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
Loading…
x
Reference in New Issue
Block a user