2024-04-03 19:08:21 +03:00
|
|
|
name: 'Test Docker Compose'
|
|
|
|
on:
|
|
|
|
pull_request:
|
2024-10-21 13:02:14 +03:00
|
|
|
|
2024-04-03 19:08:21 +03:00
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
2024-11-15 11:38:30 +03:00
|
|
|
timeout-minutes: 30
|
2024-04-03 19:08:21 +03:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v2
|
2024-10-21 13:02:14 +03:00
|
|
|
- name: Check for changed files
|
|
|
|
id: changed-files
|
|
|
|
uses: tj-actions/changed-files@v11
|
|
|
|
with:
|
|
|
|
files: |
|
|
|
|
packages/twenty-docker/**
|
|
|
|
docker-compose.yml
|
|
|
|
- name: Skip if no relevant changes
|
|
|
|
if: steps.changed-files.outputs.any_changed != 'true'
|
|
|
|
run: echo "No relevant changes detected. Marking as valid."
|
2024-04-03 19:08:21 +03:00
|
|
|
|
|
|
|
- name: Run compose
|
2024-10-21 13:02:14 +03:00
|
|
|
if: steps.changed-files.outputs.any_changed == 'true'
|
2024-04-03 19:08:21 +03:00
|
|
|
run: |
|
|
|
|
echo "Patching docker-compose.yml..."
|
|
|
|
# change image to localbuild using yq
|
|
|
|
yq eval 'del(.services.server.image)' -i docker-compose.yml
|
2024-04-11 17:53:15 +03:00
|
|
|
yq eval '.services.server.build.context = "../../"' -i docker-compose.yml
|
2024-04-03 19:08:21 +03:00
|
|
|
yq eval '.services.server.build.dockerfile = "./packages/twenty-docker/twenty/Dockerfile"' -i docker-compose.yml
|
|
|
|
yq eval '.services.server.restart = "no"' -i docker-compose.yml
|
|
|
|
|
|
|
|
yq eval 'del(.services.db.image)' -i docker-compose.yml
|
2024-04-11 17:53:15 +03:00
|
|
|
yq eval '.services.db.build.context = "../../"' -i docker-compose.yml
|
2024-11-15 11:38:30 +03:00
|
|
|
yq eval '.services.db.build.dockerfile = "./packages/twenty-docker/twenty-postgres-spilo/Dockerfile"' -i docker-compose.yml
|
2024-04-03 19:08:21 +03:00
|
|
|
|
|
|
|
echo "Setting up .env file..."
|
|
|
|
cp .env.example .env
|
|
|
|
echo "Generating secrets..."
|
|
|
|
echo "# === Randomly generated secrets ===" >>.env
|
2024-10-30 14:07:11 +03:00
|
|
|
echo "APP_SECRET=$(openssl rand -base64 32)" >>.env
|
2024-11-15 11:38:30 +03:00
|
|
|
echo "PGPASSWORD_SUPERUSER=$(openssl rand -base64 32)" >>.env
|
2024-04-03 19:08:21 +03:00
|
|
|
|
2024-11-15 11:38:30 +03:00
|
|
|
echo "Docker compose up..."
|
|
|
|
docker compose up -d || {
|
|
|
|
echo "Docker compose failed to start"
|
|
|
|
docker compose logs
|
|
|
|
exit 1
|
|
|
|
}
|
2024-04-03 19:08:21 +03:00
|
|
|
docker compose logs db server -f &
|
|
|
|
pid=$!
|
|
|
|
|
2024-11-15 11:38:30 +03:00
|
|
|
echo "Waiting for database to start..."
|
|
|
|
count=0
|
|
|
|
while [ ! $(docker inspect --format='{{.State.Health.Status}}' twenty-db-1) = "healthy" ]; do
|
|
|
|
sleep 1;
|
|
|
|
count=$((count+1));
|
|
|
|
if [ $(docker inspect --format='{{.State.Status}}' twenty-db-1) = "exited" ]; then
|
|
|
|
echo "Database exited"
|
|
|
|
docker compose logs db
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $count -gt 300 ]; then
|
|
|
|
echo "Failed to start database after 5 minutes"
|
|
|
|
docker compose logs db
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Still waiting for database... (${count}/60)"
|
|
|
|
done
|
|
|
|
|
2024-04-03 19:08:21 +03:00
|
|
|
echo "Waiting for server to start..."
|
|
|
|
count=0
|
|
|
|
while [ ! $(docker inspect --format='{{.State.Health.Status}}' twenty-server-1) = "healthy" ]; do
|
|
|
|
sleep 1;
|
|
|
|
count=$((count+1));
|
|
|
|
if [ $(docker inspect --format='{{.State.Status}}' twenty-server-1) = "exited" ]; then
|
|
|
|
echo "Server exited"
|
2024-11-15 11:38:30 +03:00
|
|
|
docker compose logs server
|
2024-04-03 19:08:21 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $count -gt 300 ]; then
|
2024-11-15 11:38:30 +03:00
|
|
|
echo "Failed to start server after 5 minutes"
|
|
|
|
docker compose logs server
|
2024-04-03 19:08:21 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-11-15 11:38:30 +03:00
|
|
|
echo "Still waiting for server... (${count}/300s)"
|
2024-04-03 19:08:21 +03:00
|
|
|
done
|
|
|
|
working-directory: ./packages/twenty-docker/
|