Common task for all prog. languages
Create a Google Compute Engine VM instance through web interface
- Compute engine > VM instances > create
- In identity and API access select Allow full access to all Cloud APIs
- In Firewall, allow HTTP traffic
Node.js
Provision a Google Compute Engine VM and install software libraries for Node.js development on GCP.
sudo apt update
sudo apt install git
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - # install node
sudo apt install nodejs # install npm (Node Package Manager) and Node.js
sudo node server/app.js # run web server
npm install # install Node.js library for Compute Engine
node list-gce-instances.js # run Node.js that lists Compute Engine instances
Java
Install a Java library on the instance.
sudo apt update
sudo apt install git -y
sudo apt install -yq openjdk-8-jdk
# make java8 default
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
sudo apt install -yq maven
# redirects entries on 80 to 8080
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
# export proyect ID as environment variable
export GCLOUD_PROJECT="$(curl -H Metadata-Flavor:Google http://metadata/computeMetadata/v1/project/project-id)"
mvn clean install
mvn spring-boot:run
mvn exec:java@list-gce # lists Compute Engine instances
Python
Install a Python library on the instance.
sudo apt update
sudo apt install git
sudo apt install python3-setuptools python3-dev build-essential
install pip - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
sudo python3 server.py