Skip to content

Commit

Permalink
Merge branch 'master' into release/v22.06
Browse files Browse the repository at this point in the history
  • Loading branch information
ateska committed Mar 5, 2023
2 parents c9d539b + f650ba1 commit fc748e5
Show file tree
Hide file tree
Showing 45 changed files with 1,619 additions and 717 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
test/test_api_docs/testfiles

# Translations
*.mo
Expand Down
38 changes: 21 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ Contributions are welcome!
Installation
------------

``pip install asab``

.. code:: shell
$ pip install asab
Documentation
Expand All @@ -42,36 +45,37 @@ Example
.. code:: python
#!/usr/bin/env python3
import asab
import asab.web
import aiohttp
import asab.web.rest
class MyApplication(asab.Application):
def __init__(self):
# Load the ASAB Web module
super().__init__(modules=[asab.web.Module])
# Locate the Web service
websvc = self.get_service("asab.WebService")
# Create the Web container
container = asab.web.WebContainer(websvc, 'my:web', config={"listen": "0.0.0.0:8080"})
# Add a route to the handler
container.WebApp.router.add_get('/', self.hello)
super().__init__()
# Create the Web server
web = asab.web.create_web_server(self)
# Add a route to the handler method
web.add_get('/hello', self.hello)
# This is the web request handler
async def hello(self, request):
return aiohttp.web.Response(text="Hello, world!\n")
return asab.web.rest.json_response(request, data="Hello, world!\n")
if __name__ == '__main__':
# Create and start the application
# The application will be available at http://localhost:8080/
app = MyApplication()
app.run()
The application is available at http://localhost:8080/.
You can test it by:


.. code:: shell
$ curl http://localhost:8080/hello
Microservices
-------------
Expand Down
47 changes: 45 additions & 2 deletions asab-manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import os
import sys
import json
import argparse
Expand All @@ -12,13 +13,50 @@
of docker image. When the MANIFEST.json is populated it could look something similar to illustration below
when generated the help of the current script.
```
{
'created_at': 2022-03-21T15:49:37.14000,
'version' :v22.9-4
"created_at": "2022-03-21T15:49:37.14000",
"version": "v22.04"
}
```
If GitLab CI/CD is configured properly, additional infomation can be included:
```
{
"created_at": "2023-02-20T20:00:37.022980Z",
"version": "v23.08-alpha2",
"CI_COMMIT_BRANCH": "master",
"CI_COMMIT_REF_NAME": "master",
"CI_COMMIT_SHA": "dae2cfa8f7d4769375e73499c4aaffea727f8501",
"CI_COMMIT_TIMESTAMP": "2023-02-20T20:57:59+01:00",
"CI_JOB_ID": "30420",
"CI_PIPELINE_CREATED_AT": "2023-02-20T19:58:06Z",
"CI_RUNNER_ID": "54",
"CI_RUNNER_EXECUTABLE_ARCH": "linux/amd64"
}
```
"""

# List of environment variables to be included in the MANIFEST.json
envvars = [
"CI_COMMIT_BRANCH",
"CI_COMMIT_TAG",
"CI_COMMIT_REF_NAME",
"CI_COMMIT_SHA",
"CI_COMMIT_TIMESTAMP",
"CI_JOB_ID",
"CI_PIPELINE_CREATED_AT",
"CI_RUNNER_ID",
"CI_RUNNER_EXECUTABLE_ARCH",
"GITHUB_HEAD_REF",
"GITHUB_JOB",
"GITHUB_SHA",
"GITHUB_REPOSITORY",
]


def create_manifest(args):
manifest = {
'created_at': datetime.datetime.utcnow().isoformat() + 'Z', # This is OK, no tzinfo needed
Expand All @@ -40,6 +78,11 @@ def create_manifest(args):
))
sys.exit(1)

for envvar in envvars:
envvarvalue = os.environ.get(envvar)
if envvarvalue is not None:
manifest[envvar] = envvarvalue

with open(args.manifest, "w") as f:
json.dump(manifest, f, indent='\t')

Expand Down
Loading

0 comments on commit fc748e5

Please sign in to comment.