aboutsummaryrefslogtreecommitdiff
path: root/.scripts.d/30-test.sh
blob: bf84a3679fa79f195867edfbef91774354c7a64f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# vim: ai:ts=8:sw=8:noet
set -EeufCo pipefail
export SHELLOPTS # propagate set to children by default
IFS=$'\t\n'

# check required commands are in place
command -v docker >/dev/null 2>&1 || {
	echo 'please install docker-client'
	exit 1
}

# shellcheck disable=SC2001
REGISTRY=$(echo "${GITHUB_SERVER_URL}" | sed -e 's|^[^/]*//||')
TAG="${GITHUB_RUN_ID}"
IMAGE_NAME="${REGISTRY}/${GITHUB_REPOSITORY,,}:${TAG}"

function cleanup() {
    docker stop "$(docker ps -aq --filter "ancestor=${IMAGE_NAME}")" >/dev/null 2>&1 || true
    docker rm "$(docker ps -aq --filter "ancestor=${IMAGE_NAME}")" >/dev/null 2>&1 || true
}
trap cleanup EXIT

# install goss
curl -fsSL https://goss.rocks/install | sh

export GOSS_SLEEP=${GOSS_SLEEP:-60}
export GOSS_VARS=${GOSS_VARS:-}
export GOSS_ADDITIONAL_COPY_PATH=${GOSS_ADDITIONAL_COPY_PATH:-}
export GOSS_OPTS="--no-color"
export DEBUG=false
export CONTAINER_LOG_OUTPUT=${CONTAINER_LOG_OUTPUT:-}

# The default 'mount' strategy uses 'sleep infinity' to keep
# the container alive. If there's an ENTRYPOINT or CMD, use 'cp'
# instead to prevent dgoss from overriding it.
if grep -qE '^(ENTRYPOINT|CMD)' Dockerfile; then
	export GOSS_FILES_STRATEGY=cp
fi

goss --gossfile goss.yaml render >goss-full.yaml
mv goss-full.yaml goss.yaml

echo "${GITEA_REGISTRY_TOKEN}" |
    docker login "${REGISTRY}" -u "${GITEA_REGISTRY_USER}" --password-stdin

dgoss run "${IMAGE_NAME}"