forgejo-runner/.forgejo/workflows/example-docker-compose.yml

75 lines
2.9 KiB
YAML
Raw Permalink Normal View History

2023-08-24 11:28:17 +01:00
# SPDX-License-Identifier: MIT
on:
push:
branches:
- 'main'
2023-11-07 19:19:08 +00:00
pull_request:
2023-08-24 11:28:17 +01:00
jobs:
example-docker-compose:
runs-on: self-hosted
steps:
2023-12-04 20:28:37 +00:00
- uses: actions/checkout@v4
2023-08-24 11:28:17 +01:00
- name: Install docker
run: |
apt-get update -qq
2024-09-28 17:01:01 +01:00
export DOCKER_TLS_VERIFY=""
export DOCKER_HOST="unix:///var/run/docker.sock"
2023-08-24 11:28:17 +01:00
export DEBIAN_FRONTEND=noninteractive
apt-get install -qq -y ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
2024-09-28 07:14:32 +01:00
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
2024-09-28 07:15:40 +01:00
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
2023-08-24 11:28:17 +01:00
apt-get update -qq
apt-get install -qq -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin=2.20.2-1~debian.11~bullseye
apt-get install -qq -y docker-compose-plugin=2.20.2-1~debian.11~bullseye
2024-09-28 17:07:07 +01:00
- name: Start Docker Daemon in the Background
2024-09-28 17:04:12 +01:00
run: |
2024-09-28 17:07:07 +01:00
nohup dockerd > /dev/null 2>&1 &
sleep 10 # Wait for Docker to initialize
docker info # Verify Docker is running
2024-09-28 17:04:12 +01:00
2023-08-24 11:28:17 +01:00
- name: run the example
run: |
set -x
cd examples/docker-compose
secret=$(openssl rand -hex 20)
sed -i -e "s/{SHARED_SECRET}/$secret/" compose-forgejo-and-runner.yml
cli="docker compose --progress quiet -f compose-forgejo-and-runner.yml"
2024-09-28 06:43:01 +01:00
chown -R 1000:1000 /srv
2023-08-24 11:28:17 +01:00
#
# Launch Forgejo & the runner
2023-08-24 11:28:17 +01:00
#
$cli up -d
2024-09-26 15:28:00 +01:00
for delay in $(seq 60) ; do test -f /srv/runner-data/.runner && break ; sleep 30 ; done
test -f /srv/runner-data/.runner
#
# Run the demo workflow
#
cli="$cli -f compose-demo-workflow.yml"
$cli up -d demo-workflow
2023-08-24 11:28:17 +01:00
#
# Wait for the demo workflow to complete
#
success='DEMO WORKFLOW SUCCESS'
failure='DEMO WORKFLOW FAILURE'
2023-08-24 11:28:17 +01:00
for delay in $(seq 60) ; do
2023-11-07 19:19:08 +00:00
$cli logs demo-workflow > /tmp/out
2023-08-24 11:28:17 +01:00
grep --quiet "$success" /tmp/out && break
grep --quiet "$failure" /tmp/out && break
2023-08-24 11:28:17 +01:00
$cli ps --all
2024-09-26 15:28:00 +01:00
$cli logs --tail=20 runner-daemon demo-workflow
sleep 30
2023-08-24 11:28:17 +01:00
done
2023-11-07 19:19:08 +00:00
grep --quiet "$success" /tmp/out
2024-09-26 15:28:00 +01:00
$cli logs runner-daemon > /tmp/runner.log
2024-08-13 07:37:52 +01:00
grep --quiet 'Start image=code.forgejo.org/oci/node:20-bookworm' /tmp/runner.log
2023-11-07 19:19:08 +00:00
- name: full docker compose logs
2023-11-07 19:19:08 +00:00
if: always()
run: |
cd examples/docker-compose
2024-09-27 18:38:59 +01:00
docker compose -f compose-forgejo-and-runner.yml -f compose-demo-workflow.yml logs