xref: /aosp_15_r20/external/bcc/scripts/docker/push.sh (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1#!/bin/bash
2set -e
3
4# Push docker tags to a configured docker repo, defaulting to quay.io
5# You must run login.sh before running this script.
6
7DEFAULT_DOCKER_REPO="quay.io"
8DEFAULT_RELEASE_TARGET="bionic-release" # will allow unprefixed tags
9
10# Currently only support pushing to quay.io
11DOCKER_REPO=${DEFAULT_DOCKER_REPO}
12
13git_repo=$1        # github.repository format: ORGNAME/REPONAME
14git_ref=$2         # github.ref        format: refs/REMOTE/REF
15                   #                       eg, refs/heads/BRANCH
16                   #                           refs/tags/v0.9.6-pre
17git_sha=$3         # github.sha                GIT_SHA
18type_name=$4       # build name, s/+/_/g   eg, bionic-release
19os_tag=${5:-18.04} # numeric docker tag    eg, 18.04
20
21# refname will be either a branch like "master" or "some-branch",
22# or a tag, like "v1.17.0-pre".
23# When a tag is pushed, a build is done for both the branch and the tag, as
24# separate builds.
25# This is a feature specific to github actions based on the `github.ref` object
26refname=$(basename ${git_ref})
27
28# The build type needs to be sanitized into a valid tag, replacing + with _
29type_tag="$(echo ${type_name} | sed 's/+/_/g')"
30
31
32echo "Triggering image build"
33SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
34${SCRIPT_DIR}/build.sh ${DOCKER_REPO}/${git_repo} ${git_sha}-${type_tag} ${os_tag}
35
36echo "Upload image for git sha ${git_sha} to ${DOCKER_REPO}/${git_repo}"
37docker push ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag}
38
39echo "Push tags to branch or git tag HEAD refs"
40docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${refname}-${type_tag}
41docker push ${DOCKER_REPO}/${git_repo}:${refname}-${type_tag}
42
43# Only push to un-suffixed tags for the default release target build type
44if [[ "${type_name}" == "${DEFAULT_RELEASE_TARGET}"* ]];then
45
46  # Update branch / git tag ref
47  echo "Pushing tags for ${DOCKER_REPO}/${git_repo}:${refname}"
48  docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${refname}
49  docker push ${DOCKER_REPO}/${git_repo}:${refname}
50
51  if [[ "${refname}" == "master" ]];then
52    if [[ "${edge}" == "ON" ]];then
53      echo "This is an edge build on master, pushing ${DOCKER_REPO}/${git_repo}:edge"
54      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:edge
55      docker push ${DOCKER_REPO}/${git_repo}:edge
56    else
57      echo "This is a build on master, pushing ${DOCKER_REPO}/${git_repo}:latest :SHA as well"
58      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:latest
59      docker tag ${DOCKER_REPO}/${git_repo}:${git_sha}-${type_tag} ${DOCKER_REPO}/${git_repo}:${git_sha}
60      docker push ${DOCKER_REPO}/${git_repo}:latest
61      docker push ${DOCKER_REPO}/${git_repo}:${git_sha}
62    fi
63  fi
64fi
65