deploy website using ssh

hey guys , I'm new to space , I have a small website and a small project that I'm trying to develop .

this part of website is a simple template and I just need to sync files between repository and server.

my server is an ubuntu server right now .

I tried to use jobs for this and execute SSH commands and then using git pull on the server , but couldn't find a complete guide for it . 

so I'm completely lost on it , is there anything that i can do ? do you think using docker may help ? any suggestions ?

I was considering migrating to GitLab for CI/DI , but i want it to work on space .

I appreciate your help .

0
4 comments

Hello! There's no specific guide for it, however, I'll be glad to assist you with this case. Using Space automation for it seems to be a good solution. In general, the process should be the following:

  1. `gitPush` event to the Space repository triggers the automation job.
  2. Automation job runs the Ubuntu Docker container with Bash commands to connect to your server and notify it about the update. This step may require using Secrets and Parameters for passing SSH keys to the job.
  3. The server executes a `git pull` command connecting to the Space repository. This step may require registering a Space Client Application to authenticate in Space easily.

Could you please try this flow and let me know if any additional questions appear?

Thanks!

1

I have found this post searching for "jetbrains space ssh deployment". I have solved it this way:

1. Create SSH connection parameters

Go to Settings -> Secrets & Parameters

Create following Parameters (key: value):

  • VPS_CMD: name of the bash script which needs to be executed, e.g. /home/user/run.sh
  • VPS_HOST: SSH server hostname, e.g. target.com
  • VPS_PORT: SSH port, e.g. 22
  • VPS_PORT: SSH server username, e.g. user

Create following Secrets (key: value):

  • VPS_KEY: SSH private key

Hint: The editor may give you following message entering your SSH private key:

This value contains leading or trailing whitespace characters. If this is unintended, please remove them.

Please ignore this message and leave the trailing carriage return or the private key cannot be used (you'll get a format error).

2. Add Space Automation

Add the file .space.kts to your repository

job("Build and push Docker") {
parameters {
secret("private-key", "{{ project:VPS_KEY }}")
}
host("Build and push a Docker image") {
fileInput {
source = FileSource.Text("{{ private-key }}")
localPath = "/root/.ssh/id_rsa"
}
dockerBuildPush {
labels["vendor"] = "Han Solo"
tags {
+"hansolo.registry.jetbrains.space/p/millenium/containers/falcon:1.0.${"$"}JB_SPACE_EXECUTION_NUMBER"
}
}
shellScript {
content = """
set -e
chmod 0400 /root/.ssh/id_rsa
ssh -i /root/.ssh/id_rsa -o "StrictHostKeyChecking=no" {{ project:VPS_USERNAME }}@{{ project:VPS_HOST }} -p {{ project:VPS_PORT }} {{ project:VPS_CMD }}
"""
}
}
}
Hint: You want to modify the container settings (vendor label, tags) or don't use that at all.
 

3. Prepare SSH target server

Add SSH public key

Add the SSH public key to /home/user/.ssh/authorized_keys (adjust the username)

Add deployment script

Do whatever you like, e.g. /home/user/run.sh

#!/bin/sh
cd /home/user/git/falcon/
git pull
do_something
Hint: Clone you repository in /home/user/git/falcon/ using SSH key based authentication for example:
git clone ssh://git@git.jetbrains.space/han/millenium/falcon.git
1

thans Benjamin Krueger. this is vey usefull and exactly what i need to do but i am stuck à this step :

Create following Secrets (key: value):

  • VPS_KEY: SSH private key

I can't manage to create my SSH private key on space. How can i do that?

0

Hello Mouhotpe , if you have created a key pair (using ssh-keygen on Linux or WSL on Windows for example) you'll have two files:

  • Your public key (id_rsa.pub) ← Just copy or add this one to your .ssh/authorized_keys file on the target server, it says “whoever has the matching secret private key - let that user in”
  • Your private key (id_rsa) ← You need to add this one in your Space (https://xyz.jetbrains.space/), select your project, choose “Settings” in the left menu, then “Secrets & Parameters” on the right page. It's very important so add this value as secret not as parameter so it won't be visible in the log files - your private keys should remain private 

Just let me know if you're still stuck somewhere.

0

Please sign in to leave a comment.