Giter Site home page Giter Site logo

Comments (6)

linusphan avatar linusphan commented on June 18, 2024 1

@legorie No problem! It's not your fault; technologies change fast, and this has probably been especially true with GCP :) That's cool that you've made changes though so future readers will have less trouble.

from google-cloud-platform-cookbook.

mehrazh avatar mehrazh commented on June 18, 2024 1

Thanks for the update @legorie

from google-cloud-platform-cookbook.

jacobleecd avatar jacobleecd commented on June 18, 2024

@mehrazh I also got this error. Apparently, GCP no longer supports debian 8. I tried to run the code on debian 9 and got numerous errors that I've been picking through since, but with no resolution. For instance, the code in the startup had to been changed to run the mongodb version that debian 9 runs and not debian 8. Following that fix, I get syntax errors that I'm unsure how to resolve. Have you figured this out?

from google-cloud-platform-cookbook.

mehrazh avatar mehrazh commented on June 18, 2024

Yeah I ended up disregarding the startup script all together. Instead, I came up with my own steps to deploy keystone on GCE. Here's what worked for me:
https://docs.google.com/document/d/18DsAIVfkuLrFSLlhy1lDq3oSWRnpnZjNvzBWDZsBmZ4/edit

from google-cloud-platform-cookbook.

linusphan avatar linusphan commented on June 18, 2024

I was able to get it working, and there are a few changes that need to be made. The problem lies in the startup-script.sh file. First, I noticed that the compute engine that is instantiated is lacking a package that is needed (if I recall correctly, needed to install mongodb). The missing package appeared to have been dirmngr and so I added a block of code that would add it. As jacobleecd mentioned, debian-8 is apparently no longer supported but debian-9 is (thus, set --image-family=debian-9 rather than debian-8 in the gcloud command to create the GCE instance) so you got to change the apt-key as well as the repo link to get the right mongodb. Then you get syntax error. The syntax error seems to be coming from using an older version of node that doesn't support ES6 syntax (specifically, destructuring assignment and possibly others). So then I changed the version of node that's installed. Other notes: remember to update the URL of git clone so that you are cloning the right one.

Here's the startup-script.sh file that I ended up with (remember to change the git clone link to match your repository on GCP Source Repositories):

#! /bin/bash
#url : https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/7-gce/gce/startup-script.sh
# Copyright 2017, Google, Inc.
# 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 startup]
set -v

# Talk to the metadata server to get the project id
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")

# Install logging monitor. The monitor will automatically pick up logs sent to
# syslog.
# [START logging]
curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash
service google-fluentd restart &
# [END logging]

# Preparing to install mongodb
sudo apt remove gnupg
sudo apt install --reinstall gnupg2
sudo apt install dirmngr

# Installing mongodb
curl https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
cat > /etc/systemd/system/mongodb.service << EOF
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
EOF
systemctl start mongodb
systemctl enable mongodb

# Install dependencies from apt
apt-get install -yq ca-certificates git nodejs build-essential supervisor

# Install nodejs
mkdir /opt/nodejs
curl https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.gz | tar xvzf - -C /opt/nodejs --strip-components=1
ln -s /opt/nodejs/bin/node /usr/bin/node
ln -s /opt/nodejs/bin/npm /usr/bin/npm

# Get the application source code from the Google Cloud Repository.
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/gcp-cookbook-book/r/gcpcookbook-repo  /opt/app

# Install app dependencies
cd /opt/app/Chapter01/mysite
npm install
cat >./.env << EOF
COOKIE_SECRET=d44d5c45e7f8149aabc06a830dba5716b4bd952a639c82499954
MONGODB_URI=mongodb://localhost:27017
EOF

# Create a nodeapp user. The application will run as this user.
useradd -m -d /home/nodeapp nodeapp
chown -R nodeapp:nodeapp /opt/app

# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/opt/app/Chapter01/mysite
command=npm start
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF

supervisorctl reread
supervisorctl update

# Application should now be running under supervisor
# [END startup]

Should there be any more problems, SSH'ing into the compute engine instance, then cd'ing into the directory indicated in the startup-script.sh, which is /opt/app/Chapter01/mysite, then running npm start and seeing if there are any errors or seeing what specific errors are outputted in the "terminal" might help. I hope others find this useful!

from google-cloud-platform-cookbook.

legorie avatar legorie commented on June 18, 2024

Thank you @mehrazh for reporting the issue. I've made changes to the startup-script to avoid confusion to future readers as suggested. Thanks to @linusphan and @jacobleecd for your inputs.
Apologies for not getting to the issue quicker.

from google-cloud-platform-cookbook.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.