Skip to content

update configure-aws-credentials@v4 configuration #12

update configure-aws-credentials@v4 configuration

update configure-aws-credentials@v4 configuration #12

Workflow file for this run

name: Build and Deploy to Docker Hub
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Build
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build, tag, and push image to Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_REPOSITORY: ${{ secrets.DOCKER_HUB_REPOSITORY }}
run: |
IMAGE_TAG=latest
REPOSITORY_URI=${DOCKER_HUB_USERNAME}/${DOCKER_HUB_REPOSITORY}
# Build the Docker image
docker build -t $REPOSITORY_URI:$IMAGE_TAG .
# Push the image to Docker Hub
docker push $REPOSITORY_URI:$IMAGE_TAG
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::246386308913:role/eks-auto
role-session-name: eksdeployersession
aws-region: ${{ env.AWS_REGION }}
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Update Kubernetes deployment
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
DOCKER_IMAGE_URI: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest
K8S_DEPLOYMENT_NAME: ${{ secrets.K8S_DEPLOYMENT_NAME }}
K8S_NAMESPACE: ${{ secrets.K8S_NAMESPACE }}
run: |
echo "$KUBE_CONFIG_DATA" | base64 --decode > kubeconfig
export KUBECONFIG=kubeconfig
# Update the Kubernetes deployment to use the new Docker image
kubectl set image deployment/$K8S_DEPLOYMENT_NAME *=$DOCKER_IMAGE_URI -n $K8S_NAMESPACE