Workflow file for this run
This file contains 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 | |
on: | |
push: | |
branches: | |
- "**" | |
env: | |
AWS_REGION: us-east-1 | |
ECR_REPOSITORY: app/web | |
EKS_CLUSTER_NAME: EKS-lanchonete-cluster | |
permissions: | |
contents: read | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
outputs: | |
image: ${{ steps.build.outputs.image }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- 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-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to ECR registry | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build the container image | |
id: build | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: ${{ github.sha }} | |
GITHUB_OUTPUT: $GITHUB_ENV | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Setup Kubeconfig | |
run: aws eks --region $AWS_REGION update-kubeconfig --name $EKS_CLUSTER_NAME | |
- name: Deploy app in Kubernetes | |
env: | |
IMAGE: ${{ steps.build.outputs.image }} | |
run: | | |
echo "image=$IMAGE" >> $GITHUB_ENV | |
echo "ENVIRONMENT=development" >> $GITHUB_ENV | |
echo "Image tag: $IMAGE" | |
ENVIRONMENT=development | |
KUSTOMIZE_DIR="$(pwd)/infra/kubernetes/$ENVIRONMENT" | |
cd $KUSTOMIZE_DIR | |
if [ ! -f kustomization.yaml ]; then | |
echo "Error: Missing kustomization file 'kustomization.yaml' in $KUSTOMIZE_DIR." | |
exit 1 | |
fi | |
kubectl get namespace $ENVIRONMENT || kubectl create namespace $ENVIRONMENT | |
kustomize edit set image web=$IMAGE | |
echo "Deploying resources in $ENVIRONMENT environment..." | |
kubectl apply -k $KUSTOMIZE_DIR -n $ENVIRONMENT |