I am currently struggling on the fact to generate an instance and directly run some code regarding Google Compute Engine. The main issue I have is that it works with a public repo ut if I want to clone a private repo, it doesn't work anymore...
I tried a lot of workarounds and until now I couldn't find any situation. I have this startup-script.sh :
#!/usr/bin/env bash
set -ex
# Talk to the metadata server to get the project id and location of application binary.
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
# Install logging monitor. The monitor will automatically pickup logs send to
# syslog.
sudo curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | sudo bash
sudo service google-fluentd restart &
# Install dependencies from apt (I actually need them)
sudo apt-get update
sudo apt-get install -yq ca-certificates supervisor git emacs redis-server
#############
# Here I have to setup my SSH key but what are my possibilities?
#############
# Cloning my repo
git clone git@gitlab.com:MY-AWESOME-SERVICE.git service
# Create a goapp user. The application will run as this user.
sudo getent passwd goapp || sudo /usr/sbin/useradd -m -d /home/goapp goapp
sudo chown -R goapp:goapp service
# Configure supervisor to run the Go app.
sudo echo "
[program:goapp]
directory=/service
command=/service/main
autostart=true
autorestart=true
user=goapp
environment=HOME=\"/home/goapp\",USER=\"goapp\"
stdout_logfile=syslog
stderr_logfile=syslog
" > goapp.conf
sudo mv goapp.conf /etc/supervisor/conf.d/goapp.conf
sudo supervisorctl reread
sudo supervisorctl update
# Application should now be running under supervisor
I saw a couple of stuff about ssh-copy-id but I am not sure to fully understand how does it work
Thanks for any help!