From d6d82555609a68c81ff536c8da392389b493db91 Mon Sep 17 00:00:00 2001 From: Sejeong Kim Date: Tue, 29 Oct 2024 20:55:33 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20docker=20compose=20=EB=B3=80=EA=B2=BD(?= =?UTF-8?q?Docker-dev,=20prod=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/aws-cicd-dev.yml | 11 --------- .github/workflows/aws-cicd-prod.yml | 23 +++++++------------ layer-api/{Dockerfile => Dockerfile-dev} | 6 ----- layer-api/Dockerfile-prod | 4 ++++ .../java/org/layer/config/SecurityConfig.java | 1 + .../org/layer/domain/etc/TempController.java | 13 +++++++++++ .../src/main/resources/application-dev.yml | 5 +++- .../src/main/resources/application-local.yml | 5 +++- .../src/main/resources/application-prod.yml | 5 +++- 9 files changed, 38 insertions(+), 35 deletions(-) rename layer-api/{Dockerfile => Dockerfile-dev} (76%) create mode 100644 layer-api/Dockerfile-prod create mode 100644 layer-api/src/main/java/org/layer/domain/etc/TempController.java diff --git a/.github/workflows/aws-cicd-dev.yml b/.github/workflows/aws-cicd-dev.yml index 8d1da1be..033f112b 100644 --- a/.github/workflows/aws-cicd-dev.yml +++ b/.github/workflows/aws-cicd-dev.yml @@ -146,17 +146,6 @@ jobs: sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }} - - name: Set Permissions on Transferred Files - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.AWS_DEV_INSTANCE_HOST }} - username: ubuntu - key: ${{ secrets.AWS_INSTANCE_PEM }} - port: 22 - script: | - sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }} - sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }} - - name: Deploy with Docker Compose uses: appleboy/ssh-action@master with: diff --git a/.github/workflows/aws-cicd-prod.yml b/.github/workflows/aws-cicd-prod.yml index ef172b4f..0f62a35f 100644 --- a/.github/workflows/aws-cicd-prod.yml +++ b/.github/workflows/aws-cicd-prod.yml @@ -57,7 +57,6 @@ jobs: run: | echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties - echo "${GOOGLE_CREDENTIALS}" > ./layer-api/src/main/resources/tokens/StoredCredential - name: Build layer-api module run: ./gradlew :layer-api:build @@ -86,13 +85,10 @@ jobs: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch - name: Push layer-api Docker Image - uses: docker/build-push-action@v4 - with: - context: ./layer-api - platforms: linux/amd64 - push: true - tags: | - ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest + run: | + docker login -u ${{ secrets.DOCKER_EAMIL }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f ./layer-api/Dockerfile-dev -t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest . + docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api - name: Push layer-batch Docker Image uses: docker/build-push-action@v4 @@ -118,9 +114,6 @@ jobs: run: | echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties - sudo chmod 777 ./layer-api/infra/${{ env.DEPLOY_TARGET }}/tokens/StoredCredential -# echo "${GOOGLE_CREDENTIALS}" > ./layer-api/src/main/resources/tokens/StoredCredential -# echo "${GOOGLE_CREDENTIALS}" > ./layer-api/infra/aws/StoredCredential - name: Archive Files run: | @@ -131,7 +124,7 @@ jobs: with: host: ${{ secrets.AWS_PROD_INSTANCE_HOST }} username: ubuntu - key: ${{ secrets.AWS_PROD_INSTANCE_PEM }} + key: ${{ secrets.AWS_INSTANCE_PEM }} port: 22 source: "layer-api.tar.gz" target: "/home/ubuntu" @@ -141,7 +134,7 @@ jobs: with: host: ${{ secrets.AWS_PROD_INSTANCE_HOST }} username: ubuntu - key: ${{ secrets.AWS_PROD_INSTANCE_PEM }} + key: ${{ secrets.AWS_INSTANCE_PEM }} port: 22 script: | cd /home/ubuntu @@ -155,7 +148,7 @@ jobs: with: host: ${{ secrets.AWS_PROD_INSTANCE_HOST }} username: ubuntu - key: ${{ secrets.AWS_PROD_INSTANCE_PEM }} + key: ${{ secrets.AWS_INSTANCE_PEM }} port: 22 script: | sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }} @@ -166,7 +159,7 @@ jobs: with: host: ${{ secrets.AWS_PROD_INSTANCE_HOST }} username: ubuntu - key: ${{ secrets.AWS_PROD_INSTANCE_PEM }} + key: ${{ secrets.AWS_INSTANCE_PEM }} port: 22 script: | sudo apt update diff --git a/layer-api/Dockerfile b/layer-api/Dockerfile-dev similarity index 76% rename from layer-api/Dockerfile rename to layer-api/Dockerfile-dev index d936d6f9..cbb49e2e 100644 --- a/layer-api/Dockerfile +++ b/layer-api/Dockerfile-dev @@ -1,10 +1,4 @@ FROM openjdk:17 - ARG JAR_FILE=./build/libs/*.jar -ARG SPRING_PROFILE - COPY ${JAR_FILE} layer-server.jar - -ENV SPRING_PROFILE=${SPRING_PROFILE} - ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=dev" ,"-jar" ,"layer-server.jar"] \ No newline at end of file diff --git a/layer-api/Dockerfile-prod b/layer-api/Dockerfile-prod new file mode 100644 index 00000000..1cc729ea --- /dev/null +++ b/layer-api/Dockerfile-prod @@ -0,0 +1,4 @@ +FROM openjdk:17 +ARG JAR_FILE=./build/libs/*.jar +COPY ${JAR_FILE} layer-server.jar +ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod" ,"-jar" ,"layer-server.jar"] \ No newline at end of file diff --git a/layer-api/src/main/java/org/layer/config/SecurityConfig.java b/layer-api/src/main/java/org/layer/config/SecurityConfig.java index ce833a59..266ed332 100644 --- a/layer-api/src/main/java/org/layer/config/SecurityConfig.java +++ b/layer-api/src/main/java/org/layer/config/SecurityConfig.java @@ -59,6 +59,7 @@ private void setHttp(HttpSecurity http) throws Exception { .requestMatchers(new AntPathRequestMatcher("/api/auth/oauth2/apple")).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/auth/create-token")).permitAll() .requestMatchers(new AntPathRequestMatcher("/admin/**")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/greeting")).permitAll() .anyRequest().authenticated() ) .headers(headers -> headers diff --git a/layer-api/src/main/java/org/layer/domain/etc/TempController.java b/layer-api/src/main/java/org/layer/domain/etc/TempController.java new file mode 100644 index 00000000..aef6a6d7 --- /dev/null +++ b/layer-api/src/main/java/org/layer/domain/etc/TempController.java @@ -0,0 +1,13 @@ +package org.layer.domain.etc; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TempController { + @GetMapping("/greeting") + public String greeting(@Value("${greeting.message}") String greeting) { + return greeting; + } +} diff --git a/layer-api/src/main/resources/application-dev.yml b/layer-api/src/main/resources/application-dev.yml index bc82af76..e894ab8f 100644 --- a/layer-api/src/main/resources/application-dev.yml +++ b/layer-api/src/main/resources/application-dev.yml @@ -80,4 +80,7 @@ openai: maxTokens: ${OPENAI_MAX_TOKENS} admin: - password: ${ADMIN_PASSWORD} \ No newline at end of file + password: ${ADMIN_PASSWORD} + +greeting: + message: this is dev \ No newline at end of file diff --git a/layer-api/src/main/resources/application-local.yml b/layer-api/src/main/resources/application-local.yml index c8fe1029..4e6ac6d3 100644 --- a/layer-api/src/main/resources/application-local.yml +++ b/layer-api/src/main/resources/application-local.yml @@ -85,4 +85,7 @@ openai: maxTokens: ${OPENAI_MAX_TOKENS} admin: - password: ${ADMIN_PASSWORD} \ No newline at end of file + password: ${ADMIN_PASSWORD} + +greeting: + message: this is local \ No newline at end of file diff --git a/layer-api/src/main/resources/application-prod.yml b/layer-api/src/main/resources/application-prod.yml index ace193ec..dbfedc7a 100644 --- a/layer-api/src/main/resources/application-prod.yml +++ b/layer-api/src/main/resources/application-prod.yml @@ -80,4 +80,7 @@ openai: maxTokens: ${OPENAI_MAX_TOKENS} admin: - password: ${ADMIN_PASSWORD} \ No newline at end of file + password: ${ADMIN_PASSWORD} + +greeting: + message: this is prod \ No newline at end of file