From 249cc9c77191849e45ae6d6b5c5a37034582ac56 Mon Sep 17 00:00:00 2001 From: Matheus <30qr4xnl@duck.com> Date: Sat, 13 Jul 2024 16:16:46 -0300 Subject: [PATCH] feat/ms-decomposition-nosql: retornando job cd --- .github/workflows/ci-cd-pipeline.yml | 144 +++++++++++++-------------- 1 file changed, 71 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ci-cd-pipeline.yml b/.github/workflows/ci-cd-pipeline.yml index d487762..80d9869 100644 --- a/.github/workflows/ci-cd-pipeline.yml +++ b/.github/workflows/ci-cd-pipeline.yml @@ -72,78 +72,76 @@ jobs: - name: Checkout code uses: actions/checkout@v2 -# - name: Set up Docker Buildx -# uses: docker/setup-buildx-action@v1 -# -# - name: Set up 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: ${{ secrets.AWS_REGION }} -# -# - name: Login to Amazon ECR -# uses: aws-actions/amazon-ecr-login@v1 -# -# - name: Calculate next tag -# id: tagger -# run: | -# TAG="0.1.0" # Initialize with the starting version -# LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) -# if [ ! -z "$LATEST_TAG" ]; then -# TAG=$(echo $LATEST_TAG | awk -F. '{$NF+=1; OFS="."; print $0}') -# fi -# echo "Next tag: $TAG" -# echo "::set-output name=next_tag::$TAG" -# -# - name: Build, tag, and push Docker image to Amazon ECR -# env: -# ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com -# ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} -# IMAGE_TAG: ${{ steps.tagger.outputs.next_tag }} -# run: | -# IMAGE_URI="$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" -# docker build -t $IMAGE_URI . -# docker push $IMAGE_URI -# echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV -# -# - name: Update Kubernetes configuration -# run: | -# sed -i 's|placeholder_repository_name|'"$IMAGE_URI"'|' ./infra/golang-app-deployment.yaml -# cat ./infra/golang-app-deployment.yaml -# -# - name: Install kubectl -# run: | -# curl -LO "https://dl.k8s.io/release/$(curl -sSL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -# chmod +x kubectl -# sudo mv kubectl /usr/local/bin/ -# -# - name: Update kube config -# run: aws eks update-kubeconfig --name ${{ secrets.AWS_EKS_CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }} -# -# - name: Deploy to Kubernetes -# env: -# K8S_DEPLOYMENT_NAME: ${{ secrets.K8S_DEPLOYMENT_NAME }} -# run: | -# kubectl apply -f ./infra -# kubectl rollout status deployment/$K8S_DEPLOYMENT_NAME - -# - name: Deploy to Kubernetes -# env: -# ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com -# ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} -# IMAGE_TAG: ${{ github.sha }} -# K8S_DEPLOYMENT_NAME: ${{ secrets.K8S_DEPLOYMENT_NAME }} -# K8S_DEPLOYMENT_CONTAINER_NAME: ${{ secrets.K8S_DEPLOYMENT_CONTAINER_NAME }} -# run: | -# kubectl set image deployment/$K8S_DEPLOYMENT_NAME $K8S_DEPLOYMENT_CONTAINER_NAME=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --record -# kubectl rollout status deployment/$K8S_DEPLOYMENT_NAME - - - name: Generate semantic version tag - uses: hennejg/github-tag-action@v4.1.jh1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Set up AWS credentials + uses: aws-actions/configure-aws-credentials@v1 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Push tag + 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: ${{ secrets.AWS_REGION }} + + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v1 + + - name: Calculate next tag + id: tagger + run: | + TAG="0.1.0" # Initialize with the starting version + LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) + if [ ! -z "$LATEST_TAG" ]; then + TAG=$(echo $LATEST_TAG | awk -F. '{$NF+=1; OFS="."; print $0}') + fi + echo "Next tag: $TAG" + echo "::set-output name=next_tag::$TAG" + + - name: Build, tag, and push Docker image to Amazon ECR + env: + ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com + ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} + IMAGE_TAG: ${{ steps.tagger.outputs.next_tag }} + run: | + IMAGE_URI="$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" + docker build -t $IMAGE_URI . + docker push $IMAGE_URI + echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV + + - name: Update Kubernetes configuration + run: | + sed -i 's|placeholder_repository_name|'"$IMAGE_URI"'|' ./infra/golang-app-deployment.yaml + cat ./infra/golang-app-deployment.yaml + + - name: Install kubectl + run: | + curl -LO "https://dl.k8s.io/release/$(curl -sSL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + chmod +x kubectl + sudo mv kubectl /usr/local/bin/ + + - name: Update kube config + run: aws eks update-kubeconfig --name ${{ secrets.AWS_EKS_CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }} + + - name: Deploy to Kubernetes + env: + K8S_DEPLOYMENT_NAME: ${{ secrets.K8S_DEPLOYMENT_NAME }} run: | - git push --follow-tags \ No newline at end of file + kubectl apply -f ./infra + kubectl rollout status deployment/$K8S_DEPLOYMENT_NAME + + - name: Deploy to Kubernetes + env: + ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com + ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} + IMAGE_TAG: ${{ github.sha }} + K8S_DEPLOYMENT_NAME: ${{ secrets.K8S_DEPLOYMENT_NAME }} + K8S_DEPLOYMENT_CONTAINER_NAME: ${{ secrets.K8S_DEPLOYMENT_CONTAINER_NAME }} + run: | + kubectl set image deployment/$K8S_DEPLOYMENT_NAME $K8S_DEPLOYMENT_CONTAINER_NAME=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --record + kubectl rollout status deployment/$K8S_DEPLOYMENT_NAME + +# - name: Bump version and push tag +# id: tag_version +# uses: mathieudutour/github-tag-action@v6.2 +# with: +# github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file