Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
60f09dc
fix: CI/CD 빌드 파일 중복 수정
LeeShinHaeng Feb 5, 2025
a53f99c
fix: Dockerfile 추가
LeeShinHaeng Feb 5, 2025
e04b744
fix: Dockerfile 경로 오타 수정
LeeShinHaeng Feb 5, 2025
6ca4a5d
fix: CD 파일 줄바꿈 수정
LeeShinHaeng Feb 5, 2025
7536760
fix: CD 복구 및 수정
LeeShinHaeng Feb 5, 2025
ae109d5
chore: scp 명령어 ~ 추가
LeeHanEum Feb 5, 2025
2a67cce
chore: sudo 명령어 삭제
LeeHanEum Feb 5, 2025
8d00cc9
chore: docker-compose.yml 파일 명시
LeeHanEum Feb 5, 2025
18815e1
chore: sshpass로 변경
LeeHanEum Feb 5, 2025
19f3436
chore: github.workspace 환경변수 추가
LeeHanEum Feb 5, 2025
171e21f
chore: target 경로 명시
LeeHanEum Feb 5, 2025
6569c6a
chore: hibernate.dialect 설정 추가
LeeHanEum Feb 5, 2025
61a4e3f
chore: .env 경로 명시
LeeHanEum Feb 5, 2025
96d9d5f
chore: .env 경로 환경변수화
LeeHanEum Feb 5, 2025
e41e03c
chore: IAM 계정으로 변경
LeeHanEum Feb 5, 2025
e7f85da
chore: scp로 오타 수정
LeeHanEum Feb 5, 2025
2fe62e6
chore: strip_components 설정
LeeHanEum Feb 5, 2025
7448269
chore: strip_components 2로 변경
LeeHanEum Feb 5, 2025
0fe6203
chore: docker-compose.yml 환경변수 경로 설정 추가
LeeHanEum Feb 5, 2025
2e1a1c6
chore: dev 스웨거 설정
LeeHanEum Feb 5, 2025
9e462e3
chore: CORS 버그 픽스
LeeHanEum Feb 5, 2025
e43198f
chore: CORS 버그 픽스
LeeHanEum Feb 5, 2025
8598e31
chore: https --> http로 수정
LeeHanEum Feb 5, 2025
568255c
chore: swagger generated url 픽스
LeeHanEum Feb 5, 2025
6171aee
chore: 프로파일에 따라 generated url 동적 생성
LeeHanEum Feb 5, 2025
a499afd
chore: SecurityConfig CORS 설정 추가
LeeHanEum Feb 5, 2025
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
39 changes: 19 additions & 20 deletions .github/workflows/dev-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -90,20 +80,29 @@ 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 }}
username: ${{ secrets.SERVER_USERNAME }}
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
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
Original file line number Diff line number Diff line change
@@ -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<String, Map<String, Object>> 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<String, String> 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<Server> 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<Server> 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 문서는 다음 링크에서 확인하실 수 있습니다.
<ul>
<li>AICS-HOME API : <a href="%s" target="_blank">%s</a></li>
</ul>

인증 인가 API 문서는 다음 링크에서 확인하실 수 있습니다.
<ul>
<li>AICS-HOME AUTH API : <a href="%s" target="_blank">%s</a></li>
</ul>
<li>사용자 API 문서: <a href="%s" target="_blank">%s</a></li><br>
<li>관리자 API 문서: <a href="%s" target="_blank">%s</a></li><br>
<li>인증/인가 API 문서: <a href="%s" target="_blank">%s</a></li>
</ul>
""",
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);
}
}
6 changes: 0 additions & 6 deletions aics-admin/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
6 changes: 0 additions & 6 deletions aics-admin/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
5 changes: 5 additions & 0 deletions aics-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Loading