Skip to content

[Deploy] Action Script와 Dockerfile #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2024
Merged
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
70 changes: 70 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Passionate Pro Deployment

on:
push:
branches: [ "main" ]

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
AWS_REGION: ap-northeast-2
working-directory: ./pro

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java JDK
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'temurin'

- name: make application.yml
if: true
run: |
touch ./src/main/resources/application.yml
echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.yml
shell: bash
working-directory: ${{ env.working-directory }}

- name: Gradle execute permission for gradlew
run: chmod +x gradlew
shell: bash
working-directory: ${{ env.working-directory }}

- name: Build with Gradle
run: ./gradlew bootjar
shell: bash
working-directory: ${{ env.working-directory }}

- name: DockerHub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Docker Image Build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} .

- name: DockerHub Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}

- name: Application Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}

script: |
sudo docker kill ${{ secrets.PROJECT_NAME }}
sudo docker rm -f ${{ secrets.PROJECT_NAME }}
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}
sudo docker run -p 8080:8080 --name ${{ secrets.PROJECT_NAME }}
5 changes: 5 additions & 0 deletions pro/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-alpine
ARG JAR_FILE=build/libs/pro-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} ./app.jar
ENV TZ=Asia/Seoul
ENTRYPOINT ["java", "-jar", "./app.jar"]
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.authorizeHttpRequests(request -> {
request.requestMatchers(
antMatcher("/docs/**"),
// antMatcher("/docs/**"),
antMatcher("/api/test"),
antMatcher("/members/signup"),
antMatcher("/members/login"),
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -13,12 +14,14 @@
import java.io.IOException;

@Component
@Slf4j
public class SessionAuthenticationEntryPoint implements AuthenticationEntryPoint {

private final ObjectMapper mapper = new ObjectMapper();

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