diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 31d7885..d891d01 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,26 +13,38 @@ jobs: build-and-push-ecr: name: Build and Push to ECR runs-on: ubuntu-latest - steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 + uses: aws-actions/configure-aws-credentials@v1 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 + - name: Build, tag, and push image to Amazon ECR run: | + # Define the image name and tag + IMAGE_NAME=realestate-pricing-app + IMAGE_TAG=latest # or use $(git rev-parse --short HEAD) for commit hash + + # Full image name including registry and repo + FULL_IMAGE_NAME=$IMAGE_NAME:$IMAGE_TAG + ECR_FULL_IMAGE_NAME=${{ secrets.AWS_ECR_LOGIN_URI }}/$IMAGE_NAME:$IMAGE_TAG + + # Build the Docker image + docker build -t $FULL_IMAGE_NAME . + + # Login to Amazon ECR aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_LOGIN_URI }} - - name: Build, tag, and push image to Amazon ECR - run: | - docker build -t ${{ secrets.AWS_ECR_LOGIN_URI }}/${{ secrets.AWS_ECR_REPOSITORY_NAME }}:latest . - docker push ${{ secrets.AWS_ECR_LOGIN_URI }}/${{ secrets.AWS_ECR_REPOSITORY_NAME }}:latest + # Tag the image to match the ECR repository + docker tag $FULL_IMAGE_NAME $ECR_FULL_IMAGE_NAME + + # Push the image to ECR + docker push $ECR_FULL_IMAGE_NAME deploy-to-ec2: name: Deploy to EC2