Created
September 15, 2021 16:30
-
-
Save samkit-jain/a1628eddeac6d2801ba664d1c4181191 to your computer and use it in GitHub Desktop.
Buildspec with codecov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 0.2 | |
env: | |
variables: | |
ECR_REGISTRY: 1234567890.dkr.ecr.ap-southeast-1.amazonaws.com | |
ECR_REPOSITORY: repository | |
secrets-manager: | |
DOCKER_HUB_USERNAME: arn:aws:secretsmanager:ap-southeast-1:1234567890:secret:dockerhub:username | |
DOCKER_HUB_PASSWORD: arn:aws:secretsmanager:ap-southeast-1:123457890:secret:dockerhub:password | |
phases: | |
install: | |
runtime-versions: | |
python: 3.8 | |
pre_build: | |
commands: | |
- echo "Logging in to ECR" | |
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY | |
- echo "Logging in to Docker" | |
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD | |
build: | |
commands: | |
- echo "Building Docker image" | |
- docker build -t $ECR_REPOSITORY . -f path/to/Dockerfile | |
- echo "Running container" | |
- docker run -d --rm --entrypoint=/usr/bin/tail --net=host --name=my-container $ECR_REPOSITORY -f /dev/null | |
- echo "Start the PostgreSQL database" | |
- docker run -d --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_DB=db_name -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password --name postgres-container postgres:13.1 | |
- echo "Running tests using Pytest" | |
- docker exec my-container bash -c "python -m pytest --cov=./ --cov-report=xml tests/" | |
- docker cp my-container:/container/path/to/tests/coverage.xml /host/path/to/tests/coverage.xml | |
- echo "Cleanup" | |
- docker rm --force my-container | |
- docker rm --force postgres-container | |
post_build: | |
commands: | |
- bash codecov_upload.sh | |
- bash deploy.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment