Skip to content

Commit

Permalink
supporting tfrobot version passed to flist and multiple ssh support
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterNashaat committed Sep 1, 2024
1 parent 2fa5282 commit 2e12bb7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
8 changes: 2 additions & 6 deletions tfgrid3/tfrobot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ RUN curl -s https://api.github.com/repos/threefoldtech/zinit/releases/latest | \

RUN chmod +x /sbin/zinit
COPY scripts/ufw.sh /usr/local/bin/
COPY scripts/tfrobot.sh /usr/local/bin/

# Adding zinit config files
ADD zinit /etc/zinit/

# Install latest tfrobot
RUN tfrobot_version=$(curl -s https://api.github.com/repos/threefoldtech/tfgrid-sdk-go/releases/latest | grep 'tag_name' | cut -d '"' -f 4 ) && \
wget "https://github.com/threefoldtech/tfgrid-sdk-go/releases/download/${tfrobot_version}/tfgrid-sdk-go_Linux_x86_64.tar.gz" && \
tar -xzf tfgrid-sdk-go_Linux_x86_64.tar.gz -C /usr/local/bin/

# Cleaning up
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* tfgrid-sdk-go_Linux_x86_64.tar.gz
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Starting Command
CMD ["/sbin/zinit", "init", "--container"]
26 changes: 26 additions & 0 deletions tfgrid3/tfrobot/scripts/tfrobot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Script to download the latest version of tfrobot if version was not passed as env variable

download_latest_tfrobot() {
echo "No version provided, downloading the latest version..."
tf_v=$(curl -s https://api.github.com/repos/threefoldtech/tfgrid-sdk-go/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
echo "Downloading latest version: $tf_v"
wget -O "Latest.tar.gz" "https://github.com/threefoldtech/tfgrid-sdk-go/releases/download/${tf_v}/tfgrid-sdk-go_Linux_x86_64.tar.gz"
tar -xzf Latest.tar.gz -C /usr/local/bin/
rm -rf /Latest.tar.gz
echo "tfrobot version ${tf_v} installed successfully."
}

# Check if a version was provided as an argument
if [ -z "$1" ]; then
echo "No version argument provided."
download_latest_tfrobot
else
tf_v=$1
echo "Downloading specified version: ${tf_v}..."
wget -O "tfrobot_version.tar.gz" "https://github.com/threefoldtech/tfgrid-sdk-go/releases/download/${tf_v}/tfgrid-sdk-go_Linux_x86_64.tar.gz"
tar -xzf tfrobot_version.tar.gz -C /usr/local/bin/
rm -rf /tfrobot_version.tar.gz
echo "tfrobot version ${tf_v} installed successfully."
fi
3 changes: 1 addition & 2 deletions tfgrid3/tfrobot/zinit/ssh_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ exec: /bin/sh -eux -c "
chmod 600 /etc/ssh/*;
touch ~/.ssh/authorized_keys;
chmod 600 ~/.ssh/authorized_keys;
echo $SSH_KEY > /root/.ssh/authorized_keys;
echo 'ssh configred'"
oneshot: true
oneshot: true
8 changes: 8 additions & 0 deletions tfgrid3/tfrobot/zinit/tfrobot_init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exec: /bin/sh -eux -c "
chmod +x /usr/local/bin/tfrobot.sh;
if [ -z ${tfrobot_version:-} ]; then
bash tfrobot.sh;
else
bash tfrobot.sh $tfrobot_version;
fi"
oneshot: true

0 comments on commit 2e12bb7

Please sign in to comment.