diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml index 95c95c27..95e8fad5 100644 --- a/.github/workflows/dev-build-deploy.yml +++ b/.github/workflows/dev-build-deploy.yml @@ -55,11 +55,6 @@ jobs: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} -f aics-auth/Dockerfile . docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest - - name: Docker image build for aics-auth - run: | - docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} -f aics-auth/Dockerfile . - docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest - # Docker Hub 이미지 푸시 - name: docker Hub push for aics-admin run: | @@ -76,11 +71,6 @@ jobs: docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest - - name: docker Hub push for aics-auth - run: | - docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest - deploy-to-dev: runs-on: ubuntu-latest needs: build-docker-image @@ -90,7 +80,18 @@ jobs: - name: checkout repository uses: actions/checkout@v3 - - name: SSH to server and deploy + - name: scp docker-compose.yml to server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + port: ${{ secrets.SERVER_PORT }} + source: docker/development/docker-compose.yml + target: ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} + strip_components: 2 + + - name: ssh to server and deploy uses: appleboy/ssh-action@v1.1.0 with: host: ${{ secrets.SERVER_HOST }} @@ -98,12 +99,10 @@ jobs: password: ${{ secrets.SERVER_PASSWORD }} port: ${{ secrets.SERVER_PORT }} script: | - echo "${{ secrets.SERVER_PASSWORD }}" | scp docker/development/docker-compose.yml ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}:${{ secrets.DOCKER_COMPOSE_PATH }} - - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-api - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-admin - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-auth - - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-api - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-admin - echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-auth \ No newline at end of file + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml pull aics-api + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml pull aics-admin + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml pull aics-auth + + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml --env-file ${{ secrets.ENVIRONMENT_PATH }} up -d aics-api + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml --env-file ${{ secrets.ENVIRONMENT_PATH }} up -d aics-admin + echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/docker-compose.yml --env-file ${{ secrets.ENVIRONMENT_PATH }} up -d aics-auth \ No newline at end of file diff --git a/aics-admin/src/main/java/kgu/developers/admin/config/SwaggerConfig.java b/aics-admin/src/main/java/kgu/developers/admin/config/SwaggerConfig.java index 2987eba7..4f9ea564 100644 --- a/aics-admin/src/main/java/kgu/developers/admin/config/SwaggerConfig.java +++ b/aics-admin/src/main/java/kgu/developers/admin/config/SwaggerConfig.java @@ -1,136 +1,96 @@ package kgu.developers.admin.config; +import static java.lang.String.format; + +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.lang.String.format; -import static org.springframework.security.config.Elements.JWT; @Configuration @RequiredArgsConstructor public class SwaggerConfig { - private final Environment environment; - - @Value("${profiles.current-ip}") - private String currentIp; + @Value("${docs.api-docs-url}") + private String apiDocsUrl; - @Value("${profiles.api-port}") - private int apiPort; + @Value("${docs.admin-docs-url}") + private String adminDocsUrl; - @Value("${profiles.admin-api-port}") - private int adminApiPort; + @Value("${docs.auth-docs-url}") + private String authDocsUrl; - @Value("${profiles.auth-api-port}") - private int authApiPort; + private final Environment environment; - private final Map> profileServerConfig = new HashMap<>(); - - @PostConstruct - public void initializeProfileServerConfig() { - profileServerConfig.put("local", Map.of("url", "http://localhost", "port", adminApiPort)); - profileServerConfig.put("dev", Map.of("url", "http://" + currentIp, "port", adminApiPort)); - } + private static final Map PROFILE_SERVER_URL_MAP = Map.of( + "dev", "https://aics-admin.ummdev.com", + "local", "http://localhost:8081" + ); @Bean public OpenAPI openAPI() { return new OpenAPI() .info(apiInfo()) .addSecurityItem(securityRequirement()) - .servers(initializeServers()) - .components(components()); + .components(components()) + .servers(initializeServers()); + } + + private List initializeServers() { + String activeProfile = environment.getActiveProfiles()[0]; + String serverUrl = PROFILE_SERVER_URL_MAP.getOrDefault(activeProfile, "http://localhost:8081"); + return List.of(new Server().url(serverUrl).description("AICS-HOME ADMIN (" + activeProfile + ")")); } private SecurityRequirement securityRequirement() { - return new SecurityRequirement().addList(JWT); + return new SecurityRequirement().addList("bearer"); } private Info apiInfo() { return new Info() - .title("AICS-HOME ADMIN API") + .title("AICS-HOME ADMIN") .description(getDescription()); } - private List initializeServers() { - return profileServerConfig.entrySet().stream() - .filter(entry -> environment.matchesProfiles(entry.getKey())) - .map(entry -> { - String url = (String) entry.getValue().get("url"); - int port = (int) entry.getValue().get("port"); - return openApiServer(url + ":" + port, "AICS-HOME ADMIN API " + entry.getKey().toUpperCase()); - }) - .collect(Collectors.toList()); - } - - private Server openApiServer(String url, String description) { - return new Server().url(url).description(description); - } - private Components components() { - return new Components().addSecuritySchemes(JWT, securityScheme()); + return new Components().addSecuritySchemes("bearer", securityScheme()); } private SecurityScheme securityScheme() { return new SecurityScheme() - .name(JWT) + .name("bearer") .type(SecurityScheme.Type.HTTP) .scheme("bearer") - .bearerFormat(JWT); + .bearerFormat("JWT"); } private String getDescription() { - String activeProfile = getActiveProfile(); return format(""" - AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다. + AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN 입니다. 로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요. 별다른 절차 없이 API를 사용하실 수 있습니다. - 사용자 API 문서는 다음 링크에서 확인하실 수 있습니다.
    -
  • AICS-HOME API : %s
  • -
