etc.

github actions으로 GCP app engine 배포하기

hid1 2023. 4. 17. 18:09

 

github actions을 사용하여 GCP App Engine에 서버 배포를 자동화하려 한다.

 

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3
        with:
          submodules: "recursive"
      - name: Auth to GCP
        uses: "google-github-actions/auth@v1"
        with:
          credentials_json: ${{ secrets.GCE_SA_KEY }}
      - name: Deploy to App Engine
        uses: google-github-actions/deploy-appengine@v1
        with:
          working_directory: server
          project_id: ${{ secrets.GCP_PROJECT }}

 

먼저 구글 클라우드에 인증하기 위해 google-github-actions/auth 액션을 사용하였다. 계정 인증을 위해서 나는 서비스 계정 키 JSON을 통한 방법을 사용하였다. credentials_json에 서비스 계정 키에 대한 JSON을 넣으면 된다. 

 

GitHub - google-github-actions/auth: A GitHub Action for authenticating to Google Cloud.

A GitHub Action for authenticating to Google Cloud. - GitHub - google-github-actions/auth: A GitHub Action for authenticating to Google Cloud.

github.com

 

 

이때 서비스 계정 키에 대한 JSON을 발급 받으려면 일단 GCP에서 서비스 계정을 생성해야 한다. 생성 과정에서 배포에 필요한 역할을 지정해야 한다. 접근 권한 때문에 몇 번의 에러를 만난 끝에 아래와 같이 권한을 부여했더니 정상적으로 잘 작동하였다. (이 과정에 필요 없는 역할이 있을 수도 있다..)

 

 

 

 

생성된 서비스 계정에서 키 관리에 들어가 새 키 만들기를 통해 JSON으로 확인을 누르면 JSON 파일이 다운로드 받아진다.

 

이 JSON의 내용을 복사한 후 배포 하려는 해당 깃헙 레포지토리의 설정 - Actions secrets and variables에서 secrets을 추가하여 붙여넣기 하면 된다. 이후 필요한 프로젝트 아이디도 따로 추가하였다. credentials_json에  ${{ secrets.내가설정한secrets이름 }}을 넣어주면 된다.

- name: Auth to GCP
        uses: "google-github-actions/auth@v1"
        with:
          credentials_json: ${{ secrets.GCE_SA_KEY }}

 

 

 

이제 google-github-actions/deploy-appengin 액션을 사용하여 배포 설정을 하면 된다.

 

GitHub - google-github-actions/deploy-appengine: A GitHub Action that deploys source code to Google App Engine.

A GitHub Action that deploys source code to Google App Engine. - GitHub - google-github-actions/deploy-appengine: A GitHub Action that deploys source code to Google App Engine.

github.com

 

 - name: Deploy to App Engine
	uses: google-github-actions/deploy-appengine@v1
	with:
		working_directory: server
		project_id: ${{ secrets.GCP_PROJECT }}

 

나는  working_directory를 사용하여 배포를 진행 할 폴더를 지정하였고 project_id도 명시해주었다. 위의 링크를 들어가서 상황에 맞게 설정을 하면 될 것 같다. 

 

 

 

 

 

 

 

반응형