DevOps

[GCP] Cloud Run์œผ๋กœ ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ์›น์„œ๋ฒ„์— ๋ฐฐํฌํ•ด๋ณด์ž!

Alchemists 2023. 2. 6. 03:54
728x90

Google Cloud๋ฅผ ํ†ตํ•ด์„œ๋งŒ ๋ฐฐํฌํ•  ์ผ์ด ์ƒ๊ฒจ์„œ ์—ฌ๋Ÿฌ๋ฒˆ ๋ป˜์ง“์„ ํ•˜๋‹ค ๊ธฐ๋กํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ์•„๋ฌด๋ž˜๋„ GCP๋Š” AWS๋ณด๋‹ค ๋ ˆํผ๋Ÿฐ์Šค๊ฐ€ ๋งŽ์ด ์—†๊ธฐ๋„ ํ•ด์„œ ๋” ์–ด๋ ค์› ๋‹ค. ํ•˜์ง€๋งŒ ๊ตฌ๊ธ€์ด์—ฌ์„œ ๊ทธ๋Ÿฐ์ง€ ๊ณต์‹๋ฌธ์„œ๊ฐ€ ์ •๋ง ์ž˜ ๋˜์–ด์žˆ์—ˆ๋‹ค. ์ฝ๊ธฐ ๋”ฐ๋ถ„ํ• ์ง€ ๋ชฐ๋ผ๋„ ๊ผญ ์ฝ์–ด๋ณด๋ฉด ์ข‹๋‹ค! ๊ฒฐ๊ตญ ๋‚˜๋„ ๋‹ต์„ ๊ณต์‹๋ฌธ์„œ์— ์ฐพ์•˜๋‹ค!

 

๋„์›€์„ ๋ฐ›์€ ๋งํฌ๋Š”

https://cloud.google.com/build/docs/deploying-builds/deploy-cloud-run?hl=ko 

 

Cloud Build๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Cloud Run์— ๋ฐฐํฌ  |  Cloud Build ๋ฌธ์„œ  |  Google Cloud

์˜๊ฒฌ ๋ณด๋‚ด๊ธฐ Cloud Build๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Cloud Run์— ๋ฐฐํฌ ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•ด ์ •๋ฆฌํ•˜๊ธฐ ๋‚ด ํ™˜๊ฒฝ์„ค์ •์„ ๊ธฐ์ค€์œผ๋กœ ์ฝ˜ํ…์ธ ๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ถ„๋ฅ˜ํ•˜์„ธ์š”. ์ด ํŽ˜์ด์ง€์—์„œ๋Š” Cloud Build๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Cloud Run ๋ฐ Cloud Run for

cloud.google.com

์ด ๋งํฌ๋Š” cloud build๋ฅผ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€ ๋‚˜์™€์žˆ๊ณ 

https://github.com/GoogleCloudPlatform/cloud-build-samples/tree/main/run-example-builddeploy

 

GitHub - GoogleCloudPlatform/cloud-build-samples: Code snippets used in Cloud Build documentation

Code snippets used in Cloud Build documentation. Contribute to GoogleCloudPlatform/cloud-build-samples development by creating an account on GitHub.

github.com

์ด ๊นƒํ—™์—๋Š” ์ƒ˜ํ”Œ๋งํฌ๊ฐ€ ์žˆ๋‹ค!

 

์›๋ž˜๋Š” ๊นƒํ—™์•ก์…˜์œผ๋กœ ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋งค๋ฒˆ ๋นŒ๋“œํ•ด์ฃผ๊ณ  ๊ทธ๊ฑธ os๊ฐ€ ์šฐ๋ถ„ํˆฌ์ธ ์ธ์Šคํ„ด์Šค์— ๋ฐฐํฌํ•˜๋ ค๊ณ  ํ–ˆ๋‹ค. ๊ทผ๋ฐ github action์—์„œ ๋‹ค fail์ด ๋– ๋ฒ„๋ ธ๊ณ , ์•„๋‹ˆ๋ฉด ์ธ์Šคํ„ด์Šค ์ž์ฒด๋ฅผ ๋„์ปค ํ”Œ๋žซํผ์œผ๋กœ ๋งŒ๋“ค์–ด๋ฒ„๋ฆด๊นŒ? ๋ผ๋Š” ์ƒ๊ฐ๋„ ๋“ค์—ˆ๋Š”๋ฐ ใ…‹ใ…‹ใ…‹ ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด Cloud optimized os๋ฐ–์— ์“ฐ์ง€ ๋ชปํ–ˆ๋‹ค. ๊ทผ๋ฐ ์ด์ƒํ•œ๊ฒŒ ์ด๊ฑด ์šฐ๋ถ„ํˆฌ๋ž‘ ์™„์ „ ๋‹ค๋ฅธ ์•  ๊ฐ™์•˜๊ณ  sudo ๋ช…๋ น์–ด๊ฐ€ ๋“ฃ์งˆ ์•Š์•„์„œ nginx๊ฐ€ ๊น”๋ฆฌ์งˆ ์•Š์•˜๋‹ค. 

