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๋ ์ด๋ฏธ์ง ์ด๋ฆ์ ๋ปํ๋ค!
์ฐธ๊ณ ์๋ฃ
[GCP]Serverless ์๋น์ค์ธ Cloud Run ์์๋ณด๊ธฐ 1๋ถโ—โCloud Run ๊ฐ์
์๋ ํ์ธ์ ์ด์ ์ด ์ ๋๋ค.
medium.com
'DevOps' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Springboot] Docker+Elastic Beanstalk +Github action ๋ฌ๊ณ CI/CDํด๋ณด์! (0) | 2023.01.14 |
---|