{"id":24362683,"url":"https://github.com/machu-gwu/aws-codebuild-test-postgres-database-example","last_synced_at":"2026-04-07T21:32:01.973Z","repository":{"id":82575047,"uuid":"519077116","full_name":"MacHu-GWU/aws-codebuild-test-postgres-database-example","owner":"MacHu-GWU","description":"Use postgres docker image for testing in AWS CodeBuild","archived":false,"fork":false,"pushed_at":"2022-07-29T04:18:52.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-23T16:38:06.339Z","etag":null,"topics":["aws","aws-codebuild","docker","postgres"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MacHu-GWU.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-07-29T04:18:21.000Z","updated_at":"2024-10-02T07:41:41.000Z","dependencies_parsed_at":"2023-11-03T12:00:12.226Z","dependency_job_id":null,"html_url":"https://github.com/MacHu-GWU/aws-codebuild-test-postgres-database-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MacHu-GWU/aws-codebuild-test-postgres-database-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Faws-codebuild-test-postgres-database-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Faws-codebuild-test-postgres-database-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Faws-codebuild-test-postgres-database-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Faws-codebuild-test-postgres-database-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MacHu-GWU","download_url":"https://codeload.github.com/MacHu-GWU/aws-codebuild-test-postgres-database-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Faws-codebuild-test-postgres-database-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31530641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-codebuild","docker","postgres"],"created_at":"2025-01-18T22:53:12.652Z","updated_at":"2026-04-07T21:32:01.965Z","avatar_url":"https://github.com/MacHu-GWU.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"AWS CodeBuild Test Postgres Database Example\n==============================================================================\n.. contents::\n    :class: this-will-duplicate-information-and-it-is-still-useful-here\n    :depth: 1\n    :local:\n\n\nSummary\n------------------------------------------------------------------------------\nIn many projects, we need a database docker container for testing. We can easily run a container with an empty database, then destroy it automatically after testing. This repo gives you an example using AWS CodeBuild to run a \"side-car\" postgres container for testing.\n\n\nThe Example\n------------------------------------------------------------------------------\nIn this example, we use the ``postgres:10.6-alpine`` image to run a postgres db in the background, and we use Python `sqlalchemy \u003chttps://www.sqlalchemy.org/\u003e`_ to connect to the postgres db and run a `simple SQL statement \u003c./tests/test_psql.py\u003e`_.\n\nThe `buildspec.yml \u003c./buildspec.yml\u003e`_ file is the AWS CodeBuild orchestration file.\n\n- In ``install`` phase, we pulled the docker image from DockerHub\n- In ``pre_build`` phase, we start a background postgres container\n- In ``build`` phase, we installed the dependencies and run the test\n- In ``post_build`` phase, we destroy the postgres container.\n\n\nDockerHub docker pull limits\n------------------------------------------------------------------------------\nThe DockerHub has 100 pull per IP per hour limits. You may easily hit this limits if you have many build runs. I recommend to use AWS ECR to cache the image you pulled from DockerHub. There's NO COST to transfer data from ECR to AWS CodeBuild if they are in AWS Region, see explanation `here \u003chttps://aws.amazon.com/ecr/pricing/\u003e`_. AWS ECR will charge if you are pulling from non AWS Region, for example, your local laptop.\n\nIn buildspec file, you should add some logic to ``install`` phase:\n\n1. if ECR doesn't have this image, we pull it, then re-tag it, and then push to ECR.\n2. if the latest image in ECR was updated one month before, we pull it form DockerHub and push it again to ECR.\n3. in ``pre_build`` phase, we always use image from ECR.\n\n\nIs this a \"Side Car\" or \"Docker in Docker\"?\n------------------------------------------------------------------------------\nYou can think of AWS CodeBuild is a VM in sandbox mode. The main build logic happens in container, however you can setup additional background container. In other words, this is NOT \"Docker in Docker\".\n\n\nReferences\n------------------------------------------------------------------------------\n- postgres on DockerHub: https://hub.docker.com/_/postgres\n- Background tasks in build environments: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-background-tasks.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachu-gwu%2Faws-codebuild-test-postgres-database-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachu-gwu%2Faws-codebuild-test-postgres-database-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachu-gwu%2Faws-codebuild-test-postgres-database-example/lists"}