Developer Notes
This page contains information for developers wishing to update or maintain the SQL Proxy endpoint on the dbconnector service.
Developer Setup
The code for the dbconnector is stored in the AWS codecommit cob_dbconnector repository (CoB Digital account).
Typically the code is cloned from that repository onto the developers local machine. In order do this, AWS credentials must set up correctly. See these notes. The AWS-CLI is required, so it must be installed locally, and credentials must be set in the ~/.aws/credentials
file.
This command will clone the develop
branch ofcob_dbconnector
application into a folder at ~/sources/cob_dbconnector
. The file may be cloned anywhere on the local computer, however this document assumes it will cloned into ~/sources/cob_dbconnector
and if it is not, then commands given here will need to be modified for the new location.
Once the repo is cloned, then the following command will build the app, build its container locally and tag the container:
The script will create a docker container, build the necessary files from the local cloned folders and then save and tag the docker image.
The developer can then use docker-compose to start the container as follows:
This will build the docker container locally, start it and name it dbconnector
.
Modifying Code
Once the steps in "Developer Setup" above have been completed, the developer can go ahead and change the code as needed in the cloned repository.
In this example the code is found in ~/sources/cob_dbconnector/src
.
Best practice is to create a working branch off the develop
branch and then make commit changes to the working branch as needed. Once ready to push and merge code back to the repo in CodeCommit, the working branch can be pushed, and then a PR made and committed. For example, to add a period to the end of the README.md file:
Now login to AWS and find the cob_dbconnector
repo in CodeCommit. Create a PR from the working_branch
into develop
. Use approval workflows as needed.
Unlike the Drupal deploy process (where the deploy is triggered by commits to the GutHub repo) there are no triggers fired by committing, pushing, tagging or merging to the cob_dbconnector CodeCommit repository.
Deployment is triggered by updates to the ECR repository.
Testing
Once changes have been made and saved in the src
folder, the application needs to be re-built and the container re-deployed in order to verify the changes work as expected.
Updating local container with updated/changed code
The repository files on the host are NOT mounted into the container. Therefore changes to code on the host machine are not automatically replicated to the container, even if a local build is forced (e.g. running npm run dev
inside the container) . In order to "load" changed code into the container, it must be rebuilt.
To re-build and re-deploy the container:
Or more concisely (ensure you are in the correct folder):
Each time you build the container using build.sh
, a new local image is created and tagged. The old image is not automatically deleted, so over time you will get a lot of images saved on your local computer, taking up disk space.
Which this is nice if you want to manually create a new container from a previous image, mostly its a nuisance and just takes up local disk space.
You can delete all DBConnector images which do not have a tag.
Manual testing in the local container
Because the dbconnector is an API designed to be used via an REST endpoint, the best tool for testing is either a custom written testbed which calls the container, or else a tool like postman.
To connect to the container for testing, you will need to know the containers IPAddress. This can be found as follows:
The IPAddress will typically be something like 172.x.0.x
, depending on your docker setup. Locally the service runs on port 3000, and the container has port 3000 exposed.
https://<IPAddress>:3000/ should be used as the endpoint for testing locally: For example In postman run a test GET request on the URL :
This should return an empty json message {}
with an HTTP Code of 200. If you get anything else there is an issue.
Attach to console
Using docker you can attach to the running console for the dbconnector container and get a tail of the stdout and stderr in real-time. This is useful because you can add console.log()
commands to the code and then see them appear in the attached console.
Use this command to attach to the console:
Create a new interactive session (shell) on container
Using docker you can open a new bash shell in the container and run commands in the console for that session. You could use this to verify the existence of files, or to check if dependencies are installed etc. This command creates an interactive shell:
If you dont need an interactive shell, you just want to run a single command, you can use this:
Automated Testing
There are a suite of automated tests created for the dbconnector. These tests are run locally by the developer, and the tests can be extended.
The stock tests adequately test all the endpoints for the service, and as new functionality or features are added, the tests should be expanded to ensure they are up to date.
The tests are run using this command:
The tests are defined in the file src/tests/tests.config.js
.
Deploying
There are 2 remote environments an AWS, stage
and production
.
To deploy to either, its a simple matter of creating a stage or production build and then pushing the image to the ECR registry. A watch process monitors the ECR repository and changes to the container images (uploads or re-tags) automatically prompts deploys to the ECR environment.
For the DBConnector there is a helper script to build, tag and push container images:
This is all that is needed to initiate a deploy.
Best Practice Developer Workflow
The might be the way a developer works:
Project Start
follow setup instructions here
create a local working branch from
develop
branch
Project Development & Local Testing
commit code locally to working branch
... iterate these steps as necessary
Project External Testing
commit code and push to AWS Code Commit
create PR on CodeCommit (follow peer review and other related project steps) and then merge PR (on CodeCommit)
build and deploy stage version (stage)
advise external testers
... iterate back through development stage steps as needed.
Project End
build and depoy production (production)
Troubleshooting
Add solutions to issues as you encounter them here.
Last updated