aboutsummaryrefslogtreecommitdiff
path: root/contrib/ci/ci.sh
blob: 611977bd3d0933c851c42992e964174f37b8e46e (plain)
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
#!/bin/bash
set -exvuo pipefail

# Requires podman
# Fails if not found in PATH
OCI_RUNTIME=$(which podman)
REPO_NAME=$(basename "${PWD}")
JOB_NAME="${1}"
JOB_ARCH=$((grep CONTAINER_ARCH contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "${2:-amd64}")
JOB_CONTAINER=$((grep CONTAINER_NAME contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "localhost/${REPO_NAME}:${JOB_ARCH}")
CONTAINER_BUILD=$((grep CONTAINER_BUILD contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "True")
CONTAINERFILE="contrib/ci/jobs/${JOB_NAME}/Containerfile"

if ! [[ -f "$CONTAINERFILE" ]]; then
	CONTAINERFILE="contrib/ci/$JOB_ARCH.Containerfile"
fi;
if ! [[ -f "$CONTAINERFILE" ]]; then
	CONTAINERFILE="$(dirname "$CONTAINERFILE")/Containerfile"
fi;

echo "Image name: ${JOB_CONTAINER}
Containerfile: ${CONTAINERFILE}"

if [ "${CONTAINER_BUILD}" = "True" ] ; then
	"${OCI_RUNTIME}" build \
		--arch "${JOB_ARCH}" \
		-t "${JOB_CONTAINER}" \
		-f "$CONTAINERFILE" .
fi

"${OCI_RUNTIME}" run \
	--rm \
	-ti \
	--arch "${JOB_ARCH}" \
	--env CI_COMMIT_REF="$(git rev-parse HEAD)" \
	--volume "${PWD}":/workdir \
	--workdir /workdir \
	"${JOB_CONTAINER}" \
	contrib/ci/jobs/"${JOB_NAME}"/job.sh

top_dir=$(dirname "${BASH_SOURCE[0]}")

#"${top_dir}"/build.sh