[Gena Co.] Internship Project/GENA Labeling Tool

(25.03.14) Docker Compose 설정 & Swagger 세팅

Genie; 2025. 3. 18. 19:03

Docker Compose 설정

...
  mysql:
    image: mysql:8.3
    container_name: datalabeling_mysql
    command: mysqld --default-authentication-plugin=mysql_native_password
    ports:
      - 3306:3306
      - 33060:33060
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
      interval: 10s
      retries: 5
      timeout: 5s
    environment:
      MYSQL_ROOT_USER: root
      MYSQL_USER: genamyqluser
      MYSQL_DATABASE: datalabeling
    env_file: "db.env"
    volumes:
      - testbed_mysql_data:/var/lib/mysql
      - ./my_sql/init:/docker-entrypoint-initdb.d
    platform: linux/amd64
    networks:
      - app-network
...
  java-app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: labeling_app
    ports:
      - 8080:8080
    env_file: "db.env"
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - app-network

...
CREATE DATABASE datalabeling;
  • 컨테이너의 /docker-entrypoint-initdb.d 경로에 호스트 시스템의 ./my_sql/backup 경로에 있는 SQL 파일을 실행
  • SQL DB를 구성을 하고 테이블을 생성할 수 있도록 세팅

Swagger Setting 설정

@Configuration
public class SwaggerConfig {
        @Bean
        public OpenAPI openAPI() {
                return new OpenAPI()
                        .components(new Components())
                        .info(apiInfo());
        }

        private io.swagger.v3.oas.models.info.Info apiInfo() {
                return new Info()
                        .title("Text2SQL Data Labeling & Management API")
                        .description("This API provides endpoints for data labeling, annotation, and management in a Text2SQL system.")
                        .version("1.0.0");
        }
}

 

  • LabelingTool description 과 함께 title을 지정
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/labels")
public class LabelController {

    private final LabelService labelService;

    @Operation(
            summary = "Create labels",
            description = "Create new labels based on the provided label list.",
            responses = {
                    @ApiResponse(responseCode = "201", description = "Labels created successfully",
                            content = @Content(mediaType = "application/json",
                                    schema = @Schema(implementation = DataResponseDto.class))),
                    @ApiResponse(responseCode = "400", description = "Invalid input")
            }
    )
    @PostMapping("")
    public ResponseEntity<DataResponseDto> createLabels(@Valid @RequestBody LabelListRequestDto requestDto) {
        DataResponseDto dataResponseDto = labelService.createLabels(requestDto);
        return new ResponseEntity<>(dataResponseDto, HttpStatus.CREATED);
    }

    @Operation(
            summary = "Get label by ID",
            description = "Retrieve a label by its unique ID.",
            responses = {
                    @ApiResponse(responseCode = "200", description = "Label found",
                            content = @Content(mediaType = "application/json",
                                    schema = @Schema(implementation = LabelDataResponseDto.class))),
                    @ApiResponse(responseCode = "404", description = "Label not found")
            }
    )
    @GetMapping("/{id}")
    public ResponseEntity<LabelDataResponseDto> getLabelById(@Parameter(description = "Label ID") @PathVariable String id) {
        LabelDataResponseDto responseDto = labelService.getLabelById(id);
        return new ResponseEntity<>(responseDto, HttpStatus.OK);
    }
    
    ...

  • @Operation @ApiResponse 를 활용해서 Springdoc OpenAPI 를 주입해서 Swagger 세팅