Skip to content

Bump orjson from 3.9.10 to 3.9.15 in /app #21

Bump orjson from 3.9.10 to 3.9.15 in /app

Bump orjson from 3.9.10 to 3.9.15 in /app #21

name: Test and deploy to ECR
on:
push:
branches: [main]
paths:
- "app/**"
- ".github/workflows/test_and_deploy_to_ecr.yaml"
pull_request:
paths:
- "app/**"
- ".github/workflows/test_and_deploy_to_ecr.yaml"
workflow_dispatch:
env:
ECR_REPOSITORY: devops-boot
CONTAINER_NAME: fastapi_app
AWS_REGION: us-east-1 # Used for a public registry
jobs:
test:
name: Application unittests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r app/requirements.txt
- name: Install pytest
run: |
pip install pytest
- name: Run tests
run: |
pytest
build:
name: Build Image
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' # Only run on push or manual dispatch
needs: test # Only run if tests execute successfully
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
ECR_REGISTRY_ALIAS: m2d0h7p4 # Alias generated by AWS: https://gallery.ecr.aws/m2d0h7p4/devops-boot
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG app/
docker build -t $ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY:latest app/
docker push $ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT