Skip to content

Commit 0a86373

Browse files
authored
Merge pull request #33 from 2024-Java-Study/jihyun_deploy/#30
[Deploy] Action Script와 Dockerfile
2 parents c2203fb + 8bca33f commit 0a86373

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Passionate Pro Deployment
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
deploy:
12+
name: Deploy
13+
runs-on: ubuntu-latest
14+
env:
15+
AWS_REGION: ap-northeast-2
16+
working-directory: ./pro
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Setup Java JDK
23+
uses: actions/[email protected]
24+
with:
25+
java-version: '17'
26+
distribution: 'temurin'
27+
28+
- name: make application.yml
29+
if: true
30+
run: |
31+
touch ./src/main/resources/application.yml
32+
echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.yml
33+
shell: bash
34+
working-directory: ${{ env.working-directory }}
35+
36+
- name: Gradle execute permission for gradlew
37+
run: chmod +x gradlew
38+
shell: bash
39+
working-directory: ${{ env.working-directory }}
40+
41+
- name: Build with Gradle
42+
run: ./gradlew bootjar
43+
shell: bash
44+
working-directory: ${{ env.working-directory }}
45+
46+
- name: DockerHub Login
47+
uses: docker/login-action@v2
48+
with:
49+
username: ${{ secrets.DOCKERHUB_USERNAME }}
50+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
51+
52+
- name: Docker Image Build
53+
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} .
54+
55+
- name: DockerHub Push
56+
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
57+
58+
- name: Application Run
59+
uses: appleboy/[email protected]
60+
with:
61+
host: ${{ secrets.EC2_HOST }}
62+
username: ${{ secrets.EC2_USERNAME }}
63+
key: ${{ secrets.EC2_KEY }}
64+
65+
script: |
66+
sudo docker kill ${{ secrets.PROJECT_NAME }}
67+
sudo docker rm -f ${{ secrets.PROJECT_NAME }}
68+
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
69+
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
70+
sudo docker run -p 8080:8080 --name ${{ secrets.PROJECT_NAME }}

pro/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM openjdk:17-alpine
2+
ARG JAR_FILE=build/libs/pro-0.0.1-SNAPSHOT.jar
3+
COPY ${JAR_FILE} ./app.jar
4+
ENV TZ=Asia/Seoul
5+
ENTRYPOINT ["java", "-jar", "./app.jar"]

pro/src/main/java/com/example/pro/auth/config/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
7676

7777
http.authorizeHttpRequests(request -> {
7878
request.requestMatchers(
79-
antMatcher("/docs/**"),
79+
// antMatcher("/docs/**"),
8080
antMatcher("/api/test"),
8181
antMatcher("/members/signup"),
8282
antMatcher("/members/login"),

pro/src/main/java/com/example/pro/auth/exception/SessionAuthenticationEntryPoint.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import jakarta.servlet.http.HttpServletRequest;
77
import jakarta.servlet.http.HttpServletResponse;
8+
import lombok.extern.slf4j.Slf4j;
89
import org.springframework.http.MediaType;
910
import org.springframework.security.core.AuthenticationException;
1011
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -13,12 +14,14 @@
1314
import java.io.IOException;
1415

1516
@Component
17+
@Slf4j
1618
public class SessionAuthenticationEntryPoint implements AuthenticationEntryPoint {
1719

1820
private final ObjectMapper mapper = new ObjectMapper();
1921

2022
@Override
2123
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
24+
log.error("Auth Exception({})={}", AuthErrorCode.UNAUTHORIZED_USER.toString(), AuthErrorCode.UNAUTHORIZED_USER.getMessage());
2225
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
2326
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
2427
response.setCharacterEncoding("utf-8");

0 commit comments

Comments
 (0)