Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/ms-decomposition-nosql: retornando job cd #10

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 71 additions & 73 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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
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/[email protected]
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
Loading