diff --git a/tfgrid3/tfrobot/Dockerfile b/tfgrid3/tfrobot/Dockerfile index 56e3bfb0..5ced11d4 100644 --- a/tfgrid3/tfrobot/Dockerfile +++ b/tfgrid3/tfrobot/Dockerfile @@ -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"] diff --git a/tfgrid3/tfrobot/scripts/tfrobot.sh b/tfgrid3/tfrobot/scripts/tfrobot.sh new file mode 100644 index 00000000..38c64d0f --- /dev/null +++ b/tfgrid3/tfrobot/scripts/tfrobot.sh @@ -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 diff --git a/tfgrid3/tfrobot/zinit/ssh_config.yaml b/tfgrid3/tfrobot/zinit/ssh_config.yaml index 6e497a76..38f75504 100644 --- a/tfgrid3/tfrobot/zinit/ssh_config.yaml +++ b/tfgrid3/tfrobot/zinit/ssh_config.yaml @@ -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 \ No newline at end of file +oneshot: true diff --git a/tfgrid3/tfrobot/zinit/tfrobot_init.yaml b/tfgrid3/tfrobot/zinit/tfrobot_init.yaml new file mode 100644 index 00000000..7bbfec5b --- /dev/null +++ b/tfgrid3/tfrobot/zinit/tfrobot_init.yaml @@ -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