simplify template #28
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
name: Build, Test, and Push to ECR | |
on: | |
push: | |
branches: [ "main" ] # Adjust to your preferred branch | |
env: | |
IMAGE_TAG: latest # Environment variable for the image tag | |
jobs: | |
build-test-and-push: | |
runs-on: ubuntu-latest # Runs the job on the latest Ubuntu environment | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 # Checks out the repository | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' # Define the Python version | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip # Upgrade pip | |
pip install -r requirements.txt # Install dependencies from requirements.txt | |
- name: Run unit tests | |
run: | | |
python -m unittest discover -s src -p "test_*.py" # Discover and run all tests prefixed with test_ | |
- name: Configure AWS credentials | |
if: success() | |
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: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
if: success() | |
id: ecr-login | |
run: | | |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | |
- name: Build and tag server Docker image | |
if: success() | |
run: | | |
docker build -t ${{ secrets.ECR_REPOSITORY_SERVER }} -f ./docker/Dockerfile.server . | |
docker tag ${{ secrets.ECR_REPOSITORY_SERVER }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY_SERVER }}:${{ env.IMAGE_TAG }} | |
- name: Build and tag client Docker image | |
if: success() | |
run: | | |
docker build -t ${{ secrets.ECR_REPOSITORY_CLIENT }} -f ./docker/Dockerfile.client . | |
docker tag ${{ secrets.ECR_REPOSITORY_CLIENT }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY_CLIENT }}:${{ env.IMAGE_TAG }} | |
- name: Push server image to ECR | |
if: success() | |
run: | | |
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY_SERVER }}:${{ env.IMAGE_TAG }} | |
- name: Push client image to ECR | |
if: success() | |
run: | | |
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY_CLIENT }}:${{ env.IMAGE_TAG }} |