Skip to content

Commit

Permalink
remove db - moved db to sales-db repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmdlt committed Nov 23, 2023
1 parent ef5a4f2 commit 7147537
Show file tree
Hide file tree
Showing 28 changed files with 60 additions and 415,626 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: main

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: docker/setup-buildx-action@v2

- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- uses: docker/build-push-action@v2
with:
context: .
push: true
cache-from: hexletcomponents/data-charts-api:latest
cache-to: type=inline
tags: hexletcomponents/data-charts-api:latest
18 changes: 7 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
FROM postgres:latest
FROM python:slim

WORKDIR /scripts
RUN apt-get update && apt-get install -yqq make
RUN pip install poetry
ENV POETRY_VIRTUALENVS_IN_PROJECT=true

COPY db/data_generator/data /scripts/data
COPY setup_user.sql /scripts/
COPY scripts/ /scripts/db


RUN cat /scripts/db/*.sql > /tmp/chartsdb.sql

RUN echo "createdb chartsdb" >> /docker-entrypoint-initdb.d/run.sh
RUN echo "psql -d chartsdb -U postgres -f /tmp/chartsdb.sql" >> /docker-entrypoint-initdb.d/run.sh
RUN echo "psql -d chartsdb -U postgres -f /scripts/setup_user.sql" >> /docker-entrypoint-initdb.d/run.sh
WORKDIR /app
COPY . .
RUN poetry install
29 changes: 11 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
dev:
poetry run flask --app app.server run --debug -h 0.0.0.0 -p 3000

run:
poetry run gunicorn -w 4 -b 0.0.0.0:3000 app.server:app

start:
make stop rm || true
docker run -it \
-p 5432:5432 \
-e POSTGRES_PASSWORD=password \
--name data-chartsdb \
data-chartsdb
docker run -p 3000:3000 app-chartsdb make run

build:
docker build . -t data-chartsdb
docker build . -t app-chartsdb

stop:
docker stop data-chartsdb
docker stop app-chartsdb

rm:
docker rm data-chartsdb
docker rm app-chartsdb

bash:
docker run --rm -it data-chartsdb bash

compose:
docker compose up

compose-build:
docker compose build

compose-down:
docker compose down -v --remove-orphans
docker run --rm -it app-chartsdb bash
10 changes: 0 additions & 10 deletions api/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions api/Makefile

This file was deleted.

19 changes: 14 additions & 5 deletions api/app/server.py → app/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import Flask, request
from datetime import datetime
import logging
import traceback
import os
import psycopg

Expand All @@ -24,9 +26,12 @@ def index():
@app.get('/visits')
def get_visits():
query = request.args
print(app.config['DATABASE_URL'])
begin_date = datetime.fromisoformat(query['begin'])
end_date = datetime.fromisoformat(query['end'])
try:
begin_date = datetime.fromisoformat(query['begin'])
end_date = datetime.fromisoformat(query['end'])
except ValueError as e:
logging.error(traceback.format_exc(2, chain=False))
return 'Invalid date. Please check your input', 400
query = '''
SELECT *
FROM visits
Expand All @@ -41,8 +46,12 @@ def get_visits():
@app.get('/registrations')
def get_registrations():
query = request.args
begin_date = datetime.fromisoformat(query['begin'])
end_date = datetime.fromisoformat(query['end'])
try:
begin_date = datetime.fromisoformat(query['begin'])
end_date = datetime.fromisoformat(query['end'])
except ValueError as e:
logging.error(traceback.format_exc(2, chain=False))
return 'Invalid date. Please check your input', 400
query = '''
SELECT *
FROM registrations
Expand Down
2 changes: 0 additions & 2 deletions db/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion db/data_generator/data/ad_campaigns.json

This file was deleted.

180 changes: 0 additions & 180 deletions db/data_generator/data/ads.csv

This file was deleted.

Loading

0 comments on commit 7147537

Please sign in to comment.