GCE 和 Github Action

警告
本文最后更新于 2021-03-21,文中内容可能已过时。

通过 Github Action 部署应用, 此方法可能有些权限问题。

https://i.imgur.com/ChfuppX.png

https://i.imgur.com/Xzimap8.png

https://i.imgur.com/cFA9cGQ.png

https://i.imgur.com/6Cs4qIe.png

进入Github账户 -> Action -> New workflow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
name: GCE Deploy

on:
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@master
        with:
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          export_default_credentials: true

#       - name: Use gcloud CLI
#         run: |
#           gcloud info
#           gcloud compute instances list

      - name: Copy files to GCE
        run: gcloud compute scp --port=${{ secrets.PORT }} --zone=us-central1-f --recurse SOURCE_FILES INSTANCE_NAME:TARGET_DIR_NAME

Setting -> Secrets

https://i.imgur.com/mx8o1BM.png

https://i.imgur.com/8godmO0.png


(gcloud.beta.compute.scp) Could not add SSH key to instance metadata permissions

setup-gcloud GitHub Action

gcloud compute scp