Files
dokku-docker-compose/.github/workflows/test.yml
2025-07-17 20:37:58 -04:00

118 lines
3.6 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:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y bats ssh netcat-openbsd
- 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 dokku
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 dokku user
echo "Adding SSH key to dokku user..."
docker exec -i $CONTAINER_ID bash -c '
mkdir -p /home/dokku/.ssh
chmod 700 /home/dokku/.ssh
cat >> /home/dokku/.ssh/authorized_keys
chmod 600 /home/dokku/.ssh/authorized_keys
chown -R dokku:dokku /home/dokku/.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 for deployment tests
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
# Run deployment tests
bats tests/deploy.bats