๋‚ด๊ฐ€ ์›ํ•˜๋Š” ํ™˜๊ฒฝ์€ ์ปค๋ฐ‹์ด ๋˜๋Š” ๊ฑธ ๋ฐ”๋กœ๋ฐ”๋กœ  ์›น์„œ๋ฒ„์— ๋ฐ˜์˜ํ•˜๋Š” ๊ฑฐ์˜€๊ณ  ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ๋“ค์˜ ์กฐ์–ธ์„ ๋“ฃ๋‹ค๋ณด๋‹ˆ Cloud Run์ด๋ผ๋Š” ์—„์ฒญ๋‚œ ์นญ๊ตฌ๋ฅผ ์•Œ๊ฒŒ๋˜์—ˆ๋‹ค. 

 

์šฐ์„  ์†Œ๊ฐœ ํŽ˜์ด์ง€๋ฅผ ๋ณด๋ฉด

https://cloud.google.com/run?hl=ko#section-7 

 

Cloud Run: ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ”„๋กœ๋•์…˜์œผ๋กœ ์‹ ์†ํžˆ ๋ฐฐํฌ  |  Google Cloud

์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ž๋™์œผ๋กœ ํ™•์žฅํ•˜๋Š” ์™„์ „ ๊ด€๋ฆฌํ˜• ์ปดํ“จํŒ… ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค. ์›ํ•˜๋Š” ์–ธ์–ด๋กœ ์•ฑ์„ ๋นŒ๋“œํ•˜๊ณ  ๋ช‡ ์ดˆ ์•ˆ์— ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cloud.google.com

"์™„์ „ ๊ด€๋ฆฌํ˜• ํ”Œ๋žซํผ์—์„œ ์›ํ•˜๋Š” ์–ธ์–ด(Go, Python, ์ž๋ฐ”, Node.js, .NET, Ruby ๋“ฑ)๋กœ ์ž‘์„ฑ๋œ ํ™•์žฅ ๊ฐ€๋Šฅํ•˜๊ณ  ์ปจํ…Œ์ด๋„ˆํ™”๋œ ์•ฑ์„ ๋นŒ๋“œํ•˜๊ณ  ๋ฐฐํฌํ•˜์„ธ์š”."

์˜ค ์—˜๋ผ์Šคํ‹ฑ ๋นˆ์Šคํ†ก์ธ๊ฐ€? 

 

์˜ˆ์‹œ๋“ค์ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์žˆ๋Š”๋ฐ ์šฐ์„  ๋‚˜๋Š” RESTAPI ๋ฐฑ์—”๋“œ ์šฉ์œผ๋กœ ์“ธ ๊ฒƒ์ด๋‹ค!

 

๐Ÿฆ„ Cloud Run ํ•ด๋ณด์ž! ๐Ÿฆ„

 

๋‚˜๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ๋„์ปค ์ด๋ฏธ์ง€๋กœ ๊ตฌ์› ๋Š”๋ฐ ๋„์ปค ํŒŒ์ผ์„ ๋ณด๋ฉด gradle์„ ๋จผ์ € ์‹คํ–‰์‹œ์ผœ์„œ jarํŒŒ์ผ์„ ๋งŒ๋“ค์—ˆ๋‹ค

 

FROM openjdk:11 AS builder
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
COPY src src
RUN chmod +x ./gradlew
RUN ./gradlew bootJAR

FROM openjdk:11
COPY --from=builder build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]

 

๋ณดํ†ต Dockefile์ด๋ผํ•˜๋ฉด COPY ๋จธ์‹œ๊ธฐํ•˜๊ณ  jarํŒŒ์ผ๋งŒ ๋†“์€ ์ฝ”๋“œ๊ฐ€ ํ‹ฐ์Šคํ† ๋ฆฌ์— ์ •๋ง ๋งŽ๋‹ค. ๋‚˜๋„ ๊ทธ๋ ‡๊ฒŒ ์ผ๋Š”๋ฐ

๋ฌธ์ œ๋Š” build ๋ ๋•Œ ์—๋Ÿฌ ๋กœ๊ทธ์— COPY failed: file not found in build context or excluded by .dockerignore: stat build/libs/garbageCollection-0.0.1-SNAPSHOT.jar: file does not exist

