Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#3 from baegjae/feature/swagg…
Browse files Browse the repository at this point in the history
…er-apm-workflows

Updates for platform works
  • Loading branch information
baegjae authored Nov 17, 2020
2 parents a6cefa7 + f9d2c5f commit 39e10d6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
File renamed without changes.
File renamed without changes.
77 changes: 77 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Python CI with Docker

on:
workflow_dispatch:
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest

env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

steps:
- uses: act10ns/slack@v1
with:
status: starting
if: always()

- name: Checkout source code
uses: actions/checkout@v2
with:
path: main
- name: Checkout ston-config
uses: actions/checkout@v2
with:
repository: sktston/ston-config
token: ${{ secrets.PAT }}
path: config

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set environment variables
run: |
echo "::set-env name=ECR_REGISTRY::${{ steps.login-ecr.outputs.registry }}"
echo "::set-env name=ECR_REPOSITORY::ston/aca-py"
echo "::set-env name=IMAGE_TAG::${{ github.sha }}"
echo "::set-env name=DOCKERFILE_PATH::docker/Dockerfile.run"
- name: Build, tag, and push image to Amazon ECR
id: build-and-push-to-ecr
working-directory: main
run: |
docker build -f $DOCKERFILE_PATH -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
with:
kustomize-version: "3.8.1"
- name: Update the image tag with Kustomize
id: update-config-with-kustomize
working-directory: config
run: |
git config user.name github-actions
git config user.email [email protected]
git pull origin master
cd overlays/dev
kustomize edit set image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
git add kustomization.yaml
git commit -m "Deploying image $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
git push origin master
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: always()
File renamed without changes.
33 changes: 31 additions & 2 deletions aries_cloudagent/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import logging
import os
from typing import Callable, Coroutine, Sequence, Set
import uuid

Expand All @@ -13,6 +14,7 @@
validation_middleware,
)
import aiohttp_cors
from elasticapm.contrib.aiohttp import ElasticAPM

from marshmallow import fields, Schema

Expand All @@ -33,6 +35,7 @@


LOGGER = logging.getLogger(__name__)
ELASTIC_APM_ENABLED = os.getenv("ELASTIC_APM_ENABLED")


class AdminModulesSchema(Schema):
Expand Down Expand Up @@ -365,9 +368,32 @@ async def activate_wallet(request, handler):
agent_label = self.context.settings.get("default_label")
version_string = f"v{__version__}"

setup_aiohttp_apispec(
app=app, title=agent_label, version=version_string, swagger_path="/api/doc"
# if it is the agent in k8s behind the nginx ingress
if agent_label == "ACA-Py Agent (Multi-Tenant)":
setup_aiohttp_apispec(
app=app,
title=agent_label,
version=version_string,
swagger_path="/agent/swagger-ui",
static_path="/agent/swagger-ui/static/swagger",
url="/agent/swagger-ui/swagger.json",
basePath="/agent/api",
securityDefinitions={
"OAuth2": {"type": "apiKey", "name": "Authorization", "in": "header"}
},
security=[{"OAuth2": []}]
)
else:
setup_aiohttp_apispec(
app=app,
title=agent_label,
version=version_string,
swagger_path="/api/doc",
securityDefinitions={
"WalletAuth": {"type": "apiKey", "name": "Wallet", "in": "header"}
},
security=[{"WalletAuth": []}]
)
app.on_startup.append(self.on_startup)

# ensure we always have status values
Expand All @@ -393,6 +419,9 @@ def sort_dict(raw: dict) -> dict:
return dict(sorted([item for item in raw.items()], key=lambda x: x[0]))

self.app = await self.make_application()
# ElasticAPM is enabled only under initial platform
if ELASTIC_APM_ENABLED and ELASTIC_APM_ENABLED == "true":
apm = ElasticAPM(self.app)
runner = web.AppRunner(self.app)
await runner.setup()

Expand Down
7 changes: 7 additions & 0 deletions aries_cloudagent/transport/inbound/http_custodial.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""Http Transport classes and functions."""

import logging
import os

from aiohttp import web

from elasticapm.contrib.aiohttp import ElasticAPM

from ...messaging.error import MessageParseError

from .base import BaseInboundTransport, InboundTransportSetupError

from ...wallet_handler.handler import WalletHandler

LOGGER = logging.getLogger(__name__)
ELASTIC_APM_ENABLED = os.getenv("ELASTIC_APM_ENABLED")


class CustodialHttpTransport(BaseInboundTransport):
Expand Down Expand Up @@ -51,6 +55,9 @@ async def start(self) -> None:
"""
app = await self.make_application()
# ElasticAPM is enabled only under initial platform
if ELASTIC_APM_ENABLED and ELASTIC_APM_ENABLED == "true":
apm = ElasticAPM(app)
runner = web.AppRunner(app)
await runner.setup()
self.site = web.TCPSite(runner, host=self.host, port=self.port)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pyld==2.0.1
py_multicodec==0.2.1
pyyaml~=5.3.1
ConfigArgParse~=1.2.3
elastic-apm~=5.9.0

0 comments on commit 39e10d6

Please sign in to comment.