From 9e41977ec2434c2b29f8488d47d457af429522e6 Mon Sep 17 00:00:00 2001 From: Pierre beucher Date: Tue, 30 Jul 2024 22:44:32 +0200 Subject: [PATCH] ci: add installation test for OS and arch --- .github/workflows/test-install.yml | 60 ++++++++++++++++++++++++++++++ cloudypad.sh | 18 +++++++-- install.sh | 4 +- test/shell/Dockerfile.alpine | 11 ++++++ test/shell/Dockerfile.debian | 19 ++++++++++ test/shell/Dockerfile.ubuntu | 17 +++++++++ test/shell/test-cloudypad.sh | 36 ++++++++++++++++++ test/shell/test-install.sh | 47 +++++++++++++++++++++++ 8 files changed, 207 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test-install.yml create mode 100644 test/shell/Dockerfile.alpine create mode 100644 test/shell/Dockerfile.debian create mode 100644 test/shell/Dockerfile.ubuntu create mode 100755 test/shell/test-cloudypad.sh create mode 100755 test/shell/test-install.sh diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml new file mode 100644 index 00000000..892d7d43 --- /dev/null +++ b/.github/workflows/test-install.yml @@ -0,0 +1,60 @@ +name: Test installation script + +on: + push: + branches: + - "*" + pull_request: + branches: + - master + +jobs: + test-install: + name: Test install.sh on various OS + runs-on: "${{ matrix.os }}" + strategy: + matrix: + os: + - ubuntu-24.04 + - ubuntu-22.04 + - ubuntu-20.04 + # - macos-14 # Docker install suported yet + # - macos-13 + - macos-12 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: (MacOS) Setup Docker + if: startsWith(matrix.os, 'macos') + # uses: docker-practice/actions-setup-docker@master + # timeout-minutes: 12 + uses: douglascamata/setup-docker-macos-action@main + # uses: crazy-max/ghaction-setup-docker@v3 + + # Test the install script and cloudypad.sh for current commit + - name: Run install script + run: | + curl -fsSL https://raw.githubusercontent.com/PierreBeucher/cloudypad/${{ github.sha }}/install.sh | CLOUDYPAD_VERSION=${{ github.sha }} sh + + - name: Check version + run: | + export PATH=$PATH:$HOME/.cloudypad/bin + export CLOUDYPAD_CONTAINER_NO_TTY=true + export CLOUDYPAD_CLI_LAUNCHER_DEBUG=true + cloudypad --version + + test-install-container: + name: Test install.sh on various OS in containers + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Test install.sh script + run: test/shell/test-install.sh + + - name: Test cloudypad.sh script + run: test/shell/test-cloudypad.sh \ No newline at end of file diff --git a/cloudypad.sh b/cloudypad.sh index 4d70dc05..473ccc13 100755 --- a/cloudypad.sh +++ b/cloudypad.sh @@ -7,6 +7,10 @@ # and run instructions. # Only a few commands need to run directly for user (eg. moonlight setup) +if [ -n "$CLOUDYPAD_CLI_LAUNCHER_DEBUG" ]; then + set -x +fi + CLOUDYPAD_VERSION=0.1.1 CLOUDYPAD_IMAGE="${CLOUDYPAD_IMAGE:-"crafteo/cloudypad:$CLOUDYPAD_VERSION"}" CLOUDYPAD_TARGET_IMAGE="crafteo/cloudypad-local-runner:local" @@ -47,12 +51,12 @@ RUN if id -u $HOST_UID >/dev/null 2>&1; then \ USER $HOST_UID EOF -container_build_output=$(docker build --progress plain -t $CLOUDYPAD_TARGET_IMAGE - < /tmp/Dockerfile-cloudypad-run 2>&1) +container_build_output=$(docker buildx build -t $CLOUDYPAD_TARGET_IMAGE - < /tmp/Dockerfile-cloudypad-run 2>&1) container_build_result=$? if [ $container_build_result -ne 0 ]; then echo "Error: could not build CloudyPad container image, build exited with code: $container_build_result" >&2 - echo "Build command was: docker build --progress plain -t $CLOUDYPAD_TARGET_IMAGE - < /tmp/Dockerfile-cloudypad-run 2>&1" >&2 + echo "Build command was: docker buildx build -t $CLOUDYPAD_TARGET_IMAGE - < /tmp/Dockerfile-cloudypad-run 2>&1" >&2 echo "Build output: " echo "$container_build_output" echo @@ -80,7 +84,15 @@ run_cloudypad_docker() { ) # Build run command with proper directories - local cmd="docker run --rm -it" + local cmd="docker run --rm" + + # Set interactive+tty by default + # no tty if CLOUDYPAD_CONTAINER_NO_TTY is set (for CI) + if [ -n "$CLOUDYPAD_CONTAINER_NO_TTY" ]; then + cmd="$cmd -t" + else + cmd="$cmd -it" + fi # Only mount a directory if it exists on host for mount in "${mounts[@]}"; do diff --git a/install.sh b/install.sh index 0fd9032b..6cf41d3c 100755 --- a/install.sh +++ b/install.sh @@ -28,14 +28,14 @@ if [ -n "$(which cloudypad)" ]; then fi fi -echo "Downloading Cloudy Pad CLI..." - # Create secure directory for Cloudy Pad home as it may contain sensitive data mkdir -p "$CLOUDYPAD_HOME" chmod 0700 $CLOUDYPAD_HOME mkdir -p "$INSTALL_DIR" +echo "Downloading $CLOUDYPAD_SCRIPT_URL..." + if command -v curl >/dev/null 2>&1; then curl --fail -sSL -o "$SCRIPT_PATH" "$CLOUDYPAD_SCRIPT_URL" elif command -v wget >/dev/null 2>&1; then diff --git a/test/shell/Dockerfile.alpine b/test/shell/Dockerfile.alpine new file mode 100644 index 00000000..f724603d --- /dev/null +++ b/test/shell/Dockerfile.alpine @@ -0,0 +1,11 @@ +FROM alpine:3 + +# Install Docker client on Alpine +RUN apk update && \ + apk add --no-cache \ + sudo \ + curl \ + openrc \ + bash \ + docker && \ + rm -rf /var/cache/apk/* \ No newline at end of file diff --git a/test/shell/Dockerfile.debian b/test/shell/Dockerfile.debian new file mode 100644 index 00000000..69c4b567 --- /dev/null +++ b/test/shell/Dockerfile.debian @@ -0,0 +1,19 @@ +FROM debian:bookworm + +# Install Docker as per https://docs.docker.com/desktop/install/debian/ +RUN apt-get update && \ + apt-get install -y \ + sudo \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common && \ + sudo install -m 0755 -d /etc/apt/keyrings && \ + sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \ + sudo chmod a+r /etc/apt/keyrings/docker.asc && \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && \ + sudo apt-get update && \ + sudo apt-get install -y docker-ce-cli && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/test/shell/Dockerfile.ubuntu b/test/shell/Dockerfile.ubuntu new file mode 100644 index 00000000..6e824e98 --- /dev/null +++ b/test/shell/Dockerfile.ubuntu @@ -0,0 +1,17 @@ +FROM ubuntu:22.04 + +# Install Docker as per https://docs.docker.com/engine/install/ubuntu/ +RUN apt-get update && \ + apt-get install -y \ + sudo \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common && \ + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && \ + apt-get update && \ + apt-get install -y docker-ce-cli && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/test/shell/test-cloudypad.sh b/test/shell/test-cloudypad.sh new file mode 100755 index 00000000..d609daa1 --- /dev/null +++ b/test/shell/test-cloudypad.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +echo "====================" +echo "Testing Ubuntu" + +docker build -f test/shell/Dockerfile.ubuntu -t cloudypad-test-cli-ubuntu:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-cli-ubuntu:local \ + bash -c './cloudypad.sh --version' + +echo "====================" +echo "Testing Debian" + +docker build -f test/shell/Dockerfile.debian -t cloudypad-test-cli-debian:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-cli-debian:local \ + bash -c './cloudypad.sh --version' + +echo "====================" +echo "Testing Alpine" + +docker build -f test/shell/Dockerfile.alpine -t cloudypad-test-cli-alpine:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-cli-alpine:local \ + bash -c './cloudypad.sh --version' \ No newline at end of file diff --git a/test/shell/test-install.sh b/test/shell/test-install.sh new file mode 100755 index 00000000..619a9709 --- /dev/null +++ b/test/shell/test-install.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -e + +echo "Testing Ubuntu with bash" + +docker build -f test/shell/Dockerfile.ubuntu -t cloudypad-test-install-ubuntu:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-install-ubuntu:local \ + bash -e -i -c '/cloudypad/install.sh && source /root/.bashrc && echo $PATH && which cloudypad || (echo "Cloudypad not found on PATH after install" && false)' + +echo "====================" +echo "Testing Ubuntu with sh" + +docker build -f test/shell/Dockerfile.ubuntu -t cloudypad-test-install-ubuntu:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-install-ubuntu:local \ + sh -c '/cloudypad/install.sh && PATH=$PATH:/root/.cloudypad/bin && echo $PATH && which cloudypad || (echo "Cloudypad not found on PATH after install" && false)' + +echo "====================" +echo "Testing Debian with bash" + +docker build -f test/shell/Dockerfile.debian -t cloudypad-test-install-debian:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-install-debian:local \ + bash -i -c '/cloudypad/install.sh && source /root/.bashrc && echo $PATH && which cloudypad || (echo "Cloudypad not found on PATH after install" && false)' + +echo "====================" +echo "Testing Alpine with sh" + + +docker build -f test/shell/Dockerfile.alpine -t cloudypad-test-install-alpine:local . +docker run \ + -v $PWD:/cloudypad -w /cloudypad \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -it \ + cloudypad-test-install-alpine:local \ + sh -c '/cloudypad/install.sh && PATH=$PATH:/root/.cloudypad/bin && echo $PATH && which cloudypad || (echo "Cloudypad not found on PATH after install" && false)' \ No newline at end of file