Skip to content

Commit d3e6f60

Browse files
iennaegrayside
andauthored
fix: update to modern Node.js and remove source repos (#636)
* fix: update to modern Node.js and remove source repos * fix: remove duplicate HOME export. * fix: add error handling exit immediately if a command exits with non-zero status * fix: remove unused variable (no longer using source repos) --------- Co-authored-by: Adam Ross <[email protected]>
1 parent 7dcdb35 commit d3e6f60

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

gce/startup-script.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
# limitations under the License.
1414

1515
# [START startup]
16-
set -v
16+
set -ve
1717

1818

1919
# Talk to the metadata server to get the project id
2020
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
2121
# [END startup]
2222
echo ${PROJECTID}
2323
# [START startup]
24-
REPOSITORY="new-repo"
2524

2625
# Install logging monitor. The monitor will automatically pick up logs sent to
2726
# syslog.
@@ -32,20 +31,19 @@ service google-fluentd restart &
3231
apt-get update
3332
apt-get install -yq ca-certificates git build-essential supervisor
3433

34+
# git requires $HOME and it's not set during the startup script.
35+
# Fetch source code
36+
export HOME=/root
37+
git clone https://github.com/GoogleCloudPlatform/nodejs-getting-started.git /opt/app
38+
3539
# Install nodejs
3640
mkdir /opt/nodejs
37-
curl https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.gz | tar xvzf - -C /opt/nodejs --strip-components=1
41+
curl https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz | tar xvfJ - -C /opt/nodejs --strip-components=1
3842
ln -s /opt/nodejs/bin/node /usr/bin/node
3943
ln -s /opt/nodejs/bin/npm /usr/bin/npm
4044

41-
# Get the application source code from the Google Cloud Repository.
42-
# git requires $HOME and it's not set during the startup script.
43-
export HOME=/root
44-
git config --global credential.helper gcloud.sh
45-
git clone https://source.developers.google.com/p/${PROJECTID}/r/${REPOSITORY} /opt/app/new-repo
46-
4745
# Install app dependencies
48-
cd /opt/app/new-repo
46+
cd /opt/app/gce
4947
npm install
5048

5149
# Create a nodeapp user. The application will run as this user.
@@ -55,7 +53,7 @@ chown -R nodeapp:nodeapp /opt/app
5553
# Configure supervisor to run the node app.
5654
cat >/etc/supervisor/conf.d/node-app.conf << EOF
5755
[program:nodeapp]
58-
directory=/opt/app/new-repo
56+
directory=/opt/app/gce
5957
command=npm start
6058
autostart=true
6159
autorestart=true

0 commit comments

Comments
 (0)