#!/bin/bash
set -Eeo pipefail
set -x

# stop service
systemctl stop containerd

# set proxy env variables
mkdir -p /run/systemd/system/containerd.service.d/
cat > /run/systemd/system/containerd.service.d/proxy.conf<<EOF
[Service]
Environment=http_proxy=${http_proxy} HTTP_PROXY=${http_proxy} https_proxy=${https_proxy} HTTPS_PROXY=${https_proxy}
EOF

systemctl daemon-reload

# start up containerd
systemctl start containerd

# pull the "busybox" image from Docker Hub
ctr images pull docker.io/library/busybox:latest

# run it and capture the output
output="$(ctr run --rm docker.io/library/busybox:latest "test-$$-$RANDOM" echo success)"

# ensure the output was exactly what we expected
[ "$output" = 'success' ]
