diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a8cda7c..050a5ab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,22 +5,32 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: 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 - # 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 @@ -29,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 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 8b38008..f96ed7b 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,23 @@ 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 + +### Web Access + +https://nodejsapi-hkqcqmboga-uc.a.run.app +https://nodejsapi-hkqcqmboga-uc.a.run.app/site + +### 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. + 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