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