Skip to content

Commit

Permalink
🔀 Merge pull request #25 from FusionTech-2430/release
Browse files Browse the repository at this point in the history
🚀 production release v1.0
  • Loading branch information
Estebans441 authored Nov 18, 2024
2 parents 8c2a478 + 9908308 commit 0753241
Show file tree
Hide file tree
Showing 36 changed files with 1,063 additions and 47 deletions.
44 changes: 15 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Build Project
on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "develop", "release" ]

jobs:
build:

Build:
runs-on: self-hosted

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.DATASOURCE_URL }}
DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }}
run: mvn clean install
- 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
36 changes: 36 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy Develop
on:
pull_request:
branches:
- develop
types:
- closed
workflow_dispatch:
jobs:
Deploy:
name: Deploy on Develop
if: ${{ github.event.pull_request.merged == true }}
runs-on: self-hosted
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.HOSTS_USERNAME }}
key: ${{ secrets.DEV_SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd AllConnected/${{ github.event.repository.name }}
echo "Fetching latest code..."
git fetch
git checkout develop
git pull
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
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..."
rm .env
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_G1_HOST }}
username: ${{ secrets.HOSTS_USERNAME }}
key: ${{ secrets.PROD_G1_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=prod1" >> .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
36 changes: 36 additions & 0 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy QA
on:
pull_request:
branches:
- release
types:
- closed
workflow_dispatch:
jobs:
Deploy:
name: Deploy on QA
if: ${{ github.event.pull_request.merged == true }}
runs-on: self-hosted
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.QA_G1_HOST }}
username: ${{ secrets.HOSTS_USERNAME }}
key: ${{ secrets.QA_G1_SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd AllConnected/${{ github.event.repository.name }}
echo "Fetching latest code..."
git fetch
git checkout release
git pull
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
echo "PROFILE=qa1" >> .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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ build/

### VS Code ###
.vscode/

### Firebase ###
spring-firebase-key.json

### Enviroment variables ###
.env
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Etapa 1: Build
FROM maven:3.9.4-eclipse-temurin-21 AS build

WORKDIR /app

# Copiar el pom y código fuente
COPY pom.xml ./
RUN mvn dependency:go-offline

COPY src ./src

RUN mvn clean package -DskipTests

# Etapa 2: Run
FROM eclipse-temurin:21-jdk-jammy

WORKDIR /app

# Copiar el jar generado desde la etapa de build
COPY --from=build /app/target/*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ Microservicio encargado del CRUD de usuarios de la aplicación AllConnected

Para ejecutar este proyecto, necesitarás agregar las siguientes variables de entorno a tu archivo .env

`DATASOURCE_URL`
### Conexion a la base de datos

`DATASOURCE_URL`
`DATASOURCE_USERNAME`

`DATASOURCE_PASSWORD`

### Configuración de Firebase
Estas variables son extraidas del archivo de configuración de Firebase en formato JSON

`GOOGLE_ADMIN_CONFIG_TYPE`
`GOOGLE_ADMIN_CONFIG_PROJECT_ID`
`GOOGLE_ADMIN_CONFIG_PRIVATE_KEY`
`GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID`
`GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL`
`GOOGLE_ADMIN_CONFIG_CLIENT_ID`
`GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL`

---
## Ejecutar Localmente 💻

Expand Down Expand Up @@ -54,6 +65,23 @@ Inicia el servidor
mvn spring-boot:run
```

---
## Ejecutar con Docker 🐋

```bash
git clone https://github.com/FusionTech-2430/users-service
```

Ve al directorio del proyecto

```bash
cd users-service
```

```bash
docker-compose up
```

---

## Autores 🧑🏻‍💻
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.8'

services:
spring-app:
build: .
ports:
- "8080:8080"
env_file:
- .env
environment:
- DATASOURCE_URL=${DATASOURCE_URL}
- DATASOURCE_USERNAME=${DATASOURCE_USERNAME}
- DATASOURCE_PASSWORD=${DATASOURCE_PASSWORD}
- GOOGLE_ADMIN_CONFIG_TYPE=${GOOGLE_ADMIN_CONFIG_TYPE}
- GOOGLE_ADMIN_CONFIG_PROJECT_ID=${GOOGLE_ADMIN_CONFIG_PROJECT_ID}
- GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY}
- GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID}
- GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL}
- GOOGLE_ADMIN_CONFIG_CLIENT_ID=${GOOGLE_ADMIN_CONFIG_CLIENT_ID}
- GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL=${GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL}
34 changes: 33 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 All @@ -64,6 +71,14 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</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-starter-test</artifactId>
Expand All @@ -74,6 +89,23 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- FIREBASE DEPENDENCIES -->
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>9.1.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.11.0</version>
</dependency>
<!-- FILENAME -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package co.allconnected.fussiontech.usersservice.config;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.gson.Gson;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.io.IOException;

@Configuration
public class FirebaseConfig {

private final FirebaseConfigProperties firebaseConfigProperties;

public FirebaseConfig(FirebaseConfigProperties firebaseConfigProperties) {
this.firebaseConfigProperties = firebaseConfigProperties;
}

@PostConstruct
public FirebaseApp initializeFirebase() throws IOException {
firebaseConfigProperties.setPrivate_key(
firebaseConfigProperties.getPrivate_key().replace("\\n", "\n")
);

String json = new Gson().toJson(firebaseConfigProperties);

GoogleCredentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(json.getBytes()));

FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(credentials)
.setStorageBucket(firebaseConfigProperties.getProject_id()+".appspot.com")
.build();

if(FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
}

return FirebaseApp.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.allconnected.fussiontech.usersservice.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "firebase")
@Data
public class FirebaseConfigProperties {
private String type;
private String project_id;
private String private_key;
private String private_key_id;
private String client_email;
private String client_id;
private String auth_uri;
private String token_uri;
private String auth_provider_x509_cert_url;
private String client_x509_cert_url;
private String universe_domain;
}
Loading

0 comments on commit 0753241

Please sign in to comment.