File: push.sh

package info (click to toggle)
bpfcc 0.35.0%2Bds-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,696 kB
  • sloc: ansic: 900,938; python: 41,379; cpp: 25,608; sh: 776; makefile: 281
file content (64 lines) | stat: -rwxr-xr-x 2,867 bytes parent folder | download | duplicates (5)
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
#!/bin/bash
set -e

# Push docker tags to a configured docker repo, defaulting to quay.io
# You must run login.sh before running this script.

DEFAULT_DOCKER_REPO="quay.io"
DEFAULT_RELEASE_TARGET="bionic-release" # will allow unprefixed tags

# Currently only support pushing to quay.io
DOCKER_REPO=${DEFAULT_DOCKER_REPO}

git_repo=$1        # github.repository format: ORGNAME/REPONAME
git_ref=$2         # github.ref        format: refs/REMOTE/REF
                   #                       eg, refs/heads/BRANCH
                   #                           refs/tags/v0.9.6-pre
git_sha=$3         # github.sha                GIT_SHA
type_name=$4       # build name, s/+/_/g   eg, bionic-release
os_tag=${5:-18.04} # numeric docker tag    eg, 18.04

# refname will be either a branch like "master" or "some-branch",
# or a tag, like "v1.17.0-pre".
# When a tag is pushed, a build is done for both the branch and the tag, as
# separate builds.
# This is a feature specific to github actions based on the `github.ref` object
refname=$(basename ${git_ref})

# The build type needs to be sanitized into a valid tag, replacing + with _
type_tag="$(echo ${type_name} | sed 's/+/_/g')"


echo "Triggering image build"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
${SCRIPT_DIR}/build.sh ${DOCKER_REPO}/${git_repo} ${git_sha}-${type_tag} ${os_tag}

echo "Upload image for git sha ${git_sha} to ${DOCKER_REPO}/${git_repo}"
docker push ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag}

echo "Push tags to branch or git tag HEAD refs"
docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${refname}-${type_tag}
docker push ${DOCKER_REPO}/${git_repo}:${refname}-${type_tag}

# Only push to un-suffixed tags for the default release target build type
if [[ "${type_name}" == "${DEFAULT_RELEASE_TARGET}"* ]];then

  # Update branch / git tag ref
  echo "Pushing tags for ${DOCKER_REPO}/${git_repo}:${refname}"
  docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${refname}
  docker push ${DOCKER_REPO}/${git_repo}:${refname}

  if [[ "${refname}" == "master" ]];then
    if [[ "${edge}" == "ON" ]];then
      echo "This is an edge build on master, pushing ${DOCKER_REPO}/${git_repo}:edge"
      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:edge
      docker push ${DOCKER_REPO}/${git_repo}:edge
    else
      echo "This is a build on master, pushing ${DOCKER_REPO}/${git_repo}:latest :SHA as well"
      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:latest
      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${git_sha}
      docker push ${DOCKER_REPO}/${git_repo}:latest
      docker push ${DOCKER_REPO}/${git_repo}:${git_sha}
    fi
  fi
fi