2

I'd like to automate the deployment of Docker containers to a VPS, using gcloud auth configure-docker to set the proper docker credentials on the VPS. This works fine when I'm

  • A: logged in as root in the online console in Webmin
  • B: logged in as root trough SSH from a Windows 11 terminal
  • C: logged in as (let's say) myuser trough SSH from a Windows 11 terminal

So, for example, I can do from Windows 11:

ssh myuser@vpsip
*type in password*
gcloud auth configure-docker

The problem is, the same command fails when I try to execute it from a Github Actions pipleine:

- name: Deploy Docker image to VPS
        uses: appleboy/ssh-action@v0.1.7
        with:
          host: vpsip
          username: myuser
          password: mypassword
          port: myport
          script: | 
            whoami
            ls
            gcloud auth configure-docker

This is incredibly weird since the whoami command returns myuser, so I'd consider that validated. The ls command also runs fine, so the login was successful, but the gcloud command fails with the error: "err: bash: line 2: gcloud: command not found"

My conclusion is that the pipeline or appleboy's action somehow messes up something, since I definitely can use the gcloud command with user "myuser" trough SSH if I start a session from a normal Windows 11 terminal.

The VPS is running Ubuntu 18.

Thank you!

Bence Mányoki
  • 257
  • 1
  • 8
  • did you already see this action? https://github.com/google-github-actions/setup-gcloud – Matteo Feb 27 '23 at 13:20
  • 1
    Did you try to verify the installed `gcloud` command using `find`? – Azeem Feb 27 '23 at 13:30
  • @Matteo Said action is supposed to setup gcloud on the runner machine that executes the pipeline. My goal is to setup gcloud via SSH on my VPS, which is a completely separate machine. – Bence Mányoki Feb 27 '23 at 16:04
  • @Azeem I have zero linux experience, and could not find anything regarding "how to verify if linux command exists with find". Any additional info on how to do this is appreciated! – Bence Mányoki Feb 27 '23 at 16:08
  • 1
    @BenceMányoki: Using direct SSH to that machine, run `which gcloud` and note down the path (as you said it works with direct SSH so it should return a valid path for the `gcloud` command). Then, in your workflow, you can use the same path with the `ls` command i.e. `ls /path/to/glcoud` to verify whether it's there or not. – Azeem Feb 28 '23 at 04:44
  • 1
    @Azeem Ran: `ls /home/myuser/google-cloud-sdk/bin` than `gcloud -v`. Results are: `out: gcloud` and `gcloud: command not found`. If I'm not mistaken, this means the executable is there, but the linux terminal just wont find it for some reason. – Bence Mányoki Mar 01 '23 at 10:22
  • 1
    @BenceMányoki: Did running `which gcloud` after SSH directly returned `/home/myuser/google-cloud-sdk/bin` path? – Azeem Mar 01 '23 at 10:25
  • @Azeem Yes, from my windows laptops ssh session `which gcloud` returned `/home/myuser/google-cloud-sdk/bin/gcloud`. I haven't tried running `which gcloud` in the pipeline yet. – Bence Mányoki Mar 01 '23 at 10:30
  • @Azeem But I've tried running `bash /home/myuser/google-cloud-sdk/bin/gcloud auth configure-docker`, and it works! Wonderful! Now I can progress with the work I wanted to get done 3 days ago :'D but anyways, it'd still be interesting to know why it doesn't find the executable from one SSH session, and it does from another... – Bence Mányoki Mar 01 '23 at 10:33
  • @BenceMányoki: So, when you SSH via that action, it's not added in the `PATH`. Simple solution: SSH directly to that machine, create a symlink i.e. `sudo ln -s $HOME/google-cloud-sdk/bin/gcloud /usr/bin` and it should work after that. – Azeem Mar 01 '23 at 10:54
  • @BenceMányoki: Also, check the output of `cat ~/.bashrc | grep google-cloud-sdk` on that machine. – Azeem Mar 01 '23 at 11:17

0 Answers0