- - 인증 인가 API 문서는 다음 링크에서 확인하실 수 있습니다. -
    -
  • AICS-HOME AUTH API : %s
  • -
+
  • 사용자 API 문서: %s

  • +
  • 관리자 API 문서: %s

  • +
  • 인증/인가 API 문서: %s
  • + """, - getApiSwaggerByProfile(activeProfile), getApiSwaggerByProfile(activeProfile), - getAuthSwaggerByProfile(activeProfile), getAuthSwaggerByProfile(activeProfile) - ); - } - - private String getAuthSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + authApiPort + "/swagger-ui/index.html"; - } - - private String getApiSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + apiPort + "/swagger-ui/index.html"; - } - - private String getActiveProfile() { - return Arrays.stream(environment.getActiveProfiles()) - .findFirst() - .orElse("local"); + apiDocsUrl, apiDocsUrl, + adminDocsUrl, adminDocsUrl, + authDocsUrl, authDocsUrl); } } diff --git a/aics-admin/src/main/resources/application-dev.yml b/aics-admin/src/main/resources/application-dev.yml index 92a38d5a..e6cd0c09 100644 --- a/aics-admin/src/main/resources/application-dev.yml +++ b/aics-admin/src/main/resources/application-dev.yml @@ -7,9 +7,3 @@ spring: host: ${REDIS_HOST:redis} port: ${REDIS_PORT:6379} password: ${REDIS_PASSWORD} - -profiles: - current-ip: ${CURRENT_IP} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file diff --git a/aics-admin/src/main/resources/application-local.yml b/aics-admin/src/main/resources/application-local.yml index 9cd9787d..d0a6e1fc 100644 --- a/aics-admin/src/main/resources/application-local.yml +++ b/aics-admin/src/main/resources/application-local.yml @@ -2,9 +2,3 @@ spring: jpa: hibernate: ddl-auto: update - -profiles: - current-ip: ${CURRENT_IP:localhost} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file diff --git a/aics-admin/src/main/resources/application.yml b/aics-admin/src/main/resources/application.yml index 1aabfde9..134239b5 100644 --- a/aics-admin/src/main/resources/application.yml +++ b/aics-admin/src/main/resources/application.yml @@ -49,3 +49,8 @@ springdoc: jwt: issuer: ${JWT_ISSUER} secret_key: ${JWT_SECRET_KEY} + +docs: + admin-docs-url: ${ADMIN_DOCS_URL} + api-docs-url: ${API_DOCS_URL} + auth-docs-url: ${AUTH_DOCS_URL} \ No newline at end of file diff --git a/aics-api/src/main/java/kgu/developers/api/config/SwaggerConfig.java b/aics-api/src/main/java/kgu/developers/api/config/SwaggerConfig.java index e93c754f..2e2674c9 100644 --- a/aics-api/src/main/java/kgu/developers/api/config/SwaggerConfig.java +++ b/aics-api/src/main/java/kgu/developers/api/config/SwaggerConfig.java @@ -1,64 +1,60 @@ package kgu.developers.api.config; +import static java.lang.String.format; + +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.lang.String.format; -import static org.springframework.security.config.Elements.JWT; @Configuration @RequiredArgsConstructor public class SwaggerConfig { - private final Environment environment; - - @Value("${profiles.current-ip}") - private String currentIp; + @Value("${docs.api-docs-url}") + private String apiDocsUrl; - @Value("${profiles.api-port}") - private int apiPort; + @Value("${docs.admin-docs-url}") + private String adminDocsUrl; - @Value("${profiles.admin-api-port}") - private int adminApiPort; + @Value("${docs.auth-docs-url}") + private String authDocsUrl; - @Value("${profiles.auth-api-port}") - private int authApiPort; + private final Environment environment; - private final Map> profileServerConfig = new HashMap<>(); - - @PostConstruct - public void initializeProfileServerConfig() { - profileServerConfig.put("local", Map.of("url", "http://localhost", "port", apiPort)); - profileServerConfig.put("dev", Map.of("url", "http://" + currentIp, "port", apiPort)); - } + private static final Map PROFILE_SERVER_URL_MAP = Map.of( + "dev", "https://aics-api.ummdev.com", + "local", "http://localhost:8080" + ); @Bean public OpenAPI openAPI() { return new OpenAPI() .info(apiInfo()) .addSecurityItem(securityRequirement()) - .servers(initializeServers()) - .components(components()); + .components(components()) + .servers(initializeServers()); + } + + private List initializeServers() { + String activeProfile = environment.getActiveProfiles()[0]; + String serverUrl = PROFILE_SERVER_URL_MAP.getOrDefault(activeProfile, "http://localhost:8080"); + return List.of(new Server().url(serverUrl).description("AICS-HOME API (" + activeProfile + ")")); } private SecurityRequirement securityRequirement() { - return new SecurityRequirement().addList(JWT); + return new SecurityRequirement().addList("bearer"); } private Info apiInfo() { @@ -67,72 +63,34 @@ private Info apiInfo() { .description(getDescription()); } - private List initializeServers() { - return profileServerConfig.entrySet().stream() - .filter(entry -> environment.matchesProfiles(entry.getKey())) - .map(entry -> { - String url = (String) entry.getValue().get("url"); - int port = (int) entry.getValue().get("port"); - return openApiServer(url + ":" + port, "AICS-HOME API " + entry.getKey().toUpperCase()); - }) - .collect(Collectors.toList()); - } - - private Server openApiServer(String url, String description) { - return new Server().url(url).description(description); - } - private Components components() { - return new Components().addSecuritySchemes(JWT, securityScheme()); + return new Components().addSecuritySchemes("bearer", securityScheme()); } private SecurityScheme securityScheme() { return new SecurityScheme() - .name(JWT) + .name("bearer") .type(SecurityScheme.Type.HTTP) .scheme("bearer") - .bearerFormat(JWT); + .bearerFormat("JWT"); } private String getDescription() { - String activeProfile = getActiveProfile(); return format(""" - AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다. + AI 컴퓨터공학부 커뮤니티, AICS-HOME API 입니다. 로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요. 별다른 절차 없이 API를 사용하실 수 있습니다. - 관리자 API 문서는 다음 링크에서 확인하실 수 있습니다.
      -
    • AICS-HOME ADMIN API : %s
    • -
    - - 인증 인가 API 문서는 다음 링크에서 확인하실 수 있습니다. -
      -
    • AICS-HOME AUTH API : %s
    • -
    +
  • 사용자 API 문서: %s

  • +
  • 관리자 API 문서: %s

  • +
  • 인증/인가 API 문서: %s
  • + """, - getAdminSwaggerByProfile(activeProfile), - getAdminSwaggerByProfile(activeProfile), - getAuthSwaggerByProfile(activeProfile), - getAuthSwaggerByProfile(activeProfile) - ); - } - - private String getAdminSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + adminApiPort + "/swagger-ui/index.html"; - } - - private String getAuthSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + authApiPort + "/swagger-ui/index.html"; - } - - private String getActiveProfile() { - return Arrays.stream(environment.getActiveProfiles()) - .findFirst() - .orElse("local"); + apiDocsUrl, apiDocsUrl, + adminDocsUrl, adminDocsUrl, + authDocsUrl, authDocsUrl); } } diff --git a/aics-api/src/main/resources/application-dev.yml b/aics-api/src/main/resources/application-dev.yml index 92a38d5a..536196ca 100644 --- a/aics-api/src/main/resources/application-dev.yml +++ b/aics-api/src/main/resources/application-dev.yml @@ -6,10 +6,4 @@ spring: redis: host: ${REDIS_HOST:redis} port: ${REDIS_PORT:6379} - password: ${REDIS_PASSWORD} - -profiles: - current-ip: ${CURRENT_IP} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file + password: ${REDIS_PASSWORD} \ No newline at end of file diff --git a/aics-api/src/main/resources/application-local.yml b/aics-api/src/main/resources/application-local.yml index 9cd9787d..7797cddf 100644 --- a/aics-api/src/main/resources/application-local.yml +++ b/aics-api/src/main/resources/application-local.yml @@ -1,10 +1,4 @@ spring: jpa: hibernate: - ddl-auto: update - -profiles: - current-ip: ${CURRENT_IP:localhost} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file + ddl-auto: update \ No newline at end of file diff --git a/aics-api/src/main/resources/application.yml b/aics-api/src/main/resources/application.yml index 161a775e..8f2ca137 100644 --- a/aics-api/src/main/resources/application.yml +++ b/aics-api/src/main/resources/application.yml @@ -11,12 +11,12 @@ spring: jpa: hibernate: ddl-auto: validate - default_batch_fetch_size: 1000 - jdbc: - time_zone: Asia/Seoul defer-datasource-initialization: true show-sql: true open-in-view: false + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect servlet: multipart: @@ -47,4 +47,7 @@ jwt: issuer: ${JWT_ISSUER} secret_key: ${JWT_SECRET_KEY} - +docs: + admin-docs-url: ${ADMIN_DOCS_URL} + api-docs-url: ${API_DOCS_URL} + auth-docs-url: ${AUTH_DOCS_URL} \ No newline at end of file diff --git a/aics-auth/Dockerfile b/aics-auth/Dockerfile new file mode 100644 index 00000000..cf701408 --- /dev/null +++ b/aics-auth/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:17-jdk-slim +WORKDIR /app +COPY aics-auth/build/libs/*.jar app.jar +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/aics-auth/src/main/java/kgu/developers/auth/config/SwaggerConfig.java b/aics-auth/src/main/java/kgu/developers/auth/config/SwaggerConfig.java index 608fb1dc..581b4632 100644 --- a/aics-auth/src/main/java/kgu/developers/auth/config/SwaggerConfig.java +++ b/aics-auth/src/main/java/kgu/developers/auth/config/SwaggerConfig.java @@ -1,137 +1,96 @@ package kgu.developers.auth.config; +import static java.lang.String.format; + +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.lang.String.format; -import static org.springframework.security.config.Elements.JWT; @Configuration @RequiredArgsConstructor public class SwaggerConfig { - private final Environment environment; - @Value("${profiles.current-ip}") - private String currentIp; + @Value("${docs.api-docs-url}") + private String apiDocsUrl; - @Value("${profiles.api-port}") - private int apiPort; + @Value("${docs.admin-docs-url}") + private String adminDocsUrl; - @Value("${profiles.admin-api-port}") - private int adminApiPort; + @Value("${docs.auth-docs-url}") + private String authDocsUrl; - @Value("${profiles.auth-api-port}") - private int authApiPort; - - private final Map> profileServerConfig = new HashMap<>(); + private final Environment environment; - @PostConstruct - public void initializeProfileServerConfig() { - profileServerConfig.put("local", Map.of("url", "http://localhost", "port", authApiPort)); - profileServerConfig.put("dev", Map.of("url", "http://" + currentIp, "port", authApiPort)); - } + private static final Map PROFILE_SERVER_URL_MAP = Map.of( + "dev", "https://aics-auth.ummdev.com", + "local", "http://localhost:8082" + ); @Bean public OpenAPI openAPI() { return new OpenAPI() .info(apiInfo()) .addSecurityItem(securityRequirement()) - .servers(initializeServers()) - .components(components()); + .components(components()) + .servers(initializeServers()); + } + + private List initializeServers() { + String activeProfile = environment.getActiveProfiles()[0]; + String serverUrl = PROFILE_SERVER_URL_MAP.getOrDefault(activeProfile, "http://localhost:8082"); + return List.of(new Server().url(serverUrl).description("AICS-HOME AUTH (" + activeProfile + ")")); } private SecurityRequirement securityRequirement() { - return new SecurityRequirement().addList(JWT); + return new SecurityRequirement().addList("bearer"); } private Info apiInfo() { return new Info() - .title("AICS-HOME API") + .title("AICS-HOME AUTH") .description(getDescription()); } - private List initializeServers() { - return profileServerConfig.entrySet().stream() - .filter(entry -> environment.matchesProfiles(entry.getKey())) - .map(entry -> { - String url = (String) entry.getValue().get("url"); - int port = (int) entry.getValue().get("port"); - return openApiServer(url + ":" + port, "AICS-HOME API " + entry.getKey().toUpperCase()); - }) - .collect(Collectors.toList()); - } - - private Server openApiServer(String url, String description) { - return new Server().url(url).description(description); - } - private Components components() { - return new Components().addSecuritySchemes(JWT, securityScheme()); + return new Components().addSecuritySchemes("bearer", securityScheme()); } private SecurityScheme securityScheme() { return new SecurityScheme() - .name(JWT) + .name("bearer") .type(SecurityScheme.Type.HTTP) .scheme("bearer") - .bearerFormat(JWT); + .bearerFormat("JWT"); } private String getDescription() { - String activeProfile = getActiveProfile(); return format(""" - AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다. + AI 컴퓨터공학부 커뮤니티 인증/인가, AICS-HOME AUTH 입니다. 로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요. 별다른 절차 없이 API를 사용하실 수 있습니다. - 사용자 API 문서는 다음 링크에서 확인하실 수 있습니다. -
      -
    • AICS-HOME API : %s
    • -
    - - 관리자 API 문서는 다음 링크에서 확인하실 수 있습니다.
      -
    • AICS-HOME ADMIN API : %s
    • -
    +
  • 사용자 API 문서: %s

  • +
  • 관리자 API 문서: %s

  • +
  • 인증/인가 API 문서: %s
  • + """, - getApiSwaggerByProfile(activeProfile), - getApiSwaggerByProfile(activeProfile), - getAdminSwaggerByProfile(activeProfile), - getAdminSwaggerByProfile(activeProfile) - ); - } - - private String getApiSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + apiPort + "/swagger-ui/index.html"; - } - - private String getAdminSwaggerByProfile(String profile) { - String url = (String) profileServerConfig.get(profile).get("url"); - return url + ":" + adminApiPort + "/swagger-ui/index.html"; - } - - private String getActiveProfile() { - return Arrays.stream(environment.getActiveProfiles()) - .findFirst() - .orElse("local"); + apiDocsUrl, apiDocsUrl, + adminDocsUrl, adminDocsUrl, + authDocsUrl, authDocsUrl); } } diff --git a/aics-auth/src/main/resources/application-dev.yml b/aics-auth/src/main/resources/application-dev.yml index 92a38d5a..536196ca 100644 --- a/aics-auth/src/main/resources/application-dev.yml +++ b/aics-auth/src/main/resources/application-dev.yml @@ -6,10 +6,4 @@ spring: redis: host: ${REDIS_HOST:redis} port: ${REDIS_PORT:6379} - password: ${REDIS_PASSWORD} - -profiles: - current-ip: ${CURRENT_IP} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file + password: ${REDIS_PASSWORD} \ No newline at end of file diff --git a/aics-auth/src/main/resources/application-local.yml b/aics-auth/src/main/resources/application-local.yml index 9cd9787d..7797cddf 100644 --- a/aics-auth/src/main/resources/application-local.yml +++ b/aics-auth/src/main/resources/application-local.yml @@ -1,10 +1,4 @@ spring: jpa: hibernate: - ddl-auto: update - -profiles: - current-ip: ${CURRENT_IP:localhost} - api-port: ${API_SERVER_PORT:8080} - admin-api-port: ${ADMIN_API_SERVER_PORT:8081} - auth-api-port: ${AUTH_API_SERVER_PORT:8082} \ No newline at end of file + ddl-auto: update \ No newline at end of file diff --git a/aics-auth/src/main/resources/application.yml b/aics-auth/src/main/resources/application.yml index a81d89cc..ae7f80f2 100644 --- a/aics-auth/src/main/resources/application.yml +++ b/aics-auth/src/main/resources/application.yml @@ -50,4 +50,7 @@ jwt: issuer: ${JWT_ISSUER} secret_key: ${JWT_SECRET_KEY} - +docs: + admin-docs-url: ${ADMIN_DOCS_URL} + api-docs-url: ${API_DOCS_URL} + auth-docs-url: ${AUTH_DOCS_URL} diff --git a/aics-common/src/main/java/kgu/developers/common/config/SecurityConfig.java b/aics-common/src/main/java/kgu/developers/common/config/SecurityConfig.java index d134dcdd..ae59fa4a 100644 --- a/aics-common/src/main/java/kgu/developers/common/config/SecurityConfig.java +++ b/aics-common/src/main/java/kgu/developers/common/config/SecurityConfig.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.Collections; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; @@ -91,7 +92,11 @@ CorsConfigurationSource corsConfigurationSource() { config.setAllowedOriginPatterns(Arrays.asList( "http://localhost:3000", "http://localhost:8080", - "http://localhost:8081" + "http://localhost:8081", + "http://localhost:8082", + "https://aics-api.ummdev.com", + "https://aics-admin.ummdev.com", + "https://aics-auth.ummdev.com" )); config.setAllowCredentials(true); return config; diff --git a/docker/development/docker-compose.yml b/docker/development/docker-compose.yml index 0c730bbc..66f97b2d 100644 --- a/docker/development/docker-compose.yml +++ b/docker/development/docker-compose.yml @@ -6,6 +6,10 @@ services: container_name: aics-api ports: - "${AICS_API_PORT}:8080" + env_file: + - .env + environment: + - SPRING_PROFILES_ACTIVE=dev depends_on: - postgres - redis @@ -17,6 +21,10 @@ services: container_name: aics-admin ports: - "${AICS_ADMIN_PORT}:8081" + env_file: + - .env + environment: + - SPRING_PROFILES_ACTIVE=dev depends_on: - postgres - redis @@ -28,6 +36,10 @@ services: container_name: aics-auth ports: - "${AICS_AUTH_PORT}:8082" + env_file: + - .env + environment: + - SPRING_PROFILES_ACTIVE=dev depends_on: - postgres - redis @@ -40,9 +52,8 @@ services: restart: always ports: - "${POSTGRES_PORT}:5432" - environment: - POSTGRES_USER: ${DB_USERNAME} - POSTGRES_PASSWORD: ${DB_PASSWORD} + env_file: + - .env volumes: - postgres-data:${DB_VOLUME_PATH} networks: @@ -55,6 +66,8 @@ services: command: redis-server ports: - "${REDIS_PORT}:6379" + env_file: + - .env networks: - aics-network