Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build & Push Docker Image to GHCR (develop)

on:
push:
branches:
- develop

jobs:
build:
# runs-on: self-hosted
runs-on: ubuntu-latest

env:
IMAGE_NAME: ghcr.io/kteventee/eventee-auth-service

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set image tag
run: |
echo "IMAGE_TAG=develop-${GITHUB_SHA::7}" >> $GITHUB_ENV

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

- name: Configure Gradle for GitHub Packages
run: |
mkdir -p ~/.gradle
cat <<EOF > ~/.gradle/gradle.properties
gpr.user=${{ github.actor }}
gpr.token=${{ secrets.COMMON_TOKEN_GITHUB }}
EOF

- name: Grant execute permission for Gradlew
run: chmod +x ./gradlew

- name: Build JAR
run: ./gradlew clean bootJar --no-daemon


- name: Login to GHCR
run: |
echo "${{ secrets.GHCR_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Build & Push Docker image
run: |
docker build -t $IMAGE_NAME:${IMAGE_TAG} .
docker push $IMAGE_NAME:${IMAGE_TAG}

# update GitOps
- name: Install kustomize
run: |
curl -s https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh | bash
sudo mv kustomize /usr/local/bin

- name: Checkout GitOps repo
uses: actions/checkout@v4
with:
repository: KTEventee/eventee-gitops
token: ${{ secrets.GITOPS_TOKEN }}
path: gitops

- name: Update auth image tag in GitOps
run: |
cd gitops/dev/auth
kustomize edit set image REPLACE_IMAGE_AUTH=$IMAGE_NAME:${IMAGE_TAG}

- name: Commit & push GitOps change
run: |
cd gitops
git config user.name "eventee-develop-ci"
git config user.email "[email protected]"
git commit -am "(chore/dev): deploy auth ${IMAGE_TAG}"
git push origin main
85 changes: 85 additions & 0 deletions .github/workflows/prod-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build & Push Docker Image to ECR (build and push prod)

on:
pull_request:
branches:
- prod
types:
- closed

permissions:
contents: read

jobs:
build:
environment: prod
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

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

- name: Configure Gradle for GitHub Packages
run: |
mkdir -p ~/.gradle
cat <<EOF > ~/.gradle/gradle.properties
gpr.user=${{ github.actor }}
gpr.token=${{ secrets.COMMON_TOKEN_GITHUB }}
EOF

- name: Grant execute permission for Gradlew
run: chmod +x ./gradlew

- name: Build JAR
run: ./gradlew clean bootJar --no-daemon

- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Generate image tag
id: image
run: |
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
echo "tag=sha-${SHORT_SHA}" >> $GITHUB_OUTPUT

- name: Build and Push Image
run: |
docker build -t ${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:${{ steps.image.outputs.tag }} .
docker push ${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:${{ steps.image.outputs.tag }}

- name: Notify GitOps repo (deploy prod)
if: success()
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITOPS_TOKEN }}" \
https://api.github.com/repos/KTEventee/eventee-gitops/dispatches \
-d '{
"event_type": "deploy-prod",
"client_payload": {
"service" : "auth",
"image": "'"${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY"'",
"tag": "'"${{ steps.image.outputs.tag }}"'"
}
}'


5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ out/

### VS Code ###
.vscode/
.DS_Store
gradle.properties

src/main/resources/application-local.properties
docker-compose.yml
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM amazoncorretto:17-alpine3.22

RUN addgroup -S app && adduser -S app -G app
WORKDIR /home/app
COPY build/libs/*.jar app.jar

RUN chown -R app:app /home/app
USER app

ENTRYPOINT ["java", "-jar", "app.jar"]
49 changes: 48 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '4.0.0'
id 'org.springframework.boot' version '3.2.6'
id 'io.spring.dependency-management' version '1.1.7'
}

Expand All @@ -19,11 +19,58 @@ repositories {
}

dependencies {
// 공통 모듈
implementation "eventee.server:common:v0.5.0"

// 스프링 스타터
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// 롬복
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

//jwt
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.5'

//oauth
// implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

//swagger
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0"

//postgres
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql:42.7.3'
runtimeOnly 'org.postgresql:postgresql'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'

// WebClientt
implementation 'org.springframework.boot:spring-boot-starter-webflux'


}

tasks.named('test') {
useJUnitPlatform()
}

repositories {
maven {
name = 'GitHubPackages'
url = uri("https://maven.pkg.github.com/KTEventee/eventee-common") // GitHub 리포지토리 URL
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("COMMON_USERNAME_GITHUB")
password = project.findProperty("gpr.token") ?: System.getenv("COMMON_TOKEN_GITHUB")
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/eventee/server/auth/client/MemberApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eventee.server.auth.client;

import eventee.server.auth.client.dto.InternalGoogleLoginRequest;
import eventee.server.auth.client.dto.InternalMemberResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;


@Component
@RequiredArgsConstructor
public class MemberApiClient {

private final WebClient memberWebClient;

public InternalMemberResponse findOrCreateByGoogle(
InternalGoogleLoginRequest request
) {
return memberWebClient.post()
.uri("/internal/members/google")
.bodyValue(request)
.retrieve()
.bodyToMono(InternalMemberResponse.class)
.block();
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package eventee.server.auth.client.dto;

public record InternalGoogleLoginRequest(
String socialId,
String email,
String nickname
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package eventee.server.auth.client.dto;

public record InternalMemberResponse(
Long memberId,
boolean isNew
) {}
19 changes: 19 additions & 0 deletions src/main/java/eventee/server/auth/config/WebClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package eventee.server.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class WebClientConfig {

@Bean
public WebClient memberWebClient(
@Value("${member.service.base-url}") String memberBaseUrl
) {
return WebClient.builder()
.baseUrl(memberBaseUrl)
.build();
}
}
Loading