Skip to content

Commit

Permalink
Merge pull request #45 from software-architecture-fiap/here-we-go
Browse files Browse the repository at this point in the history
Test deploy in prod using PR labels
  • Loading branch information
carolinebrasil authored Dec 7, 2024
2 parents a2dc31f + 6e8fb78 commit d3af1ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
60 changes: 28 additions & 32 deletions .github/workflows/build-deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
name: build-deploy-dev
on:
issue_comment:
types: [created, edited]
push:
branches:
- "**"
issue_comment:
types: [created]
pull_request:
types: [opened, synchronize]

env:
AWS_REGION: us-east-1
ECR_REPOSITORY: app/web
EKS_CLUSTER_NAME: EKS-lanchonete-cluster
AWS_REGION: us-east-1
ECR_REPOSITORY: app/web
EKS_CLUSTER_NAME: EKS-lanchonete-cluster

permissions:
contents: read
contents: read

jobs:
build-deploy-dev:
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/deploy-dev'}}
#if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/deploy-dev')
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.comment.body == '/deploy-dev' }}
runs-on: ubuntu-latest

outputs:
image: ${{ steps.build.outputs.image }}
image: ${{ steps.build.outputs.image }}

steps:
- name: Debug GitHub Event
run: |
echo "Event: ${{ toJson(github.event) }}"
echo "Event: ${{ toJson(github.event) }}"
- name: Checkout repository
uses: actions/checkout@v4

- name: Check deploy-dev comment trigger and version image tag
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/deploy-dev')
run: |
echo "Development deploy detected. I will be trigger a build using commit SHA and a deployment in development environment."
echo "tag=${{ github.sha }}-dev" >> $GITHUB_ENV
echo "The dev version is: ${{ github.sha }}-dev"
echo "Development deploy detected. I will be trigger a build using commit SHA and a deployment in development environment."
echo "tag=${{ github.sha }}-dev" >> $GITHUB_ENV
echo "The dev version is: ${{ github.sha }}-dev"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -51,7 +49,7 @@ jobs:
with:
registry-type: private
mask-password: true

- name: Build and push the container image
id: build-dev
env:
Expand All @@ -65,20 +63,18 @@ jobs:
run: aws eks --region $AWS_REGION update-kubeconfig --name $EKS_CLUSTER_NAME

- name: Deploy to development environment
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/deploy-dev')
run: |
echo "Deploying to development environment..."
# Use the image tag from the previous step
echo "Image tag: ${{ steps.build-dev.outputs.image }}"
# Deploy the image to the development environment
echo "Deploying to development environment..."
# Use the image tag from the previous step
echo "Image tag: ${{ steps.build-dev.outputs.image }}"
# Deploy the image to the development environment
ENVIRONMENT=development
KUSTOMIZE_DIR=$(pwd)/infra/kubernetes/development
kubectl get namespaces $ENVIRONMENT || kubectl create namespace $ENVIRONMENT
ENVIRONMENT=development
KUSTOMIZE_DIR=$(pwd)/infra/kubernetes/development
IMAGE_TAG=${{ steps.build-dev.outputs.image }}
kustomize edit set image web=${{ steps.build-dev.outputs.image }}
kubectl apply -k $KUSTOMIZE_DIR -n $ENVIRONMENT
echo "Deploymento to $ENVIRONMENT environment completed!"
kubectl get namespaces $ENVIRONMENT || kubectl create namespace $ENVIRONMENT
IMAGE_TAG=${{ steps.build-dev.outputs.image }}
kustomize edit set image web=${{ steps.build-dev.outputs.image }}
kubectl apply -k $KUSTOMIZE_DIR -n $ENVIRONMENT
echo "Deployment to $ENVIRONMENT environment completed!"
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ This job runs on `ubuntu-latest` and is executed if the event is an issue commen
## Deployment Logic

The deployment logic varies based on the environment:
- **Development Environment**: Triggered by issue comments containing `/deploy-dev`.
- **Production Environment**: Triggered by pushes to the `main` branch.
- **Development Environment**: Triggered by issue comments containing `/deploy-dev`.
- **Production Environment**: Triggered by pushes to the `main` branch.

The deployment process includes:
- Setting the environment and kustomize directory.
- Checking and creating the namespace if it doesn't exist.
- Updating the image in the kustomize configuration.
- Applying the Kubernetes resources using `kubectl`.
- Setting the environment and kustomize directory.
- Checking and creating the namespace if it doesn't exist.
- Updating the image in the kustomize configuration.
- Applying the Kubernetes resources using `kubectl`.

0 comments on commit d3af1ba

Please sign in to comment.