Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
5a63e3ce
Commit
5a63e3ce
authored
9 years ago
by
Gunnar Schaefer
Browse files
Options
Downloads
Patches
Plain Diff
Add config file option and default env vars
parent
bdea9b7c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
api/api.py
+2
-2
2 additions, 2 deletions
api/api.py
api/base.py
+1
-1
1 addition, 1 deletion
api/base.py
api/config.py
+9
-10
9 additions, 10 deletions
api/config.py
dev.ini
+0
-8
0 additions, 8 deletions
dev.ini
run.sh
+83
-33
83 additions, 33 deletions
run.sh
sample.config
+27
-0
27 additions, 0 deletions
sample.config
with
122 additions
and
54 deletions
api/api.py
+
2
−
2
View file @
5a63e3ce
...
...
@@ -124,10 +124,10 @@ def dispatcher(router, request, response):
application
=
webapp2
.
WSGIApplication
(
routes
)
application
.
router
.
set_dispatcher
(
dispatcher
)
if
config
.
get_item
(
'
system
'
,
'
newrelic
'
):
if
config
.
get_item
(
'
core
'
,
'
newrelic
'
):
try
:
import
newrelic.agent
,
newrelic
.
api
.
exceptions
newrelic
.
agent
.
initialize
(
config
.
get_item
(
'
system
'
,
'
newrelic
'
))
newrelic
.
agent
.
initialize
(
config
.
get_item
(
'
core
'
,
'
newrelic
'
))
application
=
newrelic
.
agent
.
WSGIApplicationWrapper
(
application
)
log
.
info
(
'
New Relic detected and loaded. Monitoring enabled.
'
)
except
ImportError
:
...
...
This diff is collapsed.
Click to expand it.
api/base.py
+
1
−
1
View file @
5a63e3ce
...
...
@@ -18,7 +18,7 @@ class RequestHandler(webapp2.RequestHandler):
def
__init__
(
self
,
request
=
None
,
response
=
None
):
self
.
initialize
(
request
,
response
)
self
.
debug
=
config
.
get_item
(
'
system
'
,
'
insecure
'
)
self
.
debug
=
config
.
get_item
(
'
core
'
,
'
insecure
'
)
request_start
=
datetime
.
datetime
.
utcnow
()
provider_avatar
=
None
...
...
This diff is collapsed.
Click to expand it.
api/config.py
+
9
−
10
View file @
5a63e3ce
...
...
@@ -20,8 +20,8 @@ logging.getLogger('paste.httpserver').setLevel(logging.WARNING) # silence Paste
DEFAULT_CONFIG
=
{
'
system
'
:
{
'
log_level
'
:
'
debug
'
,
'
core
'
:
{
'
log_level
'
:
'
info
'
,
'
insecure
'
:
False
,
'
persisted
'
:
False
,
'
newrelic
'
:
None
,
...
...
@@ -44,7 +44,6 @@ DEFAULT_CONFIG = {
},
'
persistent
'
:
{
'
db_uri
'
:
'
mongodb://localhost:9001/scitran
'
,
'
db_path
'
:
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
../persistent/db
'
),
'
data_path
'
:
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
../persistent/data
'
),
},
}
...
...
@@ -90,23 +89,23 @@ db.groups.update_one({'_id': 'unknown'}, {'$setOnInsert': { 'created': now, 'mod
db
.
sites
.
replace_one
({
'
_id
'
:
__config
[
'
site
'
][
'
_id
'
]},
{
'
name
'
:
__config
[
'
site
'
][
'
name
'
],
'
site_url
'
:
__config
[
'
site
'
][
'
url
'
]},
upsert
=
True
)
def
get_config
(
projection
=
None
):
def
get_config
():
global
__last_update
,
__config
,
environment_read
now
=
datetime
.
datetime
.
utcnow
()
if
not
__config
[
'
system
'
][
'
persisted
'
]:
if
not
__config
[
'
core
'
][
'
persisted
'
]:
__config
[
'
modified
'
]
=
now
flat_config
=
util
.
mongo_dict
(
__config
)
r
=
db
.
config
.
update_one
({
'
latest
'
:
True
},
{
'
$set
'
:
flat_config
,
'
$setOnInsert
'
:
{
'
created
'
:
now
}},
upsert
=
True
)
__config
[
'
system
'
][
'
persisted
'
]
=
bool
(
r
.
modified_count
)
__config
[
'
core
'
][
'
persisted
'
]
=
bool
(
r
.
modified_count
)
elif
now
-
__last_update
>
datetime
.
timedelta
(
seconds
=
120
):
__config
=
db
.
config
.
find_one
({
'
latest
'
:
True
}
,
projection
)
__config
=
db
.
config
.
find_one
({
'
latest
'
:
True
})
__last_update
=
now
log
.
setLevel
(
getattr
(
logging
,
__config
[
'
system
'
][
'
log_level
'
].
upper
()))
log
.
setLevel
(
getattr
(
logging
,
__config
[
'
core
'
][
'
log_level
'
].
upper
()))
return
__config
def
get_public_config
():
projection
=
None
# FIXME: define public config whitelist
return
get_
config
(
projection
)
projection
=
[
'
created
'
,
'
modified
'
,
'
site
'
,
'
auth
'
]
return
db
.
config
.
find_one
({
'
latest
'
:
True
},
projection
)
def
get_item
(
outer
,
inner
):
return
get_config
()[
outer
][
inner
]
This diff is collapsed.
Click to expand it.
dev.ini
deleted
100644 → 0
+
0
−
8
View file @
bdea9b7c
[server:main]
use
=
egg:Paste#http
host
=
127.0.0.1
port
=
8080
ssl_pem
=
/Users/gsfr/Applications/localhost.pem
[app:main]
paste.app_factory
=
api.api:app_factory
This diff is collapsed.
Click to expand it.
run.sh
+
83
−
33
View file @
5a63e3ce
...
...
@@ -2,27 +2,54 @@
set
-e
RUNTIME_DIR
=
"./runtime"
PERSITENT_DIR
=
"./persistent"
unset
CDPATH
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
if
[
"$#"
-eq
1
]
;
then
TEMP_ENV_FILE
=
$(
mktemp
-t
scitran_env
)
env
>
$TEMP_ENV_FILE
set
-o
allexport
source
"
$1
"
source
$TEMP_ENV_FILE
rm
-f
$TEMP_ENV_FILE
set
+o allexport
fi
if
[
"$#"
-gt
1
]
;
then
echo
"Usage:
$0
[config file]"
exit
1
fi
if
[
"$#"
-ge
1
]
;
then
PERSITENT_DIR
=
"
$1
"
# Default config values
if
[
-z
"
$SCITRAN_SYSTEM_HOST
"
]
;
then
SCITRAN_SYSTEM_HOST
=
"127.0.0.1"
fi
if
[
"$#"
-eq
2
]
;
then
RUNTIME_DIR
=
"
$2
"
if
[
-z
"
$SCITRAN_SYSTEM_PORT
"
]
;
then
SCITRAN_SYSTEM_PORT
=
"8080
"
fi
if
[
"$#"
-gt
2
]
;
then
echo
"Usage:
$0
persistent runtime"
exit
1
if
[
-z
"
$SCITRAN_SYSTEM_RUNTIME
"
]
;
then
SCITRAN_SYSTEM_RUNTIME
=
"./runtime"
fi
if
[
-z
"
$SCITRAN_SYSTEM_SSL_PEM
"
]
;
then
SCITRAN_SYSTEM_SSL_PEM
=
""
fi
if
[
-z
"
$SCITRAN_PERSISTENT_PATH
"
]
;
then
SCITRAN_PERSISTENT_PATH
=
"./persistent"
fi
if
[
-z
"
$SCITRAN_PERSISTENT_DB_PORT
"
]
;
then
SCITRAN_PERSISTENT_DB_PORT
=
"9001"
fi
if
[
-z
"
$SCITRAN_PERSISTENT_DB_URI
"
]
;
then
SCITRAN_PERSISTENT_DB_URI
=
"mongodb://localhost:
$SCITRAN_PERSISTENT_DB_PORT
/scitran"
fi
if
[
-f
"
$PERSITENT_DIR
/db/mongod.lock"
]
;
then
echo
"Database exists at
$PERSITENT_DIR
/db. Not bootstrapping users."
if
[
-f
"
$SCITRAN_PERSISTENT_PATH
/db/mongod.lock"
]
;
then
BOOTSTRAP_USERS
=
0
else
echo
"Creating database location at
$PERSITENT_
DIR
/db"
mkdir
-p
$PERSITENT_
DIR
/db
echo
"Creating database location at
$
SCITRAN_
PERSI
S
TENT_
PATH
/db"
mkdir
-p
$
SCITRAN_
PERSI
S
TENT_
PATH
/db
if
!
[
-f
"bootstrap.json"
]
;
then
echo
"Cannot bootstrap users. Please create bootstrap.json from bootstrap.json.sample."
exit
1
...
...
@@ -63,32 +90,32 @@ else
echo
"Installed Virtualenv"
fi
if
[
-d
"
$RUNTIME
_DIR
"
]
;
then
echo
"Virtualenv exists present at
$RUNTIME
_DIR
"
if
[
-d
"
$
SCITRAN_SYSTEM_
RUNTIME
"
]
;
then
echo
"Virtualenv exists present at
$
SCITRAN_SYSTEM_
RUNTIME
"
else
echo
"Creating 'scitran' Virtualenv at
$RUNTIME
_DIR
"
virtualenv
-p
`
brew
--prefix
`
/bin/python
--prompt
=
"(scitran)"
$RUNTIME
_DIR
echo
"Created 'scitran' Virtualenv at
$RUNTIME
_DIR
"
echo
"Creating 'scitran' Virtualenv at
$
SCITRAN_SYSTEM_
RUNTIME
"
virtualenv
-p
`
brew
--prefix
`
/bin/python
--prompt
=
"(scitran)"
$
SCITRAN_SYSTEM_
RUNTIME
echo
"Created 'scitran' Virtualenv at
$
SCITRAN_SYSTEM_
RUNTIME
"
fi
if
[
-f
"
$RUNTIME
_DIR
/bin/mongod"
]
;
then
if
[
-f
"
$
SCITRAN_SYSTEM_
RUNTIME
/bin/mongod"
]
;
then
echo
"MongoDB is installed"
else
echo
"Installing MongoDB"
curl https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.7.tgz |
tar
xz
-C
$RUNTIME
_DIR
--strip-components
1
curl https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.7.tgz |
tar
xz
-C
$
SCITRAN_SYSTEM_
RUNTIME
--strip-components
1
echo
"MongoDB installed"
fi
echo
"Activating Virtualenv"
source
$RUNTIME
_DIR
/bin/activate
source
$
SCITRAN_SYSTEM_
RUNTIME
/bin/activate
echo
"Installing Python requirements"
pip
install
-U
-r
requirements.txt
# Launch mongod
mongod
--dbpath
$PERSITENT_
DIR
/db
--smallfiles
--port
9001
&
mongod
--dbpath
$
SCITRAN_
PERSI
S
TENT_
PATH
/db
--smallfiles
--port
$SCITRAN_PERSISTENT_DB_PORT
&
MONGO_PID
=
$!
# Set python path so scripts can work
...
...
@@ -98,28 +125,51 @@ export PYTHONPATH=.
if
[
$BOOTSTRAP_USERS
-eq
1
]
;
then
echo
"Bootstrapping users"
bin/bootstrap.py
users
bootstrap.json
else
echo
"Database exists at
$SCITRAN_PERSISTENT_PATH
/db. Not bootstrapping users."
fi
if
[
!
-d
"
$PERSITENT_DIR
/testdata-master"
]
;
then
echo
"Downloading testdata"
curl https://codeload.github.com/scitran/testdata/tar.gz/master |
tar
xz
-C
$PERSITENT_DIR
TESTDATA_VERSION
=
$(
curl
-sLI
https://github.com/scitran/testdata/archive/master.tar.gz |
grep
ETag |
tail
-n
1 |
cut
-f
2
-d
'"'
)
if
[
!
-d
"
$SCITRAN_PERSISTENT_PATH
/testdata"
]
;
then
echo
"Downloading testdata to
$SCITRAN_PERSISTENT_PATH
/testdata"
mkdir
"
$SCITRAN_PERSISTENT_PATH
/testdata"
curl
-L
https://github.com/scitran/testdata/archive/master.tar.gz |
tar
xz
-C
"
$SCITRAN_PERSISTENT_PATH
/testdata"
--strip-components
1
else
if
[
"
$TESTDATA_VERSION
"
!=
"
$(
cat
$SCITRAN_PERSISTENT_PATH
/.testdata_version
)
"
]
;
then
echo
"Testdata out of data; downloading"
curl
-L
https://github.com/scitran/testdata/archive/master.tar.gz |
tar
xz
-C
"
$SCITRAN_PERSISTENT_PATH
/testdata"
--strip-components
1
else
echo
"Testdata up to date"
fi
fi
echo
"
$TESTDATA_VERSION
"
>
"
$SCITRAN_PERSISTENT_PATH
/.testdata_version"
if
[
-d
"
$PERSITENT_
DIR
/data"
]
;
then
echo
"Persistence store exists at
$PERSITENT_
DIR
/data. Not bootstrapping data. Remove to re-bootstrap."
if
[
-d
"
$
SCITRAN_
PERSI
S
TENT_
PATH
/data"
]
;
then
echo
"Persistence store exists at
$
SCITRAN_
PERSI
S
TENT_
PATH
/data. Not bootstrapping data. Remove to re-bootstrap."
else
echo
"Bootstrapping testdata"
bin/bootstrap.py data
--copy
$PERSITENT_
DIR
/testdata
-master
$
PERSITENT_
DIR
/data
bin/bootstrap.py data
--copy
$
SCITRAN_
PERSI
S
TENT_
PATH
/testdata
$SCITRAN_
PERSI
S
TENT_
PATH
/data
echo
"Bootstrapped testdata"
fi
# Serve API with paste
# python bin/api.wsgi --data_path $PERSITENT_DIR/data --ssl --insecure --log_level debug --drone_secret scitran_drone --db_uri mongodb://localhost/scitran
# Serve API with PasteScript
paster serve dev.ini
--reload
# Exit out of the python virtualenv
TEMP_INI_FILE
=
$(
mktemp
-t
scitran_api
)
cat
<<
EOF
>
$TEMP_INI_FILE
[server:main]
use = egg:Paste#http
host =
$SCITRAN_SYSTEM_HOST
port =
$SCITRAN_SYSTEM_PORT
ssl_pem=
$SCITRAN_SYSTEM_SSL_PEM
[app:main]
paste.app_factory = api.api:app_factory
EOF
paster serve
--reload
$TEMP_INI_FILE
# Clean up and exit out of the python virtualenv
rm
-f
$TEMP_INI_FILE
deactivate
# Shutdown mongod on ctrl+C
...
...
This diff is collapsed.
Click to expand it.
sample.config
0 → 100644
+
27
−
0
View file @
5a63e3ce
# vim: filetype=sh
#SCITRAN_SYSTEM_HOST="127.0.0.1"
#SCITRAN_SYSTEM_PORT="8080"
#SCITRAN_SYSTEM_RUNTIME="./runtime"
#SCITRAN_SYSTEM_SSL_PEM="*"
#SCITRAN_CORE_INSECURE=false
#SCITRAN_CORE_LOG_LEVEL=debug
#SCITRAN_CORE_NEWRELIC=none
#SCITRAN_SITE__ID=""
#SCITRAN_SITE_NAME=""
#SCITRAN_SITE_URL=""
#SCITRAN_SITE_CENTRAL_URL=""
#SCITRAN_SITE_REGISTERED=""
#SCITRAN_SITE_SSL_CERT=""
#SCITRAN_PERSISTENT_PATH="./persistent"
#SCITRAN_PERSISTENT_DB_PORT=9001
#SCITRAN_PERSISTENT_DB_URI="mongodb://localhost:$SCITRAN_PERSISTENT_DB_PORT/scitran"
#SCITRAN_AUTH_AUTH_ENDPOINT=""
#SCITRAN_AUTH_CLIENT_ID=""
#SCITRAN_AUTH_DRONE_SECRET=""
#SCITRAN_AUTH_ID_ENDPOINT=""
#SCITRAN_AUTH_VERIFY_ENDPOINT=""
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment