Skip to content

Commit

Permalink
Merge pull request #1 from xogns1514/be-515-DOCKER_IMAGE_TAG_01
Browse files Browse the repository at this point in the history
Be 515 docker image tag 01
  • Loading branch information
xogns1514 authored Aug 19, 2024
2 parents e89876e + 9f5c3e4 commit 4a9e588
Show file tree
Hide file tree
Showing 82 changed files with 1,322 additions and 709 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/be-cd_dev-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ jobs:
JWT_TOKEN_EXPIRE_CYCLE=${{ secrets.JWT_TOKEN_EXPIRE_CYCLE }}
JWT_SIGN_ALGORITHM=${{ secrets.JWT_SIGN_ALGORITHM }}
# Cookie settings
COOKIE_ACCESS_TOKEN_KEY=${{ secrets.COOKIE_ACCESS_TOKEN_KEY }}
COOKIE_HTTP_ONLY=${{ secrets.COOKIE_HTTP_ONLY }}
COOKIE_SECURE=${{ secrets.COOKIE_SECURE }}
COOKIE_DOMAIN=${{ secrets.COOKIE_DOMAIN }}
COOKIE_PATH=${{ secrets.COOKIE_PATH }}
COOKIE_SAME_SITE=${{ secrets.COOKIE_SAME_SITE }}
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
EOF
- name: Stop and remove existing containers
Expand Down
140 changes: 77 additions & 63 deletions .github/workflows/be-cd_prod-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,70 +37,84 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Image build and push
run: |
docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/cruru:prod-latest --platform linux/arm64 .
docker push ${{ secrets.DOCKER_REPO_NAME }}/cruru:prod-latest
- name: Upload docker-compose yaml script to artifact
uses: actions/upload-artifact@v4
with:
name: docker-compose
path: ${{ github.workspace }}/backend/docker-compose.prod.yml
- name: Get current date and time
id: datetime
run: |
echo "datetime=$(date +'%Y-%m-%d_%H:%M:%S')" >> "$GITHUB_OUTPUT"
deploy:
environment: prod
runs-on: [self-hosted, be-prod]
needs: build
defaults:
run:
working-directory: backend
steps:
- name: Set docker-compose YAML script to runner
uses: actions/download-artifact@v4
with:
name: docker-compose
path: ${{ github.workspace }}/backend

