Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Build and Push to ECR

on:
push:
branches:
- integration
pull_request:
branches:
- main

env:
AWS_REGION: us-east-1
ECR_REPOSITORY: west-discovery
IMAGE_TAG: ${{ github.sha }}

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov pytest-asyncio

- name: Run linting
run: |
pip install flake8
flake8 src/ --config=.flake8

- name: Run tests
run: |
pytest tests/ -v --cov=src/stac_fastapi/globus_search --cov-report=xml
continue-on-error: true

- name: Upload coverage reports
uses: codecov/codecov-action@v4
if: github.event_name == 'push'
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
continue-on-error: true

build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
# if: ${{ (github.ref == 'refs/heads/main/' && github.event_name == 'pull_request') || (github.ref == 'refs/heads/integration/' && github.event_name == 'push') }}
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
image-digest: ${{ steps.build-push.outputs.digest }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-duration-seconds: 3600
role-session-name: GitHubActions-${{ github.run_id }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/x86_64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATE=${{ github.event.head_commit.timestamp }}
VCS_REF=${{ github.sha }}
VERSION=${{ steps.meta.outputs.version }}

- name: Image digest
run: echo ${{ steps.build-push.outputs.digest }}
Loading