์–˜๊ฐ€ ์ž๊พธ ๋–ด๋‹ค.. 

https://bgpark.tistory.com/132

 

Docker COPY failed: no source files were specified ์—๋Ÿฌ

์˜ค๋Š˜์€ aws ecs fargat์— spring boot microservice๋ฅผ code pipeline์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐํฌํ•˜๋˜ ์ค‘ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์— ๋Œ€ํ•ด์„œ ๋งํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฐœ์ƒ ์ด์Šˆ docker ์ด๋ฏธ์ง€๋ฅผ build ํ•˜๋˜ ์ค‘, ๊ณ„์† COPY failed: no source files were spe

bgpark.tistory.com

์ด ๊ธ€์„ ๋ณด๋‹ˆ๊นŒ context์˜ ์œ„์น˜๋ฅผ ๋ช…ํ™•ํžˆ ํ•ด์ฃผ๋Š”๊ฒŒ ํ•„์š”ํ•˜๋‹ค ์ƒ๊ฐํ–ˆ๊ณ  ๊ทธ๋ž˜์„œ ๊ทธ๋ƒฅ docker ์ด๋ฏธ์ง€ ์ƒ์„ฑํ• ๋•Œ jarํŒŒ์ผ์„ ๋งŒ๋“ค์–ด๋ฒ„๋ฆฌ๋ฉด ์œ„์น˜๊ฐ€ ๋ช…ํ™•ํ•ด์ง€์ง€ ์•Š์„๊นŒ? ๋ผ๋Š” ๋ฐœ์ƒ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค (ํ‹€๋ ธ์„ ์ˆ˜ ์žˆ์–ด์š”.. )

 

Cloud Run ์— ๋“ค์–ด๊ฐ€๋ฉด 

Compute Engine๋งŒ ์‚ฌ์šฉ ์„ค์ •ํ•ด์ฃผ๋„๋ก ํ•˜์ž! 

 

์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค๋ฉด ์†Œ์Šค์ €์žฅ์†Œ์—์„œ ์ง€์†์ ์œผ๋กœ ์ƒˆ ๋ฒ„์ „ ๋ฐฐํฌ ์„ ํƒ -> Build Type์„ Dockerfile๋กœ ํ•ด์ค€๋‹ค.

๊ทผ๋ฐ ์ง€์†์ ์œผ๋กœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๊ฐ์ง€ํ•˜๋ ค๋ฉด ํŠธ๋ฆฌ๊ฑฐ๋ผ๋Š”๊ฒŒ ํ•„์š”ํ•œ๋ฐ

์ด๊ฑด cloudbuild.yamlํŒŒ์ผ์„ ํ†ตํ•ด Cloud Run์— ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ  ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค


# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START cloudbuild_run_example_builddeploy]
steps:
  # Build the container image
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/${{ secrets.GCE_PROJECT }}/gcollector', '.']
  # Push the container image to Container Registry
  - name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/${{ secrets.GCE_PROJECT }}/gcollector']
  # Deploy container image to Cloud Run
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['run', 'deploy', 'gcollector', '--image', 'gcr.io/${{ secrets.GCE_PROJECT }}/gcollector', '--region', 'us-east1-b', '--platform', 'managed', '--allow-unauthenticated']
images:
  - gcr.io/${{ secrets.GCE_PROJECT }}/gcollector
# [END cloudbuild_run_example_builddeploy]

 

GCE_PROJECT๊ฐ€ ํ”„๋กœ์ ํŠธ id์ด๋‹ค

gcollector๋Š” ์ด๋ฏธ์ง€ ์ด๋ฆ„์„ ๋œปํ•œ๋‹ค!

 

 

 

 

์ฐธ๊ณ ์ž๋ฃŒ

https://medium.com/google-cloud-apac/gcp-serverless-%EC%84%9C%EB%B9%84%EC%8A%A4%EC%9D%B8-cloud-run-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0-1%EB%B6%80-cloud-run-%EA%B0%9C%EC%9A%94-f2e8561ae179

 

[GCP]Serverless ์„œ๋น„์Šค์ธ Cloud Run ์•Œ์•„๋ณด๊ธฐ 1๋ถ€โ€Š—โ€ŠCloud Run ๊ฐœ์š”

์•ˆ๋…•ํ•˜์„ธ์š” ์ด์ •์šด ์ž…๋‹ˆ๋‹ค.

medium.com

 

728x90

'DevOps' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Springboot] Docker+Elastic Beanstalk +Github action ๋‹ฌ๊ณ  CI/CDํ•ด๋ณด์ž!  (0) 2023.01.14