add node exporter installation #102
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image to ECR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1️⃣ Checkout the main repo (required for OIDC) | |
| - name: Checkout main repo | |
| uses: actions/checkout@v4 | |
| # 2️⃣ Configure AWS credentials using OIDC | |
| - name: Configure AWS credentials using OIDC role | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| with: | |
| role-to-assume: arn:aws:iam::938674806440:role/github2 | |
| aws-region: ap-southeast-1 | |
| # 3️⃣ Login to Amazon ECR | |
| - name: Login to Amazon ECR | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| # 4️⃣ Clone the lab-final-project repo | |
| - name: Clone lab-final-project | |
| run: | | |
| git clone https://github.com/Infratify/lab-final-project.git | |
| ls -lah lab-final-project # just to verify | |
| # 5️⃣ Build Docker image from cloned lab project | |
| - name: Build Docker image | |
| run: | | |
| IMAGE_NAME=devops-bootcamp/final-project-faridamirul | |
| IMAGE_TAG=Latest | |
| docker build -t $IMAGE_NAME:$IMAGE_TAG ./lab-final-project | |
| # 6️⃣ Tag Docker image for ECR | |
| - name: Tag Docker image for ECR | |
| run: | | |
| ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | |
| IMAGE_NAME=devops-bootcamp/final-project-faridamirul | |
| IMAGE_TAG=Latest | |
| ECR_URI=$ACCOUNT_ID.dkr.ecr.ap-southeast-1.amazonaws.com/$IMAGE_NAME | |
| docker tag $IMAGE_NAME:$IMAGE_TAG $ECR_URI:$IMAGE_TAG | |
| echo "ECR_URI=$ECR_URI" >> $GITHUB_ENV | |
| # 7️⃣ Push Docker image to ECR | |
| - name: Push Docker image to ECR | |
| run: | | |
| IMAGE_TAG=Latest | |
| docker push $ECR_URI:$IMAGE_TAG |