diff --git a/.github/workflows/build-push-ecr.yml b/.github/workflows/build-push-ecr.yml new file mode 100644 index 0000000..4915375 --- /dev/null +++ b/.github/workflows/build-push-ecr.yml @@ -0,0 +1,62 @@ +name: Build and Push to AWS ECR + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + workflow_dispatch: + +env: + AWS_REGION: us-east-1 + ECR_REPOSITORY: zerodev/passkey-server + +permissions: + contents: write + id-token: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::117243983517:role/zerodev-gha + role-session-name: GitHubActions-${{ github.run_id }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + with: + registries: "352956043285" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }} + tags: | + type=sha,prefix=${{ github.event.pull_request.head.ref }}-,enable={{is_not_default_branch}} + type=sha,prefix=,enable={{is_default_branch}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max