Skip to content

Commit

Permalink
[STMT-6, STMT-151] βœ¨πŸ‘· CI/CDλ₯Ό μœ„ν•œ github actions workflow ꡬ좕 및 νšŒμ›κ°€μž…, λ‘œκ·Έβ€¦
Browse files Browse the repository at this point in the history
…인 api κ΅¬ν˜„ (#21)

* [STMT-151] ✨ κ³΅ν†΅μ μœΌλ‘œ μ‚¬μš©λ˜λŠ” 생성 μ‹œκ°„, μˆ˜μ • μ‹œκ°„ μΆ”κ°€λ₯Ό μœ„ν•œ 좔상 클래슀 κ΅¬ν˜„ (#10)

* [STMT-151] ✨ κ³΅ν†΅μ μœΌλ‘œ μ‚¬μš©λ˜λŠ” 생성 μ‹œκ°„, μˆ˜μ • μ‹œκ°„ μΆ”κ°€λ₯Ό μœ„ν•œ 좔상 클래슀 κ΅¬ν˜„

* [STMT-151] πŸ› μ„€μ • 클래슀λ₯Ό λͺ…μ‹œν•˜μ—¬ μŠ€ν”„λ§ μ»¨ν…μŠ€νŠΈμ—μ„œ κ΄€λ¦¬ν•˜λ„λ‘ μ„€μ •

* [STMT-6] πŸ‘· CI/CDλ₯Ό μœ„ν•œ github-actions μΆ”κ°€

* [STMT-6] πŸ‘· CI/CDλ₯Ό μœ„ν•œ github-actions μΆ”κ°€

* [STMT-151] ✨ λ‘œκ·ΈμΈμ„ μœ„ν•œ 멀버, OAuth 둜그인 정보 λͺ¨λΈλ§ (#11)

* [STMT-6] πŸ› 도컀 μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰ μ „, 이전에 μ‹€ν–‰ μ€‘μ΄λ˜ μ»¨ν…Œμ΄λ„ˆλ₯Ό 쀑지, μ‚­μ œν•˜λ„λ‘ μˆ˜μ • 및 λ‹€μˆ˜μ˜ μ˜€νƒ€ μˆ˜μ •

* [STMT-6] πŸ’š JDK 21 distribution temurin에 λŒ€ν•œ CI/CD μžλ™ν™” ν…ŒμŠ€νŠΈ

* [STMT-6] πŸ‘· CI/CD μžλ™ν™” μ›Œν¬ν”Œλ‘œμš° μ™„μ„±

* [STMT-6] ✏️ 주석 제거

* [STMT-151] ✨ JWT 생성 및 검증 객체 κ΅¬ν˜„ (#14)

* [STMT-151] ✨ JWT 생성 및 검증 객체 κ΅¬ν˜„

* [STMT-151] βž• JWT, OpenFeign, QueryDSL μ˜μ‘΄μ„± μΆ”κ°€

* [STMT-151] ✨ OAuth2 둜그인/νšŒμ›κ°€μž… κΈ°λŠ₯ κ΅¬ν˜„ (#16)

* [STMT-151] πŸ”§ QueryDSL μ„€μ •

* [STMT-151] ✨ API 곡톡 응닡 객체 κ΅¬ν˜„

* [STMT-151] ✨ ν΄λΌμ΄μ–ΈνŠΈμ—κ²Œ 전달받은 Access Token을 μ΄μš©ν•˜μ—¬ kakao에 μœ μ € 정보 μš”μ²­ κΈ°λŠ₯ κ΅¬ν˜„

* [STMT-151] ✨ OAuth 둜그인 정보λ₯Ό κ΄€λ¦¬ν•˜λŠ” 도메인 μ •μ˜

* [STMT-151] ✨ 카카였 μœ μ € 정보 쑰회 응닡 객체 μ •μ˜

* [STMT-151] ✨ OAuth νšŒμ›κ°€μž…/둜그인 κΈ°λŠ₯ ν•„ν„° κ΅¬ν˜„

* [STMT-151] ✨ OAuth νšŒμ›κ°€μž… / 둜그인 인증 ν”„λ‘œλ°”μ΄λ” κ΅¬ν˜„

* [STMT-151] ✨ JWT 인증 ν•„ν„° κ΅¬ν˜„

* [STMT-151] ✨ κΆŒν•œ λΆ€μ‘± 및 미인증 μœ μ €κ°€ μš”μ²­μ‹œ μ˜ˆμ™Έλ°œμƒμ— λŒ€ν•œ μ˜ˆμ™Έ ν•Έλ“€λŸ¬ μΆ”κ°€

* [STMT-151] ✨ κ΅¬ν˜„ν•œ ν•„ν„° μ‹œνλ¦¬ν‹° ν•„ν„° 체인에 등둝

* [STMT-151] ✨ νšŒμ›κ°€μž… 좔가정보 μž…λ ₯ API κ΅¬ν˜„

* [STMT-6] πŸ‘· CI-CD workflow μˆ˜μ • - ν™˜κ²½λ³€μˆ˜ μ„€μ • (#17) (#18)

- 파일 이름 λ³€κ²½
 - github-actions.yml -> ci-cd.yml
- gitignore에 application-secret.properties 파일 μΆ”κ°€

Co-authored-by: zxcv9203 <[email protected]>

* [STMT-6] πŸ‘· ci-cd μ›Œν¬ν”Œλ‘œμš°κ°€ μ‹€νŒ¨ν•˜λŠ” 원인 규λͺ… 및 문제 ν•΄κ²° (#19)

* [STMT-6] πŸ‘· CI-CD workflow μˆ˜μ • - ν™˜κ²½λ³€μˆ˜ μ„€μ • (#17)

- 파일 이름 λ³€κ²½
 - github-actions.yml -> ci-cd.yml
- gitignore에 application-secret.properties 파일 μΆ”κ°€

Co-authored-by: zxcv9203 <[email protected]>

* [STMT-6] ci-cd.yml event trigger μˆ˜μ •

* [STMT-6] ci-cd.yml 문법 였λ₯˜ μˆ˜μ •

step-Checkoutμ—μ„œ uses μ•ž λŒ€μ‰¬ μ‚­μ œ

---------

Co-authored-by: zxcv9203 <[email protected]>

* [STMT-6] πŸ”§ 개발 ν™˜κ²½λ³„ yml μ„€μ • 파일 μž‘μ„± (#20)

Co-authored-by: zxcv9203 <[email protected]>

* [STMT-6] πŸ’š CI/CD dev ν…ŒμŠ€νŠΈ

* [STMT-6] prod μ„€μ •νŒŒμΌλ‘œ λΉŒλ“œν•˜λŠ” μ„€μ • μΆ”κ°€

* [STMT-6] πŸ’š CICD ν…ŒμŠ€νŠΈμš©μœΌλ‘œ event triger에 μΆ”κ°€ν•œ μ½”λ“œ μ‚­μ œ

branch `dev` μ œμ™Έ

* [STMT-6] πŸ”₯ prod μ„€μ • 파일의 security logging μ„€μ • μ½”λ“œ 제거

* [STMT-6] πŸ”₯ ci-cd μ›Œν¬ ν”Œλ‘œμš°μ˜ 디버그 μ½”λ“œ 제거

* [STMT-6] πŸ”₯ ci-cd μ›Œν¬ ν”Œλ‘œμš° μˆ˜μ • - docker compose 배포 λͺ…λ Ήμ–΄

* [STMT-6] πŸš€ docker-compose.yml 생성

---------

Co-authored-by: zxcv9203 <[email protected]>
Co-authored-by: tngtied <[email protected]>
Co-authored-by: tngtied <[email protected]>
  • Loading branch information
4 people authored Feb 16, 2024
1 parent da0ba3a commit 7cec6ea
Show file tree
Hide file tree
Showing 69 changed files with 1,546 additions and 66 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# github repository actions νŽ˜μ΄μ§€μ— λ‚˜νƒ€λ‚  이름
name: CI/CD using github actions & docker

# event trigger
on:
push:
branches: [ "main" ]

permissions:
contents: read

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:

# JDK setting
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: set environment variables
working-directory: ./
run: |
touch src/main/resources/application-secret.properties
echo ${{ secrets.ENV }} >> src/main/resources/application-secret.properties
# gradle caching - λΉŒλ“œ μ‹œκ°„ ν–₯상
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# docker login
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# build gradle
- name: Build gradlew
run: |
chmod +x gradlew
./gradlew jib \
-Djib.from.auth.username=${{ secrets.DOCKER_USERNAME }} \
-Djib.from.auth.password=${{ secrets.DOCKER_PASSWORD }} \
-Dspring.profiles.active=prod
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.AWS_PUBLIC_IP }}
username: ${{ secrets.AWS_USER }}
key: ${{ secrets.AWS_PRIVATE_KEY }}
port: ${{ secrets.AWS_SSH_PORT }}
script: |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/server
sudo docker stop stumeet-server
docker container prune -f
sudo docker-compose up -d --no-deps --force-recreate stumeet-server
sudo docker image prune -f
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

application-secret.properties
38 changes: 33 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'com.google.cloud.tools.jib' version '3.4.0'
}

group = 'com.stumeet'
Expand All @@ -28,23 +29,37 @@ ext {
}

dependencies {
// jwt μ˜μ‘΄μ„± μΆ”κ°€
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.flywaydb:flyway-mysql'
implementation 'org.flywaydb:flyway-core'

annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.springframework.security:spring-security-test'

implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" // 버전 λ³€κ²½
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"


}

dependencyManagement {
Expand All @@ -62,3 +77,16 @@ tasks.named('asciidoctor') {
inputs.dir snippetsDir
dependsOn test
}

jib {
from {
image = "eclipse-temurin:21"
}
to {
image = "stumeet/server"
tags = [version]
}
container {
jvmFlags = ["-Xms128m", "-Xmx128m"]
}
}
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

networks:
server-connection:
driver: bridge

services:
nginx:
container_name: nginx
image: nginx
restart: always
ports:
- '80:80'
- '443:443'
networks:
- server-connection
environment:
- TZ=Asia/Seoul
depends_on:
- stumeet-server

stumeet-server:
container_name: stumeet-server
image: stumeet/server
restart: always
expose:
- '8080'
networks:
- server-connection
2 changes: 2 additions & 0 deletions src/main/java/com/stumeet/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients
public class ServerApplication {

public static void main(String[] args) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/com/stumeet/server/account/domain/Account.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.stumeet.server.common.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;

@Configuration
public class AuthConfig {
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.stumeet.server.common.auth.config;

import com.stumeet.server.common.auth.filter.JwtAuthenticationFilter;
import com.stumeet.server.common.auth.filter.OAuthAuthenticationFilter;
import com.stumeet.server.common.auth.handler.InvalidAuthenticationFailureHandler;
import com.stumeet.server.common.auth.handler.OAuthAuthenticationSuccessHandler;
import com.stumeet.server.common.auth.service.JwtAuthenticationService;
import com.stumeet.server.common.auth.service.OAuthAuthenticationProvider;
import com.stumeet.server.common.token.JwtTokenProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
import org.springframework.security.web.context.SecurityContextRepository;

@Configuration
@RequiredArgsConstructor
public class SecurityConfig {

private final InvalidAuthenticationFailureHandler invalidAuthenticationFailureHandler;
private final OAuthAuthenticationProvider authenticationProvider;
private final AuthenticationManager authenticationManager;
private final JwtTokenProvider jwtTokenProvider;
private final JwtAuthenticationService jwtAuthenticationService;
private final OAuthAuthenticationSuccessHandler oAuthAuthenticationSuccessHandler;
private final AuthenticationEntryPoint authenticationEntryPoint;
private final AccessDeniedHandler accessDeniedHandler;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.formLogin(AbstractHttpConfigurer::disable);
http.rememberMe(AbstractHttpConfigurer::disable);
http.httpBasic(AbstractHttpConfigurer::disable);
http.logout(AbstractHttpConfigurer::disable);
http.csrf(AbstractHttpConfigurer::disable);

http.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin));

http.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

http.authenticationProvider(authenticationProvider);

http.addFilterBefore(new OAuthAuthenticationFilter(invalidAuthenticationFailureHandler, authenticationManager, oAuthAuthenticationSuccessHandler), UsernamePasswordAuthenticationFilter.class);
http.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider, jwtAuthenticationService), UsernamePasswordAuthenticationFilter.class);

http.authorizeHttpRequests(auth -> {
auth.requestMatchers("/api/v1/oauth").permitAll();
auth.requestMatchers("/h2-console/**").permitAll();
auth.requestMatchers("/api/v1/signup").hasAnyAuthority("FIRST_LOGIN");
auth.anyRequest().authenticated();
});

http.securityContext(securityContext -> securityContext.securityContextRepository(securityContextRepository()));

http.exceptionHandling(handler -> {
handler.authenticationEntryPoint(authenticationEntryPoint);
handler.accessDeniedHandler(accessDeniedHandler);
});

return http.build();
}
@Bean
public SecurityContextRepository securityContextRepository() {
return new RequestAttributeSecurityContextRepository();
}
}
Loading

0 comments on commit 7cec6ea

Please sign in to comment.