Package: pydevhammer
Py Dev Hammer:snake: :nerd_face: :hammer:When all you have is a hammer, everything looks like a dev.AboutPy Dev Hammer is a collection of tools to help in developing Python applications.This pre-alpha release contains a single tool. It is a Continuous Integration helper which performs
dynamic and static code analysis on your project and POSTs the results to GitHub as statuses.Seeroad mapfor further release plans. The first item is to use AWS CloudFormation to
make most of this document redundant. As the project progresses this README will reference other
READMEs instead of detailing everything.Requirespython3.6PrerequisitesNote: this guide attempts to keep specific references to third-party tools to a minimum as they are
very likely to change. Use your intuition and please get incontactif there are glaring problems and/or you want to
buy me a beer. The latter is recommended.GitHubTo enable Continuous Integration of your commits, GitHub communicates with AWS CodeBuild viaWebhooks. For ease of use you can set this up in
theGitHub UIrather than
using the API. The following options should be used:Payload URL:https://codebuild.{your-aws-region}.amazonaws.com/webhooksContent type:application/jsonSecret:Create a secure secretSSL verification:EnableWhich events would you like to trigger this webhook?:Just the push event.Active:TickedYou will link CodeBuild to GitHubnext.AWSCodeBuildYou mustconfigure your buildto integrate with GitHub. For theSource provideroption choose GitHub thenConnect to GitHub.
Follow the authentication path then pick the source repository.The following options should be used:Report build status:TickedWebhook:TickedBranch filter:Leave blank(Build them all!)Build Badge:TickedBuild specification:Use the buildspec.yml in the source code root directoryBuildspec name:buildspec.ymlService role:Create a service role in your accountDynamoDBTo maintain the state of multiple builds, aDynamoDB tablewith a partition and sort key needs to be created. Theexample app fileuses the following
values:dynamo:
    table_name: 'build-status'
    partition_key_name: 'branch_name'
    sort_key_name: 'build_start_time'The primary partition key is aStringand the primary sort key is aNumber.Systems Manager (SSM)To POST to GitHub agithub_ownerandgithub_tokenarerequired. These are to
be kept in theAWS Systems Manager Parameter Storeas typeSecureString.IAMYou will be creating an IAM service role when configuringCodeBuild.ConfigTwo configuration files are required for the scripts:appanduser. Examples are located atexamples/app_config.example.ymlandexamples/user_config.example.yml.AppThe example app config can be copied and used as is, however you may want to remove some of the test
types undertests_to_runand note that yourbuildspec.ymlwill need to be adjusted to
match.UserThe example user config should be modified to suit your GitHub and AWS project details.CertificatesTo POST securely to GitHub (as you are sending your GitHub token over the Internet) a certificate
must be used. Pass your file path as an environment variableCERTIFICATE_FILE. Alternatively you
can use the third-party Python modulecertifito generate this.
The script will look for the environment variable first and fall back to usingcertifi.where().Environment variablesA number of environment variables must be set for the CodeBuild environment via thebuildspec.ymlfile.This variable is set automatically by AWS CodeBuild:CODEBUILD_SRC_DIRThese variables are used by the scripts of this project:(Note: the back-ticks are important as this is BASH-land)PYTHONPATH=`pwd`CONFIG_DIR=/path/to/your/config/dirCERTIFICATE_FILE=/path/to/your/cert.file(Note:optional)CODEBUILD_GIT_BRANCH=`git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }'`(Note: deprecation warning; will be sourced from within Python in future releases)This variable is used by CodeBuild:TESTS_DIR=$CODEBUILD_SRC_DIR/path/to/your/tests/results/dir(Note: this is the test directory for your project, not this project)Installationpip install pydevhammerUsageCreate a Python file to run the scripts from the command line viabuildspec.yml. An example file
can be found inexamples/run_github_status_posting.py.To use CodeBuild with the aboveAWS config, you will need to create abuildspec.ymlfile. An example file is located inexamples/buildspec.yml. Thebuildsection of that file is where you will call thetests_to_run.Road MapSet up all AWS resources with CloudFormation (who wants to read this README?)reStructuredText to Markdown converter (mostly already written)Visualisation of the toolkit with dashboards (need more tools in the old toolkit first)Dockerising things (that should be Dockerised)Monitoring (comings and goings of electrons)Other cool things I'm sure (fingers crossed)