Deployment to Google Compute Engine

deployment
compute-engine

#21

When you start your phoenix server
I guess when creating the instance and running the instance-startup.sh

what IP is it binding to
Im not sure about this

hello_team@hello-instance:~$ netstat -lnpt | grep 8080
(No info could be read for "-p": geteuid()=1000 but you should be root.)


48%20PM

I’m sorry if I’m not helping. I’m still new at deployment. :sweat:


#22

Then leave of the -p it is not that important. netstat -lnt | grep 8080 will be enough to see if something is listening on port 8080 and which IP it has bound to.

And also, please try to curl your application from the host running it. If its working there, we can put more energy in debugging the networking issue.

What do you guess with that file?

As I said, it should be in the logs.


#23

netstat -lnt | grep 8080 not showing anything
netstat -lnt showing this

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::4369                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN 

curl is working on the server

instance-stratup.sh is the file that run PORT=8080 ./hello-release start
You can refer in the tutorial in section “Create a startup script”


#24

Wait? there is nothing listening on port 8080, but a local curl works fine?


#25

Yup. curl --help does show the list of curl options

hello_team@hello-instance:~$ curl -V
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2q zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

#26

I asked you to curl your application locally. curl localhost:8080 or something like that.

But I assume it wont work.

How exactly are you starting the application? Are you using foreground or start? If you do the former, do you close the connection/terminal or do you keep it open? You application will shut down as soon as the parent process dies. If though you use the latter, please check your logs for any error messages.


#27

Let’s backup abit. Im starting to get confuse now.

So first, I run this command
PORT=8080 _build/prod/rel/hello/bin/hello.run foreground
Without stopping this command I run curl localhost:8080,
It will show the HTML file for the home page

The project runs perfectly when I, PORT=8080 _build/prod/rel/hello/bin/hello.run foreground
There were no errors, the logs from Phoenix does show normally without errors


#28

And while it is still running, what does netstat tell you now? Are you able to access your site from external?


#29
Muhammads-MacBook-Pro:hello Azim$ netstat -lnt | grep 8080
tcp4       0      0  192.168.0.116.49980    192.168.0.157.8080     TIME_WAIT  

I can access the site using localhost:8080 not the remote server


#30

The listener is bound to the IP 192.168.0.157, This does not look like its your external IP.

Try setting http: [ip: {0, 0, 0, 0}, port: …, …] in your config to accept connections on all IPs.


#31

Wait? Why MacBook? Is GCE running on macbooks?


#32

Wait. You want me to run the commands in GCE or my local machine?
Hahaha. Im confuse now :sweat_smile:


#33

Do you want to deploy to GCE or to your local laptop?


#34

I want to deploy to GCE


#35

Then run the commands on GCE.

I want to know on what IP the application binds to, I want to know if it works when you curl the application locally on the remote (yeah, confusing, I know)


#36
hello_team@hello-instance:~$ netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::4369                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN  
hello_team@hello-instance:~$ curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

#37

Is the application currently running?

Until we got that sorted, we need to make sure that you started it manually using … foreground and then not close that terminal, but use another one to do the curl and netstat.


#38

I’m not sure. What I know from the tutorial in “Deploying your application to a single instance” section there’s a instance-startup.sh that I added in the root of my project and the last line in the instance-startup.sh is PORT=8080 ./hello-release start and I just create an instance in GCE by running

gcloud compute instances create hello-instance \
    --image-family debian-9 \
    --image-project debian-cloud \
    --machine-type f1-micro \
    --scopes "userinfo-email,cloud-platform" \
    --metadata-from-file startup-script=instance-startup.sh \
    --metadata release-url=gs://hello-releases/hello-release \
    --zone asia-southeast1-a \
    --tags http-server

In my bucket there’s hello-releases/hello-release


#39

I do not mind the turial. We already have learnt that it for some reasons doesn’t do as we expect.

Please log in to the host, start your application in foreground mode, fire up a second SSH into that host and check curl and netstat, while you are doing this, please also observe the logs of the foreground instance. The curl should show up there.


#40

I’m not sure how to start the application in foreground from the GCE.

hello_team@hello-instance:/$ ls
app  bin  boot  dev  etc  home  initrd.img  initrd.img.old  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  startup-LfE2ig  sys  tmp  usr  var  vmlinuz  vmlinuz.old
hello_team@hello-instance:/$ cd app/
hello_team@hello-instance:/app$ ls
cloud_sql_proxy  hello-release  tmp