Skip to content

feat: add latest_x_feed_payload to Settings and implement caching in … #30

feat: add latest_x_feed_payload to Settings and implement caching in …

feat: add latest_x_feed_payload to Settings and implement caching in … #30

name: Build and Push Docker Image
on:
push:
branches: [main]
env:
IMAGE_NAME: ${{ secrets.DOCKER_HUB_USER }}/poll-agent
AWS_REGION: us-east-1
ECR_REPOSITORY: poll-agent
# Lambda container images are typically deployed as a single-arch image (x86_64 or arm64).
# Keeping this as single-arch avoids dependency wheel gaps on secondary architectures.
LAMBDA_IMAGE_PLATFORMS: linux/amd64
LAMBDA_FUNCTION_NAME: ${{ secrets.LAMBDA_FUNCTION_NAME }}
LAMBDA_ALIAS: ${{ secrets.LAMBDA_ALIAS }}
jobs:
build-and-push-dockerhub:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASS }}
- name: Build and push multi-arch image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
build-and-push-ecr-lambda:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Lambda image to ECR
if: ${{ env.ECR_REPOSITORY != '' }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.lambda
push: true
platforms: ${{ env.LAMBDA_IMAGE_PLATFORMS }}
# Lambda does not support OCI image indexes/attestations.
# Disable BuildKit provenance/SBOM so the pushed artifact is a plain single-arch image manifest.
provenance: false
sbom: false
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:lambda-latest
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:lambda-${{ github.sha }}
- name: Update Lambda function to new image
if: ${{ env.ECR_REPOSITORY != '' && env.LAMBDA_FUNCTION_NAME != '' }}
run: |
IMAGE_URI="${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:lambda-${{ github.sha }}"
aws lambda update-function-code \
--function-name "${LAMBDA_FUNCTION_NAME}" \
--image-uri "${IMAGE_URI}" >/dev/null
aws lambda wait function-updated --function-name "${LAMBDA_FUNCTION_NAME}"
echo "Updated ${LAMBDA_FUNCTION_NAME} -> ${IMAGE_URI}"
- name: Publish version and update alias
if: ${{ env.ECR_REPOSITORY != '' && env.LAMBDA_FUNCTION_NAME != '' && env.LAMBDA_ALIAS != '' }}
run: |
VERSION="$(aws lambda publish-version --function-name "${LAMBDA_FUNCTION_NAME}" --query Version --output text)"
aws lambda update-alias \
--function-name "${LAMBDA_FUNCTION_NAME}" \
--name "${LAMBDA_ALIAS}" \
--function-version "${VERSION}" >/dev/null
echo "Alias ${LAMBDA_ALIAS} -> version ${VERSION}"