This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
Deploy to Amazon EKS #59
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
# To use this workflow, you will need to complete the following set-up steps: | |
# | |
# 1. Create an ECR repository to store your images. | |
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. | |
# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name. | |
# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region. | |
# | |
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. | |
# See the documentation for each action used below for the recommended IAM policies for this IAM user, | |
# and best practices on handling the access key credentials. | |
name: Deploy to Amazon EKS | |
on: | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} # set this to your Amazon ECR repository name | |
CONTAINER_NAME: rms-api-pagamentos # set this to the name of the container in the | |
# containerDefinitions section of your task definition | |
permissions: | |
contents: read | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
# environment: production | |
steps: | |
- name: Checkout | |
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 Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
docker push --all-tags $ECR_REGISTRY/$ECR_REPOSITORY | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Criar arquivo kubeconfig | |
# https://docs.aws.amazon.com/pt_br/eks/latest/userguide/create-kubeconfig.html | |
run: aws eks update-kubeconfig --region ${{ secrets.AWS_REGION }} --name ${{ secrets.EKS_CLUSTER_NAME }} | |
- name: kubectl-apply | |
# A ordem dos arquivos importa no Kubernetes | |
run: | | |
kubectl apply \ | |
-f k8s/production/api/namespace.yaml \ | |
-f k8s/production/api/config.yaml \ | |
-f k8s/production/api/service-account.yaml \ | |
-f k8s/production/api/secret-provider.yaml \ | |
-f k8s/production/api/deployment.yaml \ | |
-f k8s/production/api/service.yaml \ | |
-f k8s/production/api/hpa.yaml | |
# Baseado na Action de exemplo "Deploy to Amazon ECS" do GitHub |