Docker-compose

Download the docker-composel.yml

The pre configered runner is a type of baremetal runner, which run commands directly in the docker container.

Sample runner.sh

if [[ $RUNNER_TYPE == 'baremetal' ]];then
  cd cmddir
  chmod a+x ./entrypoint.sh
  ./entrypoint.sh $RAW_ARGS
  exit 0
fi

Add a new runner which run on the host machine. Commands could config to be run in a Lxd container, Or a docker container, Or a docker in Lxd container.

Sample runner.sh

if [[ $1 == 'getlistenip' ]];then
        networkname={{runner.settings.networkname}}
        networkname=${networkname:-lxdbr0}
        # if you changed the network name, you should change it here.
        echo "listenip:$(lxc network get ${networkname} ipv4.address | cut -d'/' -f1)"
        exit 0
fi

if [[ $1 == 'execcmd' ]];then
  if [[ -n $(lxc list -f csv | awk -F, '$1 == "'"${INSTANCE_ID}"'" && $2 == "RUNNING" {print $1}') ]]; then
        echo "container $INSTANCE_ID is running."
  elif [[ -n $(lxc list -f csv | awk -F, '$1 == "'"${INSTANCE_ID}"'" && $2 == "STOPPED" {print $1}') ]]; then
        echo "container $INSTANCE_ID is stopped."
        lxc start $INSTANCE_ID
        sleep 1
  else
        echo "container $INSTANCE_ID doesn't exist."
        lxc launch $IMAGE_NAME $INSTANCE_ID
        sleep 1
  fi

  chmod a+x ./cmddir/entrypoint.sh
  lxc file push -r cmddir ${INSTANCE_ID}/
  lxc exec $INSTANCE_ID --cwd cmddir \
        --env SCRIPT_ENVS_CLEAR="$SCRIPT_ENVS_CLEAR" \
        --env ALL_ENV_NAMES="$ALL_ENV_NAMES" \
        --env HOST_IP="$HOST_IP" \
        --env HOST_LISTEN_PORT="$HOST_LISTEN_PORT" \
        --env HOST_LISTEN_SCHEMA="$HOST_LISTEN_SCHEMA" \
        --env USERCMD_ID="$USERCMD_ID" \
        --env RAW_ARGS="$RAW_ARGS" \
        --env SSH_USER="$SSH_USER" \
        --env SSH_HOST="$SSH_HOST" \
        --env SSH_PRIVATE_KEY_VALUE="$SSH_PRIVATE_KEY_VALUE" \
        --env X_API_KEY="$X_API_KEY" \
        ./entrypoint.sh
  if [[ $stopcontainer != 'false' ]];then
    lxc stop $INSTANCE_ID
  fi
  exit 0
fi

Install Lxd on host

Please follow the instruction of the official website: https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/

Please Choose btrfs filesytem to support docker in Lxd container.

Or use docker

Sample runner.sh

#  --add-host=host.docker.internal:host-gateway  to resolve host.docker.internal
if [[ $RUNNER_TYPE  == 'docker' ]];then
        chmod a+x ./cmddir/entrypoint.sh
        docker run -v "$(pwd)/cmddir:/cmddir" \
        --add-host=host.docker.internal:host-gateway \
        --env SCRIPT_ENVS_CLEAR="$SCRIPT_ENVS_CLEAR" \
        --env ALL_ENV_NAMES="$ALL_ENV_NAMES" \
        --env HOST_IP="$HOST_IP" \
        --env HOST_LISTEN_PORT="$HOST_LISTEN_PORT" \
        --env HOST_LISTEN_SCHEMA="$HOST_LISTEN_SCHEMA" \
        --env USERCMD_ID="$USERCMD_ID" \
        --env RAW_ARGS="$RAW_ARGS" \
        --env SSH_USER="$SSH_USER" \
        --env SSH_HOST="$SSH_HOST" \
        --env SSH_PRIVATE_KEY_VALUE="$SSH_PRIVATE_KEY_VALUE" \
        --env X_API_KEY="$X_API_KEY" \
        $IMAGE_NAME bash -c "cd /cmddir && ./entrypoint.sh"
        exit 0

fi