Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.122.1/containers/python-3
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
// Update 'VARIANT' to pick a Python version. Rebuild the container
// if it already exists to update. Available variants: 3, 3.6, 3.7, 3.8
"args": {
"VARIANT": "3"
}
},
"name": "Existing Docker Compose (Extend)",
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "dash",
// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspace",
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
Expand All @@ -33,14 +37,15 @@
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker"
],
]
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8888,
8050
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r requirements.txt",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
// "forwardPorts": [],
// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "appuser"
}
38 changes: 38 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.4'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
dash:
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
# debugging) to execute as the user. Uncomment the next line if you want the entire
# container to run as this user instead. Note that, on Linux, you may need to
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
# user: vscode

# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/workspace:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"

9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ FROM python:3.8-slim-buster
EXPOSE 8000

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# ENV PYTHONUNBUFFERED=1

# Install pip requirements
# ADD requirements.txt .
Expand All @@ -18,8 +18,9 @@ ADD . /app
RUN pip install -r requirements.txt

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser
# RUN useradd appuser && chown -R appuser /app
# USER appuser
# ENV HOME /home/appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["run-transmonee_dashboard-dev"]
14 changes: 14 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.4'

services:
dash:
image: dash
build:
context: .
dockerfile: ./Dockerfile
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 8000"]
ports:
- 8000:8000
- 5678:5678
environment:
- FLASK_APP=transmonee_dashboard/src/transmonee_dashboard/app.py
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.4'

services:
dash:
image: dash
build:
context: .
dockerfile: ./Dockerfile
env_file:
- .env
ports:
- 8000:8000

redis:
image: redis
container_name: redis-container
ports:
- "6379:6379"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ uritemplate==3.0.1
urllib3==1.26.5
wcwidth==0.2.5
Werkzeug==1.0.1
redis

sentry-sdk[flask]
6 changes: 1 addition & 5 deletions transmonee_dashboard/src/transmonee_dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
app = create_dash(server)

# define a cache instance
# TODO: Move configuration to settings
# TODO: for prod move to redis or similar
cache = Cache(
app.server, config={"CACHE_TYPE": "filesystem", "CACHE_DIR": "cache-directory"}
)
cache = Cache(app.server)


# Push an application context so we can use Flask's 'current_app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def get_base_layout(**kwargs):
kwargs.get("hash")
if kwargs.get("hash")
else "#{}".format((next(iter(indicators_dict.items())))[0].lower())
# else "#{}".format(next(iter(indicators_dict.values()))["NAME"].lower())
)

return html.Div(
Expand Down Expand Up @@ -641,7 +640,6 @@ def indicator_card(
)
else "None"
)
print(name)
card = dbc.Card(
[
dbc.CardBody(
Expand Down Expand Up @@ -699,7 +697,6 @@ def get_card_popover_body(sources):
for index, source_info in enumerate(sources):
countries.append(f"- {source_info[0]}: {source_info[1]}")
card_countries = "\n".join(countries)
print(card_countries)
return card_countries


Expand Down
9 changes: 9 additions & 0 deletions transmonee_dashboard/src/transmonee_dashboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Flask instance used by the Dash app. Any values corresponding to Dash
# keword arguments will be passed They must be in UPPER CASE in order to take effect. For more information see
# http://flask.pocoo.org/docs/config.
import os

# Your App's title. The value of this parameter will be propagated into
# `app.title`
Expand Down Expand Up @@ -61,3 +62,11 @@

# The ID of the element used to inject the navbar items into
NAVBAR_CONTAINER_ID = "navbar-items"

# CACHE settings
CACHE_TYPE = os.environ.get("CACHE_TYPE")
CACHE_REDIS_HOST = os.environ.get("CACHE_REDIS_HOST")
CACHE_REDIS_PORT = os.environ.get("CACHE_REDIS_PORT")
CACHE_REDIS_DB = os.environ("CACHE_REDIS_DB")
CACHE_REDIS_URL = os.environ("CACHE_REDIS_URL")
CACHE_DEFAULT_TIMEOUT = os.environ("CACHE_DEFAULT_TIMEOUT")