diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..5b3a728 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,60 @@ +# 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: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + # jdk 11 세팅 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + + # 패키징 + - name: Build with Maven + run: mvn -B package --file pom.xml + + # 도커 로그인 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # 도커 이미지 빌드 + - name: Build the Docker image + run: docker build -t 10m24s/eureka . + + # 이미지 띄우기 + - name: push Docker image + run: docker push 10m24s/eureka + + # 쉘 스크립트 실행 + - name: execute shell script + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_IP }} + username: ${{ secrets.SSH_ID }} + key: ${{ secrets.SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script_stop: true + script: "./startup.sh" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..760cca0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM eclipse-temurin:11 +ARG JAR_FILE=./target/*.jar +COPY ${JAR_FILE} app.jar +COPY src/main/resources/application-prod.properties application-prod.properties + +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/src/main/java/store/mybooks/eureka/EurekaApplication.java b/src/main/java/store/mybooks/eureka/EurekaApplication.java index 5ec8fba..a3c6070 100644 --- a/src/main/java/store/mybooks/eureka/EurekaApplication.java +++ b/src/main/java/store/mybooks/eureka/EurekaApplication.java @@ -2,12 +2,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; +@EnableEurekaServer @SpringBootApplication public class EurekaApplication { - public static void main(String[] args) { - SpringApplication.run(EurekaApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(EurekaApplication.class, args); + } } diff --git a/src/main/java/store/mybooks/eureka/config/SecurityConfig.java b/src/main/java/store/mybooks/eureka/config/SecurityConfig.java new file mode 100644 index 0000000..b4c63c2 --- /dev/null +++ b/src/main/java/store/mybooks/eureka/config/SecurityConfig.java @@ -0,0 +1,36 @@ +package store.mybooks.eureka.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.SecurityFilterChain; + +/** + * packageName : store.mybooks.eureka.config + * fileName : SecurityConfig + * author : minsu11 + * date : 2/16/24 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2/16/24 minsu11 최초 생성 + */ +@EnableWebSecurity(debug = false) +@Configuration +public class SecurityConfig { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http + .csrf() + .disable() + .authorizeRequests() + .anyRequest().authenticated() + .and() + .httpBasic(); + + return http.build(); + + } +} diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..f1e92c9 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,6 @@ +spring.security.user.name=admin +spring.security.user.password=1234 +server.port=5050 +eureka.server.my-url=eureka +eureka.client.service-url.defaultZone=\ + http://${spring.security.user.name}:${spring.security.user.password}@localhost:${server.port}/${eureka.server.my-url} diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..f2d79d1 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,5 @@ +spring.security.user.name=admin +spring.security.user.password=chzhvkdlrkwhgdkdy!12 +server.port=5050 +eureka.server.my-url=eureka +eureka.client.service-url.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@180.210.82.248:${server.port}/${eureka.server.my-url}/ diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..6442fd5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,5 @@ - +server.shutdown=graceful +spring.lifecycle.timeout-per-shutdown-phase=10s +eureka.client.register-with-eureka=false +eureka.client.fetch-registry=false +spring.profiles.active=dev