Created
May 10, 2025 11:22
-
-
Save rimrachai-marma/7f687890bfe630bec2f8cf1ee65a7938 to your computer and use it in GitHub Desktop.
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: Deploy to AWS EKS | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
AWS_REGION: us-west-1 | |
EKS_CLUSTER_NAME: my-cluster-name | |
DOCKER_IMAGE: rimra/express-app | |
DEPLOYMENT_NAME: express-app | |
CONTAINER_NAME: express-app | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: production | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
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: ${{ env.AWS_REGION }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build, Tag, and Push image to DockerHub | |
id: build-image | |
env: | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t ${DOCKER_IMAGE}:${IMAGE_TAG} . | |
docker push ${DOCKER_IMAGE}:${IMAGE_TAG} | |
echo "image=${DOCKER_IMAGE}:${IMAGE_TAG}" >> $GITHUB_OUTPUT | |
- name: Install kubectl | |
uses: azure/setup-kubectl@v1 | |
with: | |
version: "latest" | |
- name: Update kubeconfig | |
run: | | |
aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }} | |
- name: Deploy to EKS | |
run: | | |
kubectl set image deployment/${{ env.DEPLOYMENT_NAME }} ${{ env.CONTAINER_NAME }}=${{ steps.build-image.outputs.image }} | |
kubectl rollout status deployment/${{ env.DEPLOYMENT_NAME }} | |
- name: Verify deployment pods | |
run: | | |
kubectl get pods -l app=${{ env.DEPLOYMENT_NAME }} --output=wide |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment