Skip to content

Commit

Permalink
🔀 Merge pull request #10 from FusionTech-2430/release
Browse files Browse the repository at this point in the history
🚀 Release v1.0
  • Loading branch information
Estebans441 authored Nov 18, 2024
2 parents 6f7bdee + 3e41f99 commit 7324f99
Show file tree
Hide file tree
Showing 38 changed files with 1,227 additions and 124 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build Project
on:
pull_request:
branches: [ "main", "develop", "release" ]

jobs:
Build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Build with Maven
env:
CONFIG_IP: ${{ secrets.DEV_INTEG_HOST }}
run: mvn clean install
49 changes: 8 additions & 41 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
name: Deploy Develop
on:
push:
branches: ["develop"]
pull_request:
branches: ["develop"]
branches:
- develop
types:
- closed
workflow_dispatch:
jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Maven
run: sudo apt-get install -y maven
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"
cache: maven
- name: Build with Maven
env:
DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }}
DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }}
DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }}
GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}
GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}
GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}
GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}
GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}
GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}
GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}
run: mvn clean install

deploy:
Deploy:
name: Deploy on Develop
if: ${{ github.event.pull_request.merged == true }}
runs-on: self-hosted
needs: Build
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
Expand All @@ -53,16 +28,8 @@ jobs:
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env
echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env
echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env
echo "PROFILE=dev" >> .env
echo "CONFIG_IP=10.43.101.114" >> .env
docker rm -f ${{ github.event.repository.name }}
docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }}
echo "Docker container running..."
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy PROD
on:
push:
tags:
- '*'
workflow_dispatch:
jobs:
Deploy:
name: Deploy on PROD
runs-on: self-hosted
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_G2_HOST }}
username: ${{ secrets.HOSTS_USERNAME }}
key: ${{ secrets.PROD_G2_SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd AllConnected/${{ github.event.repository.name }}
echo "Fetching latest code..."
git fetch
git checkout main
git pull
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
echo "PROFILE=prod2" >> .env
echo "CONFIG_IP=10.43.101.72" >> .env
docker rm -f ${{ github.event.repository.name }}
docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }}
echo "Docker container running..."
rm .env
49 changes: 8 additions & 41 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
name: Deploy QA
on:
push:
branches: ["release"]
pull_request:
branches: ["release"]
branches:
- release
types:
- closed
workflow_dispatch:
jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Maven
run: sudo apt-get install -y maven
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "temurin"
cache: maven
- name: Build with Maven
env:
DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }}
DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }}
DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }}
GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}
GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}
GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}
GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}
GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}
GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}
GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}
run: mvn clean install

Deploy:
name: Deploy on QA
if: ${{ github.event.pull_request.merged == true }}
runs-on: self-hosted
needs: Build
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
Expand All @@ -53,17 +28,9 @@ jobs:
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_G2_URL }}/${{ secrets.DB_NAME }}" >> .env
echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env
echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env
echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env
echo "PROFILE=qa2" >> .env
echo "CONFIG_IP=10.43.100.223" >> .env
docker rm -f ${{ github.event.repository.name }}
docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }}
echo "Docker container running..."
rm .env
rm .env
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package co.allconnected.fussiontech.productsservice.controllers;

import co.allconnected.fussiontech.productsservice.dtos.LabelDTO;
import co.allconnected.fussiontech.productsservice.dtos.Response;
import co.allconnected.fussiontech.productsservice.services.LabelService;
import co.allconnected.fussiontech.productsservice.utils.OperationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/labels")
public class LabelsController {
private final LabelService labelService;

@Autowired
public LabelsController(LabelService labelService) {
this.labelService = labelService;
}

@PostMapping
public ResponseEntity<LabelDTO> createLabel(@RequestParam String name) {
try {
if (name == null || name.trim().isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); // Manejo del error si 'name' es nulo o vacío
}
LabelDTO labelDTO = labelService.createLabel(name);
return ResponseEntity.status(HttpStatus.CREATED).body(labelDTO);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@PutMapping("/{id}")
public ResponseEntity<?> updateLabel(@PathVariable String id, @RequestParam String name) {
try {
return ResponseEntity.status(HttpStatus.OK).body(labelService.updateLabel(id, name));
} catch (OperationException e) {
return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()));
}
}
@GetMapping("/{id}")
public ResponseEntity<?> getLabel(@PathVariable String id) {
try {
return ResponseEntity.status(HttpStatus.OK).body(labelService.getLabel(id));
} catch (OperationException e) {
return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()));
}
}

@GetMapping()
public ResponseEntity<?> getLabels() {
try {
LabelDTO[] listLabelsDTO = labelService.getLabels();
return ResponseEntity.status(HttpStatus.OK).body(listLabelsDTO);
} catch (OperationException e) {
return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage()));
} catch (RuntimeException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()));
}
}

@DeleteMapping("/{id}")
public ResponseEntity<?> deleteLabel(@PathVariable String id) {
try {
labelService.deleteLabel(id);
return ResponseEntity.status(HttpStatus.OK).body(new Response(HttpStatus.OK.value(), "Label deleted"));
} catch (OperationException e) {
return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage()));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()));
}
}
}
Loading

0 comments on commit 7324f99

Please sign in to comment.