Skip to content

Add: correct build-context for CI #8

Add: correct build-context for CI

Add: correct build-context for CI #8

Workflow file for this run

name: Build and Push to ECR
on:
workflow_dispatch:
schedule:
- cron: '0 */12 * * *'
push:
branches:
- prod
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
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: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up build context
run: |
rm -rf build-context
cp -r apps/backend build-context
- name: Build, tag, and push image to ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
echo "Building image..."
docker build -f build-context/Dockerfile.prod -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG build-context
echo "Tagging image as latest..."
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
$ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "Pushing image with tag $IMAGE_TAG..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "Pushing image with tag latest..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest