| 
1 |  | -name: Deploy to cloudtype  | 
 | 1 | +# This workflow uses actions that are not certified by GitHub.  | 
 | 2 | +# They are provided by a third-party and are governed by  | 
 | 3 | +# separate terms of service, privacy policy, and support  | 
 | 4 | +# documentation.  | 
 | 5 | +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time  | 
 | 6 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle  | 
 | 7 | + | 
 | 8 | +name: Java CI/CD with Gradle  | 
 | 9 | + | 
2 | 10 | on:  | 
3 | 11 |   push:  | 
4 |  | -    branches:  | 
5 |  | -      - main  | 
 | 12 | +    branches: [ "main" ]  | 
 | 13 | +  pull_request:  | 
 | 14 | +    branches: [ "main" ]  | 
 | 15 | + | 
6 | 16 | permissions:  | 
7 | 17 |   contents: read  | 
8 |  | -  packages: write  | 
 | 18 | +  id-token: write  | 
9 | 19 | 
 
  | 
10 | 20 | jobs:  | 
 | 21 | +  build:  | 
 | 22 | +    runs-on: ubuntu-latest  | 
 | 23 | + | 
 | 24 | +    steps:  | 
 | 25 | +    - uses: actions/checkout@v4  | 
 | 26 | +      | 
 | 27 | +    - name: Set up JDK 17  | 
 | 28 | +      uses: actions/setup-java@v4  | 
 | 29 | +      with:  | 
 | 30 | +        java-version: '17'  | 
 | 31 | +        distribution: 'temurin'  | 
 | 32 | + | 
 | 33 | +    # Gradle 권한 설정 추가  | 
 | 34 | +    - name: Grant execute permission for gradlew  | 
 | 35 | +      run: chmod +x gradlew  | 
 | 36 | + | 
 | 37 | +    - name: Build with Gradle  | 
 | 38 | +      working-directory: ./Location-based-target-authentication  | 
 | 39 | +      run: |  | 
 | 40 | +        chmod +x ./gradlew  | 
 | 41 | +        ./gradlew bootJar --info --stacktrace  | 
 | 42 | +
  | 
 | 43 | +    - name: Upload JAR  | 
 | 44 | +      uses: actions/upload-artifact@v4  | 
 | 45 | +      with:  | 
 | 46 | +        name: app  | 
 | 47 | +        path: ./Location-based-target-authentication/build/libs/*.jar  | 
 | 48 | +        if-no-files-found: error  | 
 | 49 | + | 
11 | 50 |   deploy:  | 
 | 51 | +    needs: build  | 
12 | 52 |     runs-on: ubuntu-latest  | 
13 |  | -    permissions:  | 
14 |  | -      contents: read  | 
15 |  | -      packages: write  | 
 | 53 | +      | 
16 | 54 |     steps:  | 
17 |  | -      - name: Checkout  | 
18 |  | -        uses: actions/checkout@v2  | 
19 |  | -      - name: Connect deploy key  | 
20 |  | -        uses: cloudtype-github-actions/connect@v1  | 
21 |  | -        with:  | 
22 |  | -          token: ${{ secrets.CLOUDTYPE_TOKEN }}  | 
23 |  | -          repo: be  | 
24 |  | -      - name: Deploy  | 
25 |  | -        uses: cloudtype-github-actions/deploy@v1  | 
26 |  | -        with:  | 
27 |  | -          token: ${{ secrets.CLOUDTYPE_TOKEN }}  | 
28 |  | -          project: be  | 
29 |  | -          stage: main  | 
30 |  | -          yaml: |  | 
31 |  | -            name: willgo  | 
32 |  | -            app: dockerfile  | 
33 |  | -              env:  | 
34 |  | -                - name: GOOGLE_CLIENT_ID  | 
35 |  | -                  value: ${{ secrets.GOOGLE_CLIENT_ID }}  | 
36 |  | -                - name: GOOGLE_CLIENT_SECRET  | 
37 |  | -                  value: ${{ secrets.GOOGLE_CLIENT_SECRET }}  | 
38 |  | -                - name: JWT_SECRET_KEY  | 
39 |  | -                  value: ${{ secrets.JWT_SECRET_KEY }}  | 
40 |  | -                - name: KAKAO_API_KEY  | 
41 |  | -                  value: ${{ secrets.KAKAO_API_KEY }}  | 
42 |  | -                - name: KAKAO_CLIENT_ID  | 
43 |  | -                  value: ${{ secrets.KAKAO_CLIENT_ID }}  | 
44 |  | -                - name: KAKAO_CLIENT_SECRET  | 
45 |  | -                  value: ${{ secrets.KAKAO_CLIENT_SECRET }}  | 
46 |  | -                - name: MAIL_HOST  | 
47 |  | -                  value: ${{ secrets.MAIL_HOST }}  | 
48 |  | -                - name: MAIL_PASSWORD  | 
49 |  | -                  value: ${{ secrets.MAIL_PASSWORD }}  | 
50 |  | -                - name: MAIL_PORT  | 
51 |  | -                  value: ${{ secrets.MAIL_PORT }}  | 
52 |  | -                - name: MAIL_USERNAME  | 
53 |  | -                  value: ${{ secrets.MAIL_USERNAME }}  | 
54 |  | -                - name: SERVER_IP  | 
55 |  | -                  value: ${{ secrets.SERVER_IP }}  | 
56 |  | -                - name: SERVER_USER  | 
57 |  | -                  value: ${{ secrets.SERVER_USER }}  | 
58 |  | -                - name: SSH_PRIVATE_KEY  | 
59 |  | -                  value: ${{ secrets.SSH_PRIVATE_KEY }}  | 
60 |  | -              buildenv: []  | 
61 |  | -            context:  | 
62 |  | -              git:  | 
63 |  | -                url: git@github.com:Location-based-target-authentication/BE.git  | 
64 |  | -                ref: main  | 
65 |  | -              preset: java-springboot  | 
 | 55 | +    - uses: actions/download-artifact@v4  | 
 | 56 | +      with:  | 
 | 57 | +        name: app  | 
 | 58 | + | 
 | 59 | +    # SSH 키 설정  | 
 | 60 | +    - name: Setup SSH  | 
 | 61 | +      run: |  | 
 | 62 | +        mkdir -p ~/.ssh  | 
 | 63 | +        echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key  | 
 | 64 | +        chmod 700 ~/.ssh  | 
 | 65 | +        chmod 600 ~/.ssh/deploy_key  | 
 | 66 | +        eval $(ssh-agent -s)  | 
 | 67 | +        ssh-add ~/.ssh/deploy_key  | 
 | 68 | +        ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts  | 
 | 69 | +
  | 
 | 70 | +    # SSH 연결 테스트  | 
 | 71 | +    - name: Test SSH connection  | 
 | 72 | +      run: |  | 
 | 73 | +        ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} 'echo "Connection test successful"'  | 
 | 74 | +
  | 
 | 75 | +    # JAR 파일 전송  | 
 | 76 | +    - name: Copy JAR to Server  | 
 | 77 | +      run: |  | 
 | 78 | +        ls -la  | 
 | 79 | +        scp -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no *.jar ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/home/${{ secrets.SERVER_USER }}/  | 
 | 80 | +
  | 
 | 81 | +    # 서버에서 JAR 실행  | 
 | 82 | +    - name: Execute JAR  | 
 | 83 | +      uses: appleboy/ssh-action@v1.0.0  | 
 | 84 | +      with:  | 
 | 85 | +        host: ${{ secrets.SERVER_IP }}  | 
 | 86 | +        username: ${{ secrets.SERVER_USER }}  | 
 | 87 | +        key: ${{ secrets.SSH_PRIVATE_KEY }}  | 
 | 88 | +        script: |  | 
 | 89 | +          cd /home/${{ secrets.SERVER_USER }}  | 
 | 90 | +          sudo tee /etc/systemd/system/willgo.service << EOF  | 
 | 91 | +          [Unit]  | 
 | 92 | +          Description=Willgo Backend Application  | 
 | 93 | +          After=network.target  | 
 | 94 | +
  | 
 | 95 | +          [Service]  | 
 | 96 | +          Type=simple  | 
 | 97 | +          User=root  | 
 | 98 | +          WorkingDirectory=/home/${{ secrets.SERVER_USER }}  | 
 | 99 | +            | 
 | 100 | +          # JWT 설정  | 
 | 101 | +          Environment=JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}  | 
 | 102 | +          Environment=JWT_ACCESS_TOKEN_EXPIRATION=600000  | 
 | 103 | +          Environment=JWT_REFRESH_TOKEN_EXPIRATION=604800000  | 
 | 104 | +            | 
 | 105 | +          # 카카오 설정  | 
 | 106 | +          Environment=KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY }}  | 
 | 107 | +          Environment=KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}  | 
 | 108 | +          Environment=KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }}  | 
 | 109 | +          Environment=KAKAO_REDIRECT_URI=https://175.45.203.57:8443/api/v1/auth/kakao/callback  | 
 | 110 | +            | 
 | 111 | +          # 구글 설정  | 
 | 112 | +          Environment=GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}  | 
 | 113 | +          Environment=GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}  | 
 | 114 | +          Environment=GOOGLE_REDIRECT_URI=https://175.45.203.57:8443/api/v1/auth/google/callback  | 
 | 115 | +            | 
 | 116 | +          # 메일 설정  | 
 | 117 | +          Environment=MAIL_HOST=${{ secrets.MAIL_HOST }}  | 
 | 118 | +          Environment=MAIL_PORT=${{ secrets.MAIL_PORT }}  | 
 | 119 | +          Environment=MAIL_USERNAME=${{ secrets.MAIL_USERNAME }}  | 
 | 120 | +          Environment=MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }}  | 
 | 121 | +            | 
 | 122 | +          # Tomcat 설정  | 
 | 123 | +          Environment=TOMCAT_CONNECTOR_PROTOCOL=org.apache.coyote.http11.Http11NioProtocol  | 
 | 124 | +          Environment=TOMCAT_CONNECTOR_MAX_CONNECTIONS=10000  | 
 | 125 | +          Environment=TOMCAT_CONNECTOR_ACCEPT_COUNT=100  | 
 | 126 | +          Environment=TOMCAT_CONNECTOR_CONNECTION_TIMEOUT=20000  | 
 | 127 | +          Environment=TOMCAT_CONNECTOR_MAX_KEEP_ALIVE_REQUESTS=1  | 
 | 128 | +          Environment=TOMCAT_CONNECTOR_KEEP_ALIVE_TIMEOUT=1  | 
 | 129 | +
  | 
 | 130 | +          ExecStart=/usr/bin/java -jar Location-based-target-authentication-0.0.1-SNAPSHOT.jar \  | 
 | 131 | +            --spring.profiles.active=secret \  | 
 | 132 | +            --logging.level.com.swyp.global.security=DEBUG \  | 
 | 133 | +            --logging.level.org.springframework.web=DEBUG \  | 
 | 134 | +            --logging.level.org.springframework.web.cors=TRACE \  | 
 | 135 | +            --spring.config.location=classpath:/application.properties \  | 
 | 136 | +            --server.tomcat.remoteip.remote-ip-header=x-forwarded-for \  | 
 | 137 | +            --server.tomcat.remoteip.protocol-header=x-forwarded-proto \  | 
 | 138 | +            --server.tomcat.redirect-context-root=false \  | 
 | 139 | +            --server.tomcat.use-relative-redirects=true \  | 
 | 140 | +            --server.forward-headers-strategy=native \  | 
 | 141 | +            --server.tomcat.max-http-form-post-size=10MB \  | 
 | 142 | +            --server.tomcat.max-swallow-size=20MB \  | 
 | 143 | +            -Dspring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID} \  | 
 | 144 | +            -Dspring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET} \  | 
 | 145 | +            -Dspring.security.oauth2.client.registration.google.redirect-uri=${GOOGLE_REDIRECT_URI} \  | 
 | 146 | +            -Dgoogle.redirect.url=${GOOGLE_REDIRECT_URI} \  | 
 | 147 | +            -Dgoogle.client.id=${GOOGLE_CLIENT_ID} \  | 
 | 148 | +            -Dgoogle.client.secret=${GOOGLE_CLIENT_SECRET} \  | 
 | 149 | +            -Dkakao.client.id=${KAKAO_CLIENT_ID} \  | 
 | 150 | +            -Dkakao.client.secret=${KAKAO_CLIENT_SECRET} \  | 
 | 151 | +            -Dkakao.redirect.url=${KAKAO_REDIRECT_URI} \  | 
 | 152 | +            -Dspring.security.oauth2.client.registration.google.scope=profile,email \  | 
 | 153 | +            -Dspring.security.oauth2.client.registration.google.client-name=Google \  | 
 | 154 | +            -Dspring.security.oauth2.client.registration.google.authorization-grant-type=authorization_code \  | 
 | 155 | +            -Dspring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth \  | 
 | 156 | +            -Dspring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token \  | 
 | 157 | +            -Dspring.security.oauth2.client.provider.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo \  | 
 | 158 | +            -Dspring.security.oauth2.client.provider.google.user-name-attribute=sub \  | 
 | 159 | +            -Dspring.security.oauth2.client.registration.kakao.client-id=${KAKAO_CLIENT_ID} \  | 
 | 160 | +            -Dspring.security.oauth2.client.registration.kakao.client-secret=${KAKAO_CLIENT_SECRET} \  | 
 | 161 | +            -Dspring.security.oauth2.client.registration.kakao.redirect-uri=${KAKAO_REDIRECT_URI} \  | 
 | 162 | +            -Dspring.security.oauth2.client.registration.kakao.client-name=Kakao \  | 
 | 163 | +            -Dspring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code \  | 
 | 164 | +            -Dspring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post \  | 
 | 165 | +            -Dspring.security.oauth2.client.registration.kakao.scope=profile_nickname,profile_image,account_email \  | 
 | 166 | +            -Dspring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize \  | 
 | 167 | +            -Dspring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token \  | 
 | 168 | +            -Dspring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me \  | 
 | 169 | +            -Dspring.security.oauth2.client.provider.kakao.user-name-attribute=id \  | 
 | 170 | +            -DMAIL_HOST=${MAIL_HOST} \  | 
 | 171 | +            -DMAIL_PORT=${MAIL_PORT} \  | 
 | 172 | +            -DMAIL_USERNAME=${MAIL_USERNAME} \  | 
 | 173 | +            -DMAIL_PASSWORD=${MAIL_PASSWORD} \  | 
 | 174 | +            -Dmail.transport.protocol=smtp \  | 
 | 175 | +            -Dmail.smtp.auth=true \  | 
 | 176 | +            -Dmail.smtp.starttls.enable=true \  | 
 | 177 | +            -Dmail.smtp.timeout=5000 \  | 
 | 178 | +            -Dmail.smtp.connectiontimeout=5000 \  | 
 | 179 | +            -Dmail.smtp.writetimeout=5000 \  | 
 | 180 | +            -Dmail.smtp.ssl.trust=smtp.gmail.com \  | 
 | 181 | +            -Dmail.smtp.ssl.protocols=TLSv1.2 \  | 
 | 182 | +            -Dmail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory \  | 
 | 183 | +            -Dmail.smtp.socketFactory.fallback=false \  | 
 | 184 | +            -Dmail.smtp.socketFactory.port=587 \  | 
 | 185 | +            -Dmail.debug=true \  | 
 | 186 | +            -Dcors.allowed-origins=https://locationcheckgo.netlify.app,https://localhost:8443,https://175.45.203.57:8443 \  | 
 | 187 | +            -Dserver.tomcat.additional-tld-skip-patterns=*.jar \  | 
 | 188 | +            -Dserver.tomcat.relaxed-query-chars=|,{,},[,],^,`,<,> \  | 
 | 189 | +            -Dserver.tomcat.relaxed-path-chars=|,{,},[,],^,`,<,> \  | 
 | 190 | +            -Dserver.tomcat.connector.protocol=${TOMCAT_CONNECTOR_PROTOCOL} \  | 
 | 191 | +            -Dserver.tomcat.max-connections=${TOMCAT_CONNECTOR_MAX_CONNECTIONS} \  | 
 | 192 | +            -Dserver.tomcat.accept-count=${TOMCAT_CONNECTOR_ACCEPT_COUNT} \  | 
 | 193 | +            -Dserver.tomcat.connection-timeout=${TOMCAT_CONNECTOR_CONNECTION_TIMEOUT} \  | 
 | 194 | +            -Dserver.tomcat.max-keep-alive-requests=${TOMCAT_CONNECTOR_MAX_KEEP_ALIVE_REQUESTS} \  | 
 | 195 | +            -Dserver.tomcat.keep-alive-timeout=${TOMCAT_CONNECTOR_KEEP_ALIVE_TIMEOUT} \  | 
 | 196 | +            -Dserver.tomcat.reject-illegal-header-values=false \  | 
 | 197 | +            -Dserver.tomcat.uri-encoding=UTF-8  | 
 | 198 | +            | 
 | 199 | +          Restart=always  | 
 | 200 | +
  | 
 | 201 | +          [Install]  | 
 | 202 | +          WantedBy=multi-user.target  | 
 | 203 | +          EOF  | 
 | 204 | +
  | 
 | 205 | +          # 서비스 시작  | 
 | 206 | +          sudo systemctl daemon-reload  | 
 | 207 | +          sudo systemctl restart willgo  | 
 | 208 | +          sudo systemctl status willgo  | 
0 commit comments