Files
dokku-docker-compose/.github/workflows/test.yml
Deploy Bot 1592f73dff Update CI to use Node.js 20 LTS
- Switch from deprecated Node.js 16.x to current LTS 20.x
- Update setup script URL to use setup_20.x
2025-07-17 21:55:50 -04:00

153 lines
4.9 KiB
YAML

name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
dokku:
image: dokku/dokku:latest
ports:
- "2222:22"
- "8080:80"
- "8443:443"
env:
DOKKU_HOST: localhost
DOKKU_SKIP_APP_WEB_CONFIG: 1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
options: >-
--health-cmd "nc -z localhost 22"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code with submodules
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y bats git
# Clone bats-core if not already present
if [ ! -d "bats-core" ]; then
git clone https://github.com/bats-core/bats-core.git
sudo ./bats-core/install.sh /usr/local
fi
# Install BATS helpers
mkdir -p tests/test_helper
# Install bats-support
if [ ! -d "tests/test_helper/bats-support" ]; then
git clone --depth 1 https://github.com/bats-core/bats-support.git tests/test_helper/bats-support
fi
# Install bats-assert
if [ ! -d "tests/test_helper/bats-assert" ]; then
git clone --depth 1 https://github.com/bats-core/bats-assert.git tests/test_helper/bats-assert
fi
# Install bats-file
if [ ! -d "tests/test_helper/bats-file" ]; then
git clone --depth 1 https://github.com/bats-core/bats-file.git tests/test_helper/bats-file
fi
# Verify BATS helpers were installed
if [ ! -d "tests/test_helper/bats-support" ] || [ ! -d "tests/test_helper/bats-assert" ] || [ ! -d "tests/test_helper/bats-file" ]; then
echo "Error: Failed to install BATS helper libraries"
ls -la tests/test_helper/
exit 1
fi
- name: Set up SSH
run: |
# Create .ssh directory
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Generate SSH key without passphrase
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -C "github-actions@dokku-test"
# Add to SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Create SSH config
cat > ~/.ssh/config << 'EOL'
Host dokku-test
HostName localhost
Port 2222
User root
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
EOL
# Set permissions
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/id_ed25519*
# Add public key to Dokku container
echo "Waiting for Dokku SSH to be ready..."
until nc -z localhost 2222; do sleep 1; done
sleep 5 # Give it a moment to fully start
# Install the public key in the Dokku container
cat ~/.ssh/id_ed25519.pub | ssh-keyscan -p 2222 -t ed25519 localhost > /dev/null 2>&1 || true
# Wait for Dokku to be ready
echo "Waiting for Dokku to be ready..."
# Get the actual container ID
CONTAINER_ID=$(docker ps -qf "name=dokku")
echo "Dokku container ID: $CONTAINER_ID"
# Wait for SSH to be ready
until docker exec $CONTAINER_ID ps | grep -q sshd; do
echo "Waiting for SSH to be ready..."
sleep 2
done
# Add the key to the root user
echo "Adding SSH key to root user..."
docker exec -i $CONTAINER_ID bash -c '
mkdir -p /root/.ssh
chmod 700 /root/.ssh
cat >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
chown -R root:root /root/.ssh
' < ~/.ssh/id_ed25519.pub || true
# Test SSH connection
echo "Testing SSH connection..."
ssh -T dokku-test "echo 'SSH connection successful!'" || echo "SSH test failed, but continuing..."
- name: Install Dokku plugins
run: |
ssh -T dokku-test "\
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres && \
dokku plugin:install https://github.com/dokku/dokku-redis.git redis && \
dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql"
- name: Run unit tests
run: bats tests/parser.bats
- name: Run integration tests
run: bats tests/integration.bats
- name: Run deployment tests
run: |
# Install Node.js 20.x LTS for deployment tests
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Run deployment tests
bats tests/deploy.bats