File: util

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (77 lines) | stat: -rwxr-xr-x 2,072 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash

: "${BUILDX_CMD=docker buildx}"
: "${BUILDX_BUILDER=}"

: "${GITHUB_ACTIONS=}"
: "${GITHUB_REPOSITORY=}"
: "${GITHUB_RUN_ID=}"
: "${GITHUB_TOKEN=}"

: "${CONTEXT=}"
: "${CACHE_FROM=}"
: "${CACHE_TO=}"

dockerCmd() {
  (
    set -x
    docker "$@"
  )
}

buildxCmd() {
  (
    set -x
    BUILDX_NO_DEFAULT_LOAD=true BUILDX_BUILDER="${BUILDX_BUILDER}" ${BUILDX_CMD} "$@"
  )
}

buildAttestFlags() {
  if ${BUILDX_CMD} build --help 2>&1 | grep -- '--attest' >/dev/null; then
    prvattrs="mode=max"
    if [ "$GITHUB_ACTIONS" = "true" ]; then
      prvattrs="$prvattrs,builder-id=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
    fi
    echo "--attest=type=sbom --attest=type=provenance,$prvattrs"
  fi
}

currentref=""
currentcontext="."
cacheFromFlags=""
cacheToFlags=""
if [ "$GITHUB_ACTIONS" = "true" ] && [ "$GITHUB_REPOSITORY" = "moby/buildkit" ]; then
  currentref="https://github.com/$GITHUB_REPOSITORY.git#$GITHUB_REF"
  if [ -n "$CACHE_FROM" ]; then
    for cfrom in $CACHE_FROM; do
      if [[ $cfrom == *"type=gha"* ]]; then
        if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cfrom != *"repository="* ]]; then
          cfrom="${cfrom},repository=${GITHUB_REPOSITORY}"
        fi
        if [[ -n "$GITHUB_TOKEN" ]] && [[ $cfrom != *"ghtoken="* ]]; then
          cfrom="${cfrom},ghtoken=${GITHUB_TOKEN}"
        fi
      fi
      cacheFromFlags="${cacheFromFlags}--cache-from=$cfrom "
    done
  fi
  if [ -n "$CACHE_TO" ]; then
    for cto in $CACHE_TO; do
      if [[ $cto == *"type=gha"* ]]; then
        if [[ -n "$GITHUB_REPOSITORY" ]] && [[ $cto != *"repository="* ]]; then
          cto="${cto},repository=${GITHUB_REPOSITORY}"
        fi
        if [[ -n "$GITHUB_TOKEN" ]] && [[ $cto != *"ghtoken="* ]]; then
          cto="${cto},ghtoken=${GITHUB_TOKEN}"
        fi
      fi
      cacheToFlags="${cacheToFlags}--cache-to=$cto "
    done
  fi
fi
if [ -n "$currentref" ]; then
  currentcontext="--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 $currentref"
fi
if [ -n "$CONTEXT" ]; then
  currentcontext=$CONTEXT
fi