From 9a855d1dc7f4958c079167aed026c8f37664f245 Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 01:35:57 +0800 Subject: [PATCH 1/7] Update deploy.yml to enable manual trigger --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a8cda7c..5a89a03 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,6 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: jobs: setup-build-publish-deploy: From be5ea6a7e312c721e3024c5940ec264eec9d99f4 Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 01:54:39 +0800 Subject: [PATCH 2/7] Update deploy.yml for GCloud action v2 --- .github/workflows/deploy.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a89a03..e43dbcf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,12 +16,20 @@ jobs: - name: Checkout uses: actions/checkout@master - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@v0 + - id: 'auth' + uses: 'google-github-actions/auth@v2' with: - service_account_email: ${{ secrets.GCP_EMAIL }} - service_account_key: ${{ secrets.GCP_CREDENTIALS }} - export_default_credentials: true + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v2' + + # Setup gcloud CLI + # - uses: google-github-actions/setup-gcloud@v2 + # with: + # service_account_email: ${{ secrets.GCP_EMAIL }} + # service_account_key: ${{ secrets.GCP_CREDENTIALS }} + # export_default_credentials: true # Configure Docker with Credentials - name: Configure Docker From fa4002d73ba9728e9e4a1bbe53ab45bb99063b3b Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 02:10:30 +0800 Subject: [PATCH 3/7] Update deploy.yml to add environment --- .github/workflows/deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e43dbcf..c3f30e2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,8 +11,9 @@ jobs: setup-build-publish-deploy: name: Setup, Build, Publish, and Deploy runs-on: ubuntu-latest + environment: GCP Deploy steps: - + - name: Checkout uses: actions/checkout@master From f6bdffea89811a35b39743c7dad6819070f71af7 Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 02:24:57 +0800 Subject: [PATCH 4/7] Update deploy.yml --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c3f30e2..050a5ab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -39,8 +39,8 @@ jobs: # Build the Docker image - name: Build & Publish + # gcloud config set project ${{ secrets.GCP_PROJECT }} run: | - gcloud config set project ${{ secrets.GCP_PROJECT }} gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_APPLICATION }} gcloud config set run/region us-central1 From 85d9c93c2f41df48bb9281a230049a6129c017bb Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 09:39:52 +0800 Subject: [PATCH 5/7] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 8b38008..05ff2b7 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,18 @@ In order for this to be provisioned on your Google Cloud instance, you need to m * GCP_PROJECT You'll also need to activate a couple of APIs in Google Cloud, the first deployment will probably fail and point you into the right direction. Alternatively, you could deploy the first version manually. + +## Updates + +### Changed GCP action to version 2 + +This is to fix the deprecation error on version 0 before. + +The new version requires different authentication semantics. A separate auth action is added, depending only on the JSON key of an GCP service account, from the `GCP_CREDENTIALS`; `GCP_EMAIL` is no longer needed. + +### Workflow change for the forked repo + +We add an GitHub environment for storing the deployment credentials. This is added to the `deploy.yml` script, so the workflow can access the credentials variables, including the GCP service account key. + +The GCP service account used in this project is created as an Editor role, under a GCP project. It thus only have access to this project and do not need to switch project in the `gcloud` shell. + From b821f28dab3e74192a384a8b2b0aa548cd7d0ab3 Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 09:48:59 +0800 Subject: [PATCH 6/7] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 05ff2b7..27546b7 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ You'll also need to activate a couple of APIs in Google Cloud, the first deploym ## Updates +### Web Access + +https://nodejsapi-hkqcqmboga-uc.a.run.app + ### Changed GCP action to version 2 This is to fix the deprecation error on version 0 before. From ca976350ff5b50591d16bef88eea448d5b66e7fb Mon Sep 17 00:00:00 2001 From: Li Yunfan Date: Sat, 13 Apr 2024 10:18:32 +0800 Subject: [PATCH 7/7] Add website --- Dockerfile | 5 +++++ README.md | 1 + app.js | 2 ++ site.html | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 site.html diff --git a/Dockerfile b/Dockerfile index e329115..f63aa11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,9 +11,14 @@ RUN npm install -g express-generator RUN npm install express --save RUN useradd -ms /bin/bash user COPY app.js /home/user/app.js +COPY site.html /home/user/index.html +COPY gcp_iam.png /home/user/gcp_iam.png COPY start.sh /home/user/start.sh RUN chmod a+x /home/user/start.sh USER user WORKDIR /home/user +RUN mkdir public +RUN mv /home/user/index.html /home/user/public/index.html +RUN mv /home/user/gcp_iam.png /home/user/public/gcp_iam.png CMD ["sh","/home/user/start.sh"] diff --git a/README.md b/README.md index 27546b7..f96ed7b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ You'll also need to activate a couple of APIs in Google Cloud, the first deploym ### Web Access https://nodejsapi-hkqcqmboga-uc.a.run.app +https://nodejsapi-hkqcqmboga-uc.a.run.app/site ### Changed GCP action to version 2 diff --git a/app.js b/app.js index b37ca53..2703f25 100644 --- a/app.js +++ b/app.js @@ -32,6 +32,8 @@ app.get("/random", (req, res, next) => { res.json([Math.floor(Math.random() * 90) + 10]); }); +app.use('/site', express.static('public')); + app.get('*',function (req, res) { res.redirect('/'); }); diff --git a/site.html b/site.html new file mode 100644 index 0000000..5762129 --- /dev/null +++ b/site.html @@ -0,0 +1,2 @@ +Hello, this is a static HTML page. +Sample Image