From e3bbf60e939e6f80c427c142ccc64bd8d9c0496b Mon Sep 17 00:00:00 2001 From: Roger Martinez <31829545+rogerthatdev@users.noreply.github.com> Date: Thu, 27 Jul 2023 17:05:18 -0700 Subject: [PATCH 1/2] feat(run): add GCSFuse files to filesystem sample (#3368) * gcsfuse run script * gcsfuse Dockerfile * region tag --- run/filesystem/gcsfuse.Dockerfile | 59 +++++++++++++++++++++++++++++++ run/filesystem/gcsfuse.run.sh | 31 ++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 run/filesystem/gcsfuse.Dockerfile create mode 100644 run/filesystem/gcsfuse.run.sh diff --git a/run/filesystem/gcsfuse.Dockerfile b/run/filesystem/gcsfuse.Dockerfile new file mode 100644 index 0000000000..bcc1ff0f8f --- /dev/null +++ b/run/filesystem/gcsfuse.Dockerfile @@ -0,0 +1,59 @@ +# Copyright 2023 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 cloudrun_fuse_dockerfile] + +# Use the official Node.js image. +# https://hub.docker.com/_/node +FROM node:20-slim + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + curl \ + gnupg \ + lsb-release \ + tini && \ + gcsFuseRepo=gcsfuse-`lsb_release -c -s` && \ + echo "deb http://packages.cloud.google.com/apt $gcsFuseRepo main" | \ + tee /etc/apt/sources.list.d/gcsfuse.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ + apt-key add - && \ + apt-get update && \ + apt-get install -y gcsfuse && \ + apt-get clean + +# Set fallback mount directory +ENV MNT_DIR /mnt/gcs + +# Copy local code to the container image. +ENV APP_HOME /app +WORKDIR $APP_HOME +COPY package*.json ./ + +# Install production dependencies. +RUN npm install --only=production + +# Copy local code to the container image. +COPY . ./ + +# Ensure the script is executable +RUN chmod +x /app/gcsfuse.run.sh + +# Use tini to manage zombie processes and signal forwarding +# https://github.com/krallin/tini +ENTRYPOINT ["/usr/bin/tini", "--"] + +# Pass the wrapper script as arguments to tini +CMD ["/app/gcsfuse.run.sh"] +# [END cloudrun_fuse_dockerfile] \ No newline at end of file diff --git a/run/filesystem/gcsfuse.run.sh b/run/filesystem/gcsfuse.run.sh new file mode 100644 index 0000000000..78c9f94131 --- /dev/null +++ b/run/filesystem/gcsfuse.run.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Copyright 2023 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 cloudrun_fuse_script] +#!/usr/bin/env bash +set -eo pipefail + +# Create mount directory for service +mkdir -p $MNT_DIR + +echo "Mounting GCS Fuse." +gcsfuse --debug_gcs --debug_fuse $BUCKET $MNT_DIR +echo "Mounting completed." + +# Start the application +node index.js & + +# Exit immediately when one of the background processes terminate. +wait -n +# [END cloudrun_fuse_script] \ No newline at end of file From e2bbb0c299dc92b9a73c5c836e74991221b7fe72 Mon Sep 17 00:00:00 2001 From: Roger Martinez <31829545+rogerthatdev@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:48:21 -0700 Subject: [PATCH 2/2] fix: rename gcsfuse script (#3369) * run node index.js in bg; rename gcsfuse sh script * update name in dockerfile too --- run/filesystem/gcsfuse.Dockerfile | 4 ++-- run/filesystem/{gcsfuse.run.sh => gcsfuse_run.sh} | 0 run/filesystem/run.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename run/filesystem/{gcsfuse.run.sh => gcsfuse_run.sh} (100%) diff --git a/run/filesystem/gcsfuse.Dockerfile b/run/filesystem/gcsfuse.Dockerfile index bcc1ff0f8f..c96e180ebb 100644 --- a/run/filesystem/gcsfuse.Dockerfile +++ b/run/filesystem/gcsfuse.Dockerfile @@ -48,12 +48,12 @@ RUN npm install --only=production COPY . ./ # Ensure the script is executable -RUN chmod +x /app/gcsfuse.run.sh +RUN chmod +x /app/gcsfuse_run.sh # Use tini to manage zombie processes and signal forwarding # https://github.com/krallin/tini ENTRYPOINT ["/usr/bin/tini", "--"] # Pass the wrapper script as arguments to tini -CMD ["/app/gcsfuse.run.sh"] +CMD ["/app/gcsfuse_run.sh"] # [END cloudrun_fuse_dockerfile] \ No newline at end of file diff --git a/run/filesystem/gcsfuse.run.sh b/run/filesystem/gcsfuse_run.sh similarity index 100% rename from run/filesystem/gcsfuse.run.sh rename to run/filesystem/gcsfuse_run.sh diff --git a/run/filesystem/run.sh b/run/filesystem/run.sh index cc8f190e8e..e0ae632df4 100644 --- a/run/filesystem/run.sh +++ b/run/filesystem/run.sh @@ -25,7 +25,7 @@ mount -o nolock $FILESTORE_IP_ADDRESS:/$FILE_SHARE_NAME $MNT_DIR echo "Mounting completed." # Start the application -node index.js +node index.js & # Exit immediately when one of the background processes terminate. wait -n