Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git/
.gitignore
*.md
Dockerfile
.dockerignore
10 changes: 10 additions & 0 deletions .github/workflows/hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: hello.yml
on:
push:

jobs:
hello-cd-ci:
runs-on: ubuntu-latest
steps:
- name: Print Hello CI/CD
run: echo "Hello CI/CD"
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#FROM amazoncorretto:21-alpine3.22
#
#WORKDIR /app
#
#COPY target/*.jar app.jar
#
#EXPOSE 8080
#
#ENTRYPOINT ["java","-jar","app.jar"]

#===============================Multi-stage Dockerfile=================================

#Build
FROM maven:3.9-amazoncorretto-21-alpine AS builder

WORKDIR /app

COPY pom.xml .

COPY src ./src

RUN mvn clean test package -DskipTests=false

#Runtime
FROM amazoncorretto:21-alpine3.22 AS runtime

WORKDIR /app

COPY --from=builder /app/target/*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]
13 changes: 0 additions & 13 deletions compose.yaml

This file was deleted.

83 changes: 83 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
services:
postgres:
image: 'postgres:latest'
container_name: postgres_db
environment:
- 'POSTGRES_DB=mydatabase'
- 'POSTGRES_PASSWORD=secret'
- 'POSTGRES_USER=myuser'
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql
- shared_volume:/shared
networks:
- app_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U myuser -d mydatabase"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s

redis:
image: 'redis:latest'
container_name: redis_cache
ports:
- '6379:6379'
volumes:
- redis_data:/data
- shared_volume:/shared
networks:
- app_network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s

devcalc-api:
image: 'shyuu7/devcalc-api:latest'
container_name: devcalc_app
ports:
- '8080:8080'
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- shared_volume:/app/shared
networks:
- app_network
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/mydatabase
- SPRING_DATASOURCE_USERNAME=myuser
- SPRING_DATASOURCE_PASSWORD=secret
- SPRING_REDIS_HOST=redis
- SPRING_REDIS_PORT=6379

test_container:
image: busybox
container_name: connectivity_test
command: sleep 3600
volumes:
- shared_volume:/shared
networks:
- app_network
depends_on:
- postgres
- redis

volumes:
postgres_data:
driver: local
redis_data:
driver: local
shared_volume:
driver: local

networks:
app_network:
driver: bridge
Binary file added evidencias/CalculatorServiceTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/aplicacao rodando pelo docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/apontando tags 1.0.0 para latest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/calculator controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/calculator service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/conectividade com api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/conectividade com redis e postgres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/criacao da imagem docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/erro de build - teste falhando.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/git commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/git push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/healthcheck postgres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/healthcheck redis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/imagens já no dockerhub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added evidencias/subindo imagens para o dockerhub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 25 additions & 74 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,19 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com</groupId>
<artifactId>DevCalc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>DevCalc</name>
<description>DevCalc</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>

<properties>
<java.version>21</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -38,12 +27,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>

<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>runtime</scope>
Expand All @@ -54,65 +42,28 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
62 changes: 58 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,65 @@ O projeto utiliza **Apache Maven** como ferramenta de build e gerenciamento de d
```bash
mvn clean
```
4. **Acesse a API**

### Opção 2: usando Docker

Pré-requisitos:
- Docker instalado
- Docker Compose instalado

Executar apenas a API:
1. Pull da imagem do Docker Hub:
```bash
docker pull shyuu7/devcalc:latest
```
2. Executar o container:
```bash
docker run -d -p 8080:8080 shyuu7/devcalc:latest
```

Executar ambiente completo com Docker Compose:
1. Clone o repositório:
```bash
git clone https://github.com/Shyuu7/devcalc-api.git
cd devcalc-api
```
2. Iniciar os serviços:
```bash
docker-compose up -d
```
3. Verificar os containers em execução:
```bash
docker ps
```
4. Parar os serviços:
```bash
docker-compose down
```
5. Parar e remover todos os containers, redes e volumes:
```bash
docker-compose down -v
```


### **Acesse a API**

Independente do método de execução escolhido, a API estará disponível em:

URL: http://localhost:8080

Swagger UI: http://localhost:8080/swagger-ui/index.html

A API estará disponível em `http://localhost:8080`.

### **Teste os endpoints**

5. **Teste os endpoints**
Você pode testar os endpoints usando:
- Swagger UI - Interface web disponível na página principal
- Curl - Comandos HTTP via terminal
- Postman - Cliente REST gráfico
- Container de teste - Para verificar conectividade interna

Você pode testar os endpoints usando ferramentas como Postman ou cURL.
Exemplo de comando curl para somar dois números:
```bash
curl -X GET "http://localhost:8080/api/calc/sum?a=5&b=3" -H "accept: application/json"
```
23 changes: 23 additions & 0 deletions src/main/java/com/devcalc/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.devcalc.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.Contact;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("DevCalc API")
.version("1.0.0")
.description("API REST para operações matemáticas básicas")
.contact(new Contact()
.name("DevCalc Team")
.url("https://github.com/Shyuu7/devcalc-api")));
}
}
Loading