intial dockerization
This commit is contained in:
parent
0e2aef1941
commit
abdcd45057
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
todo
|
||||
env
|
||||
__pycache__
|
||||
redis-data
|
||||
|
29
docker-compose.yml
Normal file
29
docker-compose.yml
Normal file
@ -0,0 +1,29 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
web:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./web/Dockerfile
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8464:80
|
||||
environment:
|
||||
- CLIENT_ID=${CLIENT_ID}
|
||||
- CLIENT_SECRET=${CLIENT_SECRET}
|
||||
- BASE_URL=http://localhost:8464
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- './redis-data:/data'
|
||||
|
||||
populater:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./populater/Dockerfile
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- CLIENT_ID=${CLIENT_ID}
|
||||
- CLIENT_SECRET=${CLIENT_SECRET}
|
11
populater/Dockerfile
Normal file
11
populater/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM python:3
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY populater/requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY populater/src .
|
||||
ADD common ./common
|
||||
|
||||
CMD [ "python", "-u", "app.py" ]
|
@ -3,6 +3,7 @@ certifi==2022.12.7
|
||||
charset-normalizer==2.1.1
|
||||
click==8.1.3
|
||||
Flask==2.2.2
|
||||
gunicorn==20.1.0
|
||||
idna==3.4
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.2
|
@ -16,7 +16,7 @@ CLIENT_SECRET = os.environ.get('CLIENT_SECRET', None)
|
||||
if CLIENT_SECRET is None:
|
||||
raise ValueError("CLIENT_SECRET cannot be None, set using environment variable")
|
||||
|
||||
db = Db('localhost', 6379, 0, CLIENT_ID, CLIENT_SECRET)
|
||||
db = Db('redis', 6379, 0, CLIENT_ID, CLIENT_SECRET)
|
||||
|
||||
|
||||
def get_args():
|
||||
|
@ -1 +0,0 @@
|
||||
../../common/
|
15
web/Dockerfile
Normal file
15
web/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
FROM python:3
|
||||
|
||||
ENV PYTHONUNBUFFERED=value
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY web/requirements.txt ./
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY web/src .
|
||||
|
||||
ADD common ./common
|
||||
|
||||
CMD [ "gunicorn", "-b 0.0.0.0:80", "app:app" ]
|
15
web/requirements.txt
Normal file
15
web/requirements.txt
Normal file
@ -0,0 +1,15 @@
|
||||
async-timeout==4.0.2
|
||||
certifi==2022.12.7
|
||||
charset-normalizer==2.1.1
|
||||
click==8.1.3
|
||||
Flask==2.2.2
|
||||
gunicorn==20.1.0
|
||||
idna==3.4
|
||||
itsdangerous==2.1.2
|
||||
Jinja2==3.1.2
|
||||
MarkupSafe==2.1.1
|
||||
redis==4.4.0
|
||||
requests==2.28.1
|
||||
six==1.16.0
|
||||
urllib3==1.26.13
|
||||
Werkzeug==2.2.2
|
@ -23,7 +23,11 @@ CLIENT_SECRET = os.environ.get('CLIENT_SECRET', None)
|
||||
if CLIENT_SECRET is None:
|
||||
raise ValueError("CLIENT_SECRET cannot be None, set using environment variable")
|
||||
|
||||
db = Db('localhost', 6379, 0, CLIENT_ID, CLIENT_SECRET)
|
||||
BASE_URL = os.environ.get('BASE_URL', None)
|
||||
if BASE_URL is None:
|
||||
raise ValueError("BASE_URL cannot be None, set using environtment variable")
|
||||
|
||||
db = Db('redis', 6379, 0, CLIENT_ID, CLIENT_SECRET)
|
||||
|
||||
SPOTIFY_AUTHORIZE_ENDPOINT = os.environ.get('SPOTIFY_AUTHORIZE_ENDPOINT', 'https://accounts.spotify.com/authorize?')
|
||||
SPOTIFY_TOKEN_ENDPOINT = os.environ.get('SPOTIFY_AUTHORIZE_ENDPOINT', 'https://accounts.spotify.com/api/token')
|
||||
@ -60,9 +64,10 @@ def index():
|
||||
loginurl = SPOTIFY_AUTHORIZE_ENDPOINT + urllib.parse.urlencode({
|
||||
'client_id': CLIENT_ID,
|
||||
'scope': SCOPES,
|
||||
'redirect_uri': 'http://localhost:5000' + url_for('cb'),
|
||||
'redirect_uri': BASE_URL + url_for('cb'),
|
||||
'response_type': 'code'
|
||||
})
|
||||
}),
|
||||
message = { 'type':'', 'text': ''}
|
||||
))
|
||||
resp.set_cookie(
|
||||
'user_secret',
|
||||
@ -130,7 +135,7 @@ def cb():
|
||||
data = {
|
||||
'code': spotify_code,
|
||||
'grant_type': 'authorization_code',
|
||||
'redirect_uri': 'http://localhost:5000' + url_for('cb'),
|
||||
'redirect_uri': BASE_URL+ url_for('cb'),
|
||||
}
|
||||
headers = {
|
||||
'Authorization': f'Basic {authstring}',
|
||||
@ -139,6 +144,7 @@ def cb():
|
||||
|
||||
token_rq = rq.post(f"{SPOTIFY_TOKEN_ENDPOINT}", data = data, headers = headers)
|
||||
if token_rq.status_code != rq.codes.ok:
|
||||
print(f"getting token failed {token_rq.text=}")
|
||||
return render_template("index_authorised.html", message={
|
||||
'type': 'error',
|
||||
'text': f"unable to authenticate with spotify. please try again later."
|
||||
@ -151,6 +157,7 @@ def cb():
|
||||
|
||||
me_rq = rq.get(f"{SPOTIFY_API_ENDPOINT}/me", headers = { 'Authorization': f"Bearer {spotify_token}" })
|
||||
if me_rq.status_code != 200:
|
||||
print(f"getting user info failed {me_rq.text=}")
|
||||
return render_template("index_authorised.html", message={
|
||||
'type': 'error',
|
||||
'text': f"unable to authenticate with spotify. please try again later."
|
||||
|
@ -1 +0,0 @@
|
||||
../../common/
|
Loading…
Reference in New Issue
Block a user