Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pvk-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
amiv
pvk-tool
Commits
655b4caf
Commit
655b4caf
authored
Mar 17, 2018
by
Alexander Dietmüller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend: Improve configuration for backend container
parent
1eb68f0b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
18 deletions
+47
-18
.gitlab-ci.yml
.gitlab-ci.yml
+1
-1
Backend/Dockerfile
Backend/Dockerfile
+1
-1
Backend/backend/app.py
Backend/backend/app.py
+30
-8
Backend/backend/settings.py
Backend/backend/settings.py
+4
-3
Backend/create_demo_data.py
Backend/create_demo_data.py
+2
-2
Backend/requirements.txt
Backend/requirements.txt
+8
-2
Backend/tests/conftest.py
Backend/tests/conftest.py
+1
-1
No files found.
.gitlab-ci.yml
View file @
655b4caf
...
...
@@ -80,7 +80,7 @@ backend_deploy:
SSH_DEPLOY_KEY
:
$DEPLOY_PRIVATE_KEY
script
:
-
ssh $DEPLOY_HOST "docker pull $CI_REGISTRY_IMAGE_BACKEND; docker service update --force $DEPLOY_SERVICE_BACKEND;"
-
ssh
-4
$DEPLOY_HOST "docker pull $CI_REGISTRY_IMAGE_BACKEND; docker service update --force $DEPLOY_SERVICE_BACKEND;"
only
:
-
master
...
...
Backend/Dockerfile
View file @
655b4caf
...
...
@@ -6,7 +6,7 @@ WORKDIR /pvk
# API will run on port 80
EXPOSE
8080
# Environment variable for config, use path for docker secrets as default
ENV
pvk
_CONFIG=/run/secrets/pvk_config
ENV
PVK
_CONFIG=/run/secrets/pvk_config
# Install bjoern and dependencies for install (we need to keep libev)
RUN
apk add
--no-cache
--virtual
.deps
\
...
...
Backend/backend/app.py
View file @
655b4caf
...
...
@@ -17,7 +17,8 @@ Next, you should check out the following files:
"""
from
os
import
getcwd
from
os
import
getcwd
,
getenv
from
os.path
import
abspath
from
eve
import
Eve
from
flask
import
Config
...
...
@@ -33,19 +34,40 @@ from backend.signups import (
)
def
create_app
(
settings
=
None
):
"""
Super simply bootstrapping for easier test
ing.
def
create_app
(
config_file
=
None
,
**
kwargs
):
"""
Create a new eve app object and initialize everyth
ing.
Initial settings are loaded from settings.py (the Flask `Config` object
makes this easy) and updated settings from the function call, if provided.
User configuration can be loaded in the following order:
1. Use the `config_file` arg to specify a file
2. If `config_file` is `None`, you set the environment variable
`PVK_CONFIG` to the path of your config file
3. If no environment variable is set either, `config.py` in the current
working directory is used
Args:
config (path): Specify config file to use.
kwargs: All other key-value arguments will be used to update the config
Returns:
(Eve): The Eve application
"""
# Load config
config
=
Config
(
getcwd
())
config
.
from_object
(
'backend.settings'
)
if
settings
is
not
None
:
config
.
update
(
settings
)
config
.
from_object
(
"backend.settings"
)
# Specified path > environment var > default path; abspath for better log
user_config
=
abspath
(
config_file
or
getenv
(
'PVK_CONFIG'
,
'config.py'
))
try
:
config
.
from_pyfile
(
user_config
)
config_status
=
"Config loaded: %s"
%
user_config
except
IOError
:
config_status
=
"No config found."
config
.
update
(
kwargs
)
# Create the app object
application
=
Eve
(
auth
=
APIAuth
,
validator
=
APIValidator
,
settings
=
config
)
application
.
logger
.
info
(
config_status
)
# Eve provides hooks at several points of the request,
# we use this do add dynamic filtering
...
...
Backend/backend/settings.py
View file @
655b4caf
...
...
@@ -16,16 +16,17 @@ X_DOMAINS = '*'
X_HEADERS
=
[
'Authorization'
,
'If-Match'
,
'If-Modified-Since'
,
'Content-Type'
]
# AMIVAPI URL and Admin Group
AMIVAPI_URL
=
environ
.
get
(
'AMIVAPI_URL'
,
'https://amiv-api.ethz.ch'
)
ADMIN_GROUP_NAME
=
environ
.
get
(
'AMIVAPI_GROUP'
,
'PVK Admins'
)
AMIVAPI_URL
=
'https://amiv-api.ethz.ch'
ADMIN_GROUP_NAME
=
'PVK Admins'
# DB
# DB
(can be set by env for easier CI tests)
MONGO_HOST
=
environ
.
get
(
'MONGO_HOST'
,
'localhost'
)
MONGO_PORT
=
environ
.
get
(
'MONGO_PORT'
,
27017
)
MONGO_DBNAME
=
environ
.
get
(
'MONGO_DBNAME'
,
'pvk'
)
MONGO_USERNAME
=
environ
.
get
(
'MONGO_USERNAME'
,
'pvkuser'
)
MONGO_PASSWORD
=
environ
.
get
(
'MONGO_PASSWORD'
,
'pvkpass'
)
# Only JSON, simplifies hooks
XML
=
False
...
...
Backend/create_demo_data.py
View file @
655b4caf
...
...
@@ -11,7 +11,7 @@ from datetime import datetime as dt, timedelta
import
requests
AMIVAPI_DEV_URL
=
"https://amiv-api.ethz.ch"
PVK_DEV_URL
=
'http://
localhost:80'
# 'http://
pvk-api-dev.amiv.ethz.ch'
PVK_DEV_URL
=
'http://pvk-api-dev.amiv.ethz.ch'
DATE_FORMAT
=
"%Y-%m-%dT%H:%M:%SZ"
ASSISTANTS
=
[
'pablo'
,
'assi'
,
'anon'
,
'mongo'
]
...
...
@@ -113,7 +113,7 @@ def create_course(lecture, assistant, token, open_signup=True):
'room'
:
next
(
ROOM
),
'spots'
:
randint
(
MIN_SPOTS
,
MAX_SPOTS
),
}
return
post
(
'courses'
,
data
,
token
)
[
'_id'
]
return
post
(
'courses'
,
data
,
token
)
def
create_signups
(
course
,
token
):
...
...
Backend/requirements.txt
View file @
655b4caf
attrs==17.3.0
Cerberus==0.9.2
certifi==2017.11.5
chardet==3.0.4
click==6.7
Eve==0.7.
4
Eve==0.7.
8
Events==0.2.2
Flask==0.12
Flask-PyMongo==0.5.1
...
...
@@ -10,8 +11,13 @@ idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==0.23
pymongo==3.5.1
pluggy==0.6.0
py==1.5.2
pymongo==3.6.1
requests==2.18.4
simplejson==3.13.2
six==1.11.0
tox==2.9.1
urllib3==1.22
virtualenv==15.1.0
Werkzeug==0.11.15
Backend/tests/conftest.py
View file @
655b4caf
...
...
@@ -127,7 +127,7 @@ def admin(self, **kwargs):
@
pytest
.
fixture
def
app
():
"""Create app, instantiate test client, drop DB after use."""
application
=
create_app
(
settings
=
TEST_SETTINGS
)
application
=
create_app
(
**
TEST_SETTINGS
)
application
.
test_client_class
=
TestClient
application
.
client
=
application
.
test_client
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment