Skip to content

Commit

Permalink
ci: add installation test for OS and arch
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBeucher committed Jul 31, 2024
1 parent be65d24 commit 9e41977
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 5 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions cloudypad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/shell/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -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/*
19 changes: 19 additions & 0 deletions test/shell/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -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/*
17 changes: 17 additions & 0 deletions test/shell/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -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/*
36 changes: 36 additions & 0 deletions test/shell/test-cloudypad.sh
Original file line number Diff line number Diff line change
@@ -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'
47 changes: 47 additions & 0 deletions test/shell/test-install.sh
Original file line number Diff line number Diff line change
@@ -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)'

0 comments on commit 9e41977

Please sign in to comment.