From 17fd1a2e359f412611d883d4f03127878b283118 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Tue, 28 Mar 2023 16:21:14 +0100 Subject: [PATCH] dev: make cni, consul, dev, docker, and vault scripts Lima compat. (#16689) --- Vagrantfile | 10 +++--- ...nt-linux-priv-cni.sh => linux-priv-cni.sh} | 9 ++++- ...ux-priv-consul.sh => linux-priv-consul.sh} | 11 ++++-- ...nt-linux-priv-dev.sh => linux-priv-dev.sh} | 6 ++-- scripts/linux-priv-docker.sh | 34 +++++++++++++++++++ ...inux-priv-vault.sh => linux-priv-vault.sh} | 11 ++++-- scripts/vagrant-linux-priv-docker.sh | 21 ------------ 7 files changed, 69 insertions(+), 33 deletions(-) rename scripts/{vagrant-linux-priv-cni.sh => linux-priv-cni.sh} (68%) rename scripts/{vagrant-linux-priv-consul.sh => linux-priv-consul.sh} (69%) rename scripts/{vagrant-linux-priv-dev.sh => linux-priv-dev.sh} (76%) create mode 100755 scripts/linux-priv-docker.sh rename scripts/{vagrant-linux-priv-vault.sh => linux-priv-vault.sh} (69%) delete mode 100755 scripts/vagrant-linux-priv-docker.sh diff --git a/Vagrantfile b/Vagrantfile index acb812f94..ad3fc062e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -138,23 +138,23 @@ def configureLinuxProvisioners(vmCfg) vmCfg.vm.provision "shell", privileged: true, - path: './scripts/vagrant-linux-priv-dev.sh' + path: './scripts/linux-priv-dev.sh' vmCfg.vm.provision "shell", privileged: true, - path: './scripts/vagrant-linux-priv-docker.sh' + path: './scripts/linux-priv-docker.sh' vmCfg.vm.provision "shell", privileged: true, - path: './scripts/vagrant-linux-priv-consul.sh' + path: './scripts/linux-priv-consul.sh' vmCfg.vm.provision "shell", privileged: true, - path: './scripts/vagrant-linux-priv-cni.sh' + path: './scripts/linux-priv-cni.sh' vmCfg.vm.provision "shell", privileged: true, - path: './scripts/vagrant-linux-priv-vault.sh' + path: './scripts/linux-priv-vault.sh' vmCfg.vm.provision "shell", privileged: false, diff --git a/scripts/vagrant-linux-priv-cni.sh b/scripts/linux-priv-cni.sh similarity index 68% rename from scripts/vagrant-linux-priv-cni.sh rename to scripts/linux-priv-cni.sh index 2939f6dee..1c6ea3085 100755 --- a/scripts/vagrant-linux-priv-cni.sh +++ b/scripts/linux-priv-cni.sh @@ -2,8 +2,15 @@ set -o errexit +# Minimal effort to support amd64 and arm64 installs. +ARCH="" +case $(arch) in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; +esac + VERSION="v1.0.0" -DOWNLOAD=https://github.com/containernetworking/plugins/releases/download/${VERSION}/cni-plugins-linux-amd64-${VERSION}.tgz +DOWNLOAD=https://github.com/containernetworking/plugins/releases/download/${VERSION}/cni-plugins-linux-${ARCH}-${VERSION}.tgz TARGET_DIR=/opt/cni/bin CONFIG_DIR=/opt/cni/config diff --git a/scripts/vagrant-linux-priv-consul.sh b/scripts/linux-priv-consul.sh similarity index 69% rename from scripts/vagrant-linux-priv-consul.sh rename to scripts/linux-priv-consul.sh index 0969e972e..c36a7ebd0 100755 --- a/scripts/vagrant-linux-priv-consul.sh +++ b/scripts/linux-priv-consul.sh @@ -2,8 +2,15 @@ set -o errexit -VERSION="1.10.3" -DOWNLOAD=https://releases.hashicorp.com/consul/${VERSION}/consul_${VERSION}_linux_amd64.zip +# Minimal effort to support amd64 and arm64 installs. +ARCH="" +case $(arch) in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; +esac + +VERSION="1.15.1" +DOWNLOAD=https://releases.hashicorp.com/consul/${VERSION}/consul_${VERSION}_linux_${ARCH}.zip function install_consul() { if [[ -e /usr/bin/consul ]] ; then diff --git a/scripts/vagrant-linux-priv-dev.sh b/scripts/linux-priv-dev.sh similarity index 76% rename from scripts/vagrant-linux-priv-dev.sh rename to scripts/linux-priv-dev.sh index cc702043b..b8e28c047 100755 --- a/scripts/vagrant-linux-priv-dev.sh +++ b/scripts/linux-priv-dev.sh @@ -20,6 +20,8 @@ hostname=$(hostname) sed -i -e "s/.*nomad.*/${ip} ${hostname}/" /etc/hosts # Ensure we cd into the working directory on login -if ! grep "cd /opt/gopath/src/github.com/hashicorp/nomad" /home/vagrant/.profile ; then - echo 'cd /opt/gopath/src/github.com/hashicorp/nomad' >> /home/vagrant/.profile +if [ -d /home/vagrant/ ] ; then + if ! grep "cd /opt/gopath/src/github.com/hashicorp/nomad" /home/vagrant/.profile ; then + echo 'cd /opt/gopath/src/github.com/hashicorp/nomad' >> /home/vagrant/.profile + fi fi diff --git a/scripts/linux-priv-docker.sh b/scripts/linux-priv-docker.sh new file mode 100755 index 000000000..edfb7039b --- /dev/null +++ b/scripts/linux-priv-docker.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Source: https://docs.docker.com/engine/install/ubuntu/ + +# Minimal effort to support amd64 and arm64 installs. +ARCH="" +case $(arch) in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; +esac + +USER="" +case $(whoami) in + root) USER="vagrant" ;; + *) USER=$(whoami) ;; +esac + +# Add the Docker repository +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository -y \ + "deb [arch=${ARCH}] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" + +# Update with i386, Go and Docker +sudo apt-get update + +sudo apt-get install -y docker-ce docker-ce-cli containerd.io + +# Restart Docker in case it got upgraded +sudo systemctl restart docker.service + +# Ensure Docker can be used by the correct user +sudo usermod -aG docker ${USER} diff --git a/scripts/vagrant-linux-priv-vault.sh b/scripts/linux-priv-vault.sh similarity index 69% rename from scripts/vagrant-linux-priv-vault.sh rename to scripts/linux-priv-vault.sh index 9f60e88fd..41274d067 100755 --- a/scripts/vagrant-linux-priv-vault.sh +++ b/scripts/linux-priv-vault.sh @@ -2,8 +2,15 @@ set -o errexit -VERSION=1.8.4 -DOWNLOAD=https://releases.hashicorp.com/vault/${VERSION}/vault_${VERSION}_linux_amd64.zip +# Minimal effort to support amd64 and arm64 installs. +ARCH="" +case $(arch) in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; +esac + +VERSION=1.13.0 +DOWNLOAD=https://releases.hashicorp.com/vault/${VERSION}/vault_${VERSION}_linux_${ARCH}.zip function install_vault() { if [[ -e /usr/bin/vault ]] ; then diff --git a/scripts/vagrant-linux-priv-docker.sh b/scripts/vagrant-linux-priv-docker.sh deleted file mode 100755 index aed7097d5..000000000 --- a/scripts/vagrant-linux-priv-docker.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -# Source: https://docs.docker.com/engine/install/ubuntu/ - -# Add the Docker repository -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - -add-apt-repository \ - "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) \ - stable" - -# Update with i386, Go and Docker -apt-get update - -apt-get install -y docker-ce docker-ce-cli containerd.io - -# Restart Docker in case it got upgraded -systemctl restart docker.service - -# Ensure Docker can be used by vagrant user -usermod -aG docker vagrant