- name: Extract secrets as .env file
- name: Image build and push
run: |
cat <<EOF > .env
# Docker Hub info from Github Secrets
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
# DB Configuration secrets info from Github Secrets
DB_PORT=${{ secrets.DB_PORT }}
DB_IP_ADDRESS=${{ secrets.DB_IP_ADDRESS }}
DB_URL=${{ secrets.DB_URL }}
DB_USER=${{ secrets.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DDL_AUTO=${{ secrets.DDL_AUTO }}
docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/cruru:${{ steps.datetime.outputs.datetime }} --platform linux/arm64 .
docker push ${{ secrets.DOCKER_REPO_NAME }}/cruru:${{ steps.datetime.outputs.datetime }}
# DB server configuration secrets info from Github Secrets
APP_IP_ADDRESS=${{ secrets.APP_IP_ADDRESS }}
SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
SERVER_PORT=${{ secrets.SERVER_PORT }}
SUBNET=${{ secrets.SUBNET }}
# Monitoring configuration server info from Github secrets
MONITORING_BINDING_PORT=${{ secrets.MONITORING_BINDING_PORT }}
MONITORING_PORT=${{ secrets.MONITORING_PORT }}
MONITORING_BASE_PATH=${{ secrets.MONITORING_BASE_PATH }}
# Apply configuration server info from Github secrets
APPLY_POST_BASE_URL=${{ secrets.APPLY_POST_BASE_URL }}
# Security settings
JWT_TOKEN_SECRET_KEY=${{ secrets.JWT_TOKEN_SECRET_KEY }}
JWT_TOKEN_EXPIRE_CYCLE=${{ secrets.JWT_TOKEN_EXPIRE_CYCLE }}
JWT_SIGN_ALGORITHM=${{ secrets.JWT_SIGN_ALGORITHM }}
EOF
# - name: Upload docker-compose yaml script to artifact
# uses: actions/upload-artifact@v4
# with:
# name: docker-compose
# path: ${{ github.workspace }}/backend/docker-compose.prod.yml

- name: Stop and remove existing containers
run: |
sudo docker-compose -f docker-compose.prod.yml down --rmi all
- name: Deploy docker container
run: |
sudo docker-compose --env-file .env -f docker-compose.prod.yml up -d
# deploy:
# environment: prod
# runs-on: [self-hosted, be-prod]
# needs: build
# defaults:
# run:
# working-directory: backend
# steps:
# - name: Set docker-compose YAML script to runner
# uses: actions/download-artifact@v4
# with:
# name: docker-compose
# path: ${{ github.workspace }}/backend
#
# - name: Extract secrets as .env file
# run: |
# cat <<EOF > .env
# # Docker Hub info from Github Secrets
# DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
# DOCKER_IMAGE_TAG=${{ steps.datetime.outputs.datetime }}
#
# # DB Configuration secrets info from Github Secrets
# DB_PORT=${{ secrets.DB_PORT }}
# DB_IP_ADDRESS=${{ secrets.DB_IP_ADDRESS }}
# DB_URL=${{ secrets.DB_URL }}
# DB_USER=${{ secrets.DB_USER }}
# DB_PASSWORD=${{ secrets.DB_PASSWORD }}
# DDL_AUTO=${{ secrets.DDL_AUTO }}
#
# # DB server configuration secrets info from Github Secrets
# APP_IP_ADDRESS=${{ secrets.APP_IP_ADDRESS }}
# SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
# SERVER_PORT=${{ secrets.SERVER_PORT }}
# SUBNET=${{ secrets.SUBNET }}
#
# # Monitoring configuration server info from Github secrets
# MONITORING_BINDING_PORT=${{ secrets.MONITORING_BINDING_PORT }}
# MONITORING_PORT=${{ secrets.MONITORING_PORT }}
# MONITORING_BASE_PATH=${{ secrets.MONITORING_BASE_PATH }}
#
# # Apply configuration server info from Github secrets
# APPLY_POST_BASE_URL=${{ secrets.APPLY_POST_BASE_URL }}
#
# # Security settings
# JWT_TOKEN_SECRET_KEY=${{ secrets.JWT_TOKEN_SECRET_KEY }}
# JWT_TOKEN_EXPIRE_CYCLE=${{ secrets.JWT_TOKEN_EXPIRE_CYCLE }}
# JWT_SIGN_ALGORITHM=${{ secrets.JWT_SIGN_ALGORITHM }}
#
# # Cookie settings
# COOKIE_ACCESS_TOKEN_KEY=${{ secrets.COOKIE_ACCESS_TOKEN_KEY }}
# COOKIE_HTTP_ONLY=${{ secrets.COOKIE_HTTP_ONLY }}
# COOKIE_SECURE=${{ secrets.COOKIE_SECURE }}
# COOKIE_DOMAIN=${{ secrets.COOKIE_DOMAIN }}
# COOKIE_PATH=${{ secrets.COOKIE_PATH }}
# COOKIE_SAME_SITE=${{ secrets.COOKIE_SAME_SITE }}
# COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
# EOF
#
# - name: Stop and remove existing containers
# run: |
# sudo docker-compose -f docker-compose.prod.yml down --rmi all
#
# - name: Deploy docker container
# run: |
# sudo docker-compose --env-file .env -f docker-compose.prod.yml up -d
7 changes: 7 additions & 0 deletions backend/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ services:
JWT_TOKEN_SECRET_KEY: ${JWT_TOKEN_SECRET_KEY}
JWT_TOKEN_EXPIRE_CYCLE: ${JWT_TOKEN_EXPIRE_CYCLE}
JWT_SIGN_ALGORITHM: ${JWT_SIGN_ALGORITHM}
COOKIE_ACCESS_TOKEN_KEY: ${COOKIE_ACCESS_TOKEN_KEY}
COOKIE_HTTP_ONLY: ${COOKIE_HTTP_ONLY}
COOKIE_SECURE: ${COOKIE_SECURE}
COOKIE_DOMAIN: ${COOKIE_DOMAIN}
COOKIE_PATH: ${COOKIE_PATH}
COOKIE_SAME_SITE: ${COOKIE_SAME_SITE}
COOKIE_MAX_AGE: ${COOKIE_MAX_AGE}
networks:
cruru_network:
ipv4_address: ${APP_IP_ADDRESS}
Expand Down
7 changes: 7 additions & 0 deletions backend/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ services:
JWT_TOKEN_SECRET_KEY: ${JWT_TOKEN_SECRET_KEY}
JWT_TOKEN_EXPIRE_CYCLE: ${JWT_TOKEN_EXPIRE_CYCLE}
JWT_SIGN_ALGORITHM: ${JWT_SIGN_ALGORITHM}
COOKIE_ACCESS_TOKEN_KEY: ${COOKIE_ACCESS_TOKEN_KEY}
COOKIE_HTTP_ONLY: ${COOKIE_HTTP_ONLY}
COOKIE_SECURE: ${COOKIE_SECURE}
COOKIE_DOMAIN: ${COOKIE_DOMAIN}
COOKIE_PATH: ${COOKIE_PATH}
COOKIE_SAME_SITE: ${COOKIE_SAME_SITE}
COOKIE_MAX_AGE: ${COOKIE_MAX_AGE}
networks:
cruru_network:
ipv4_address: ${APP_IP_ADDRESS}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/java/com/cruru/CruruApplication.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.boot.context.properties.ConfigurationPropertiesScan;

@SpringBootApplication
@ConfigurationPropertiesScan
public class CruruApplication {

public static void main(String[] args) {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/java/com/cruru/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void run(ApplicationArguments args) {
}

private void runDataLoader() {
Member member = new Member("[email protected]", "qwer1234", "01012345678");
Member member = new Member("[email protected]", "$2a$10$rG0JsflKdGcORjGFTURYb.npEgtvClK4.3P.EMr/o3SdekrVFxOvG",
"01012345678"); // password 원문: qwer1234
memberRepository.save(member);
Club club = new Club("우아한테크코스", member);
clubRepository.save(club);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ public ResponseEntity<Void> updateProcess(
}

@PatchMapping("/{applicantId}/reject")
public ResponseEntity<ApplicantAnswerResponses> updateReject(@PathVariable Long applicantId) {
applicantFacade.updateApplicantToReject(applicantId);
public ResponseEntity<ApplicantAnswerResponses> reject(@PathVariable Long applicantId) {
applicantFacade.reject(applicantId);
return ResponseEntity.ok().build();
}

@PatchMapping("/{applicantId}/unreject")
public ResponseEntity<ApplicantAnswerResponses> unreject(@PathVariable Long applicantId) {
applicantFacade.unreject(applicantId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void approve() {
this.state = APPROVED;
}

public void pending() {
public void unreject() {
this.state = PENDING;
}

Expand All @@ -90,6 +90,10 @@ public boolean isRejected() {
return this.state == REJECTED;
}

public boolean isNotRejected() {
return this.state != REJECTED;
}

public Dashboard getDashboard() {
return process.getDashboard();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.applicant.exception.badrequest;

import com.cruru.advice.badrequest.BadRequestException;

public class ApplicantUnrejectException extends BadRequestException {

private static final String MESSAGE = "불합격하지 않은 지원자입니다.";

public ApplicantUnrejectException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.cruru.applicant.exception.ApplicantNotFoundException;
import com.cruru.applicant.exception.badrequest.ApplicantNoChangeException;
import com.cruru.applicant.exception.badrequest.ApplicantRejectException;
import com.cruru.applicant.exception.badrequest.ApplicantUnrejectException;
import com.cruru.process.domain.Process;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -70,6 +71,19 @@ private void validateRejectable(Applicant applicant) {
}
}

@Transactional
public void unreject(long applicantId) {
Applicant applicant = findById(applicantId);
validateUnrejectable(applicant);
applicant.unreject();
}

private void validateUnrejectable(Applicant applicant) {
if (applicant.isNotRejected()) {
throw new ApplicantUnrejectException();
}
}

public ApplicantResponse toApplicantResponse(Applicant applicant) {
return new ApplicantResponse(
applicant.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public void updateApplicantProcess(long processId, ApplicantMoveRequest moveRequ
}

@Transactional
public void updateApplicantToReject(long applicantId) {
public void reject(long applicantId) {
applicantService.reject(applicantId);
}

@Transactional
public void unreject(long applicantId) {
applicantService.unreject(applicantId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cruru.auth.controller;

import com.cruru.auth.controller.dto.LoginRequest;
import com.cruru.auth.service.facade.AuthFacade;
import com.cruru.global.util.CookieManager;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/auth")
@RequiredArgsConstructor
public class AuthController {

private final AuthFacade authFacade;
private final CookieManager cookieManager;

@PostMapping("/login")
public ResponseEntity<Void> login(@RequestBody @Valid LoginRequest request) {
String token = authFacade.login(request);
ResponseCookie cookie = cookieManager.createTokenCookie(token);
return ResponseEntity.ok()
.header(HttpHeaders.SET_COOKIE, cookie.toString())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cruru.auth.controller.dto;

import com.cruru.member.domain.MemberRole;

public record LoginProfile(String email, MemberRole memberRole) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cruru.auth.controller.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

public record LoginRequest(
@Email(message = "이메일의 형식이 올바르지 않습니다.")
String email,

@NotBlank(message = "비밀번호를 입력해주세요.")
String password
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.auth.exception;

import com.cruru.advice.badrequest.BadRequestException;

public class IllegalCookieException extends BadRequestException {

private static final String MESSAGE = "유효하지 않은 쿠키입니다.";

public IllegalCookieException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.cruru.auth.exception;

public class IllegalTokenException extends RuntimeException {
import com.cruru.advice.UnauthorizedException;

public class IllegalTokenException extends UnauthorizedException {

private static final String MESSAGE = "유효하지 않는 토큰입니다.";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.auth.exception;

import com.cruru.advice.UnauthorizedException;

public class LoginFailedException extends UnauthorizedException {

private static final String MESSAGE = "비밀번호가 일치하지 않습니다.";

public LoginFailedException() {
super(MESSAGE);
}
}
Loading

0 comments on commit 4a9e588

Please sign in to comment.