File: release

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 (132 lines) | stat: -rwxr-xr-x 3,598 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash

. $(dirname $0)/../../../../../hack/util
set -eu

: "${RELEASE=false}"
: "${PLATFORMS=}"

usage() {
  echo "$0 (master|tag) (tag|channel) <repo> [push]"
  exit 1
}

if [ $# != 4 ]; then
  usage
fi

parseTag() {
  local prefix=$(echo $1 | cut -d/ -f 1)
  if [[ "$prefix" != "dockerfile" ]]; then
    echo "invalid tag $1"
    exit 1
  fi
  local suffix=$(echo $1 | awk -F- '{print $NF}')
  local tagf=./frontend/dockerfile/release/$suffix/tags
  if [ "$suffix" == "$1" ] || [ ! -f $tagf ]; then
    suffix="mainline"
  fi

  local mainTag=$(echo $1 | cut -d/ -f 2)

  publishedNames=$REPO:$mainTag

  local versioned=""
  # \d.\d.\d becomes latest
  if [[ "$mainTag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
    publishedNames=${publishedNames},$REPO:latest
    versioned=1
  fi

  # \d.\d.\d-channel becomes <channel>
  if [[ "$mainTag" =~ ^[0-9]+\.[0-9]+\.[0-9]+-$suffix$ ]] && [ -f $tagf ]; then
    publishedNames=${publishedNames},$REPO:$suffix
    versioned=1
  fi

  # \d.\d.\d* -> \d.\d* -> \d* (except "0")
  if [ "$versioned" == "1" ]; then
    publishedNames=${publishedNames},$REPO:$(echo $mainTag | sed -E 's#^([0-9]+\.[0-9]+)\.[0-9]+#\1#')
    if [ "$(echo $mainTag | sed -E 's#^([0-9]+)\.[0-9]+\.[0-9]+.*$#\1#')" != "0" ]; then
      publishedNames=${publishedNames},$REPO:$(echo $mainTag | sed -E 's#^([0-9]+)\.[0-9]+\.[0-9]+#\1#')
    fi
  fi

  TAG=$suffix
}

TYP=$1
TAG=$2
REPO=$3
PUSH=$4

platformFlag=""
if [ -n "$PLATFORMS" ]; then
  platformFlag="--platform=$PLATFORMS"
fi

pushFlag="push=false"
if [ "$PUSH" = "push" ]; then
  pushFlag="push=true"
fi

nocacheFilterFlag=""
if [[ "$RELEASE" = "true" ]] && [[ "$GITHUB_ACTIONS" = "true" ]]; then
  nocacheFilterFlag="--no-cache-filter=base"
fi

outputFlag="type=image,$pushFlag"
if [ "$GITHUB_ACTIONS" = "true" ]; then
  outputFlag="${outputFlag},\"annotation.org.opencontainers.image.title=Dockerfile Frontend\""
  if [ -n "$GITHUB_SHA" ]; then
    outputFlag="${outputFlag},annotation.org.opencontainers.image.revision=$GITHUB_SHA"
  fi
  if [ -n "$GITHUB_REPOSITORY" ] && [ -n "$GITHUB_SERVER_URL" ]; then
    outputFlag="${outputFlag},annotation.org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
    outputFlag="${outputFlag},annotation.org.opencontainers.image.url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
  fi
fi

case $TYP in
"master")
  tagf=./frontend/dockerfile/release/$TAG/tags
  if [ ! -f $tagf ]; then
    echo "invalid release $TAG"
    exit 1
  fi

  buildTags=$(cat $tagf)
  pushTag="master"
  if [ "$TAG" != "mainline" ]; then
    pushTag=${pushTag}-$TAG
  fi

  buildxCmd build $platformFlag $cacheFromFlags $cacheToFlags $nocacheFilterFlag $(buildAttestFlags) \
    --build-arg "CHANNEL=$TAG" \
    --build-arg "BUILDTAGS=$buildTags" \
    --output "${outputFlag},name=$REPO:$pushTag" \
    --file "./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile" \
    $currentcontext
  ;;
"tag")
  publishedNames=""
  parseTag $TAG
  tagf=./frontend/dockerfile/release/$TAG/tags
  if [ ! -f $tagf ]; then
    echo "no build tags found for $TAG"
    exit 1
  fi
  buildTags=$(cat $tagf)
  outputFlag="${outputFlag},\"name=$publishedNames\""
  if [ "$GITHUB_ACTIONS" = "true" ]; then
    outputFlag="${outputFlag},annotation.org.opencontainers.image.version=$TAG"
  fi

  buildxCmd build $platformFlag $cacheFromFlags $cacheToFlags $nocacheFilterFlag $(buildAttestFlags) \
    --build-arg "CHANNEL=$TAG" \
    --build-arg "BUILDTAGS=$buildTags" \
    --output "$outputFlag" \
    --file "./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile" \
    $currentcontext
  ;;
esac