forked from johnandersen777/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.containers_source
63 lines (56 loc) · 4.17 KB
/
.containers_source
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Usage: https://asciinema.org/a/620168
CONTAINER_CLI="podman"
if which docker 1>/dev/null 2>&1; then
CONTAINER_CLI="docker"
fi
image-container-manifest-example () {
cat <<'EOF'
{
"branch": "main",
"build_args": "[[\"TREE_ALG\", \"CCF\"], [\"key1\", \"va 'l feed asdf ue1\"]]",
"commit": "72a75511d7840d4062741185ec6879b585ee8c07",
"dockerfile": "FROM python:3.11\n\nWORKDIR /usr/src/scitt-api-emulator\n\nRUN set -x \\\n && export KEYRING=/usr/share/keyrings/nodesource.gpg \\\n && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee \"$KEYRING\" >/dev/null \\\n && gpg --no-default-keyring --keyring \"$KEYRING\" --list-keys \\\n && chmod a+r /usr/share/keyrings/nodesource.gpg \\\n && . /usr/lib/os-release \\\n && export VERSION=node_20.x \\\n && export DISTRO=\"${VERSION_CODENAME}\" \\\n && echo \"deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main\" | tee /etc/apt/sources.list.d/nodesource.list \\\n && echo \"deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main\" | tee -a /etc/apt/sources.list.d/nodesource.list \\\n && apt-get update -y \\\n && apt-get install -y nodejs jq \\\n && rm -rf /var/apt/lists/* \\\n && mkdir -vp /opt/nodemon \\\n && cd /opt/nodemon \\\n && npm install nodemon \\\n && echo 'export PATH=$PATH:/opt/nodemon/node_modules/.bin' >> ~/.bashrc\n\nENV PATH=\"/opt/nodemon/node_modules/.bin:$PATH\"\n\nCOPY setup.py ./\n\nRUN pip install --no-cache-dir -e .[oidc,federation-activitypub-bovine]\n\nCOPY . .\n\nRUN pip install --no-cache-dir -e .[oidc,federation-activitypub-bovine]\n\nSHELL [\"bash\", \"-xeuo\", \"pipefail\", \"-c\"]\n\nARG FQDN=scitt\nENV FQDN=${FQDN}\n\nRUN mkdir federation_workspace \\\n && grep -B 1 -A 9 '\"handle_name\": \"alice\"' docs/federation_activitypub.md \\\n | jq '.following= {} | .fqdn = env.FQDN | .workspace = env.PWD + \"/federation_workspace\" | .bovine_db_url = \"sqlite://\" + env.PWD + \"/federation_workspace/bovine.sqlite3\"' \\\n | tee federation_workspace/config.json\n\nARG TREE_ALG\nENV tree_alg=${TREE_ALG}\n\nCMD scitt-emulator server \\\n --port \"${PORT:-80}\" \\\n --workspace workspace/ \\\n --tree-alg \"${tree_alg}\" \\\n --middleware scitt_emulator.federation_activitypub_bovine:SCITTFederationActivityPubBovine \\\n --middleware-config-path federation_workspace/config.json",
"image_name": "scitt-api-emulator",
"owner": "scitt-community",
"repository": "scitt-api-emulator"
}
EOF
}
image-container-manifest-dockerfile () {
jq -r '.dockerfile'
}
image-container-manifest-dockerfile-update () {
manifest_path="${1}"
export manifest="$(cat ${manifest_path})" && dockerfile="$(cat /dev/stdin)" jq -r '.dockerfile = env.dockerfile' <(echo "${manifest}") | tee ${manifest_path}
}
image-container-manifest-build () {
export manifest="$(cat /dev/stdin)"
owner="$(jq -r -n 'env.manifest | fromjson | .owner')"
repository="$(jq -r -n 'env.manifest | fromjson | .repository')"
branch="$(jq -r -n 'env.manifest | fromjson | .branch')"
commit="$(jq -r -n 'env.manifest | fromjson | .commit')"
dockerfile="$(jq -r -n 'env.manifest | fromjson | .dockerfile')"
image_name="$(jq -r -n 'env.manifest | fromjson | .image_name')"
declare -a build_args
while IFS=$'\n' read -r line; do
build_args[${#build_args[@]}]="--build-arg"
build_args[${#build_args[@]}]="${line}"
done < <(jq -n -r '[env.manifest | fromjson | .build_args | fromjson | .[] | (.[0] + "=" + .[1])] | join("\n")')
unset manifest
if [[ "x${CONTAINER_CLI}" == "xpodman" ]]; then
build_args[${#build_args[@]}]="--format"
build_args[${#build_args[@]}]="docker"
fi
(tempdir="$(mktemp -d)" \
&& trap "rm -rf ${tempdir}" EXIT \
&& export TARGET_DIR="${tempdir}" \
&& export TARGET_REPO_URL="https://github.com/${owner}/${repository}" \
&& export TARGET_COMMIT="${commit}" \
&& mkdir -p "${TARGET_DIR}" \
&& cd "${TARGET_DIR}" \
&& git init \
&& git remote add origin "${TARGET_REPO_URL}" \
&& git fetch origin "${TARGET_COMMIT}" --depth 1 \
&& git reset --hard "${TARGET_COMMIT}" \
&& echo "${dockerfile}" | "${CONTAINER_CLI}" build --progress plain "${build_args[@]}" -t "${image_name}" -f - "${tempdir}")
}