2023-01-13 00:05:48 +05:30
|
|
|
#!/bin/bash
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
function is_latest_stable_tag() {
|
|
|
|
[ "$(latest_stable_tag)" == "${CI_COMMIT_TAG}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_latest_tag() {
|
|
|
|
[ "$(latest_tag)" == "${CI_COMMIT_TAG}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
function latest_tag() {
|
|
|
|
git -c versionsort.prereleaseSuffix=rc tag --sort=-v:refname | head -1
|
|
|
|
}
|
|
|
|
|
|
|
|
function latest_stable_tag() {
|
|
|
|
git -c versionsort.prereleaseSuffix=rc tag --sort=-v:refname | awk '!/rc/' | head -1
|
|
|
|
}
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
if [[ "${CI_PROJECT_NAME}" == "gitlabhq" || "${CI_PROJECT_NAME}" == "gitlab-foss" || "${FOSS_ONLY}" == "1" ]]; then
|
2022-11-25 23:54:43 +05:30
|
|
|
QA_IMAGE_NAME="gitlab-ce-qa"
|
2023-03-04 22:38:38 +05:30
|
|
|
QA_BUILD_TARGET="foss"
|
2023-04-23 21:23:45 +05:30
|
|
|
# Build QA Image for JH project
|
|
|
|
elif [[ "${CI_PROJECT_PATH}" =~ ^gitlab-(jh|cn)\/.*$ || "${CI_PROJECT_NAME}" =~ ^gitlab-jh ]]; then
|
|
|
|
QA_IMAGE_NAME="gitlab-jh-qa"
|
|
|
|
QA_BUILD_TARGET="jhqa"
|
|
|
|
else
|
|
|
|
QA_IMAGE_NAME="gitlab-ee-qa"
|
|
|
|
QA_BUILD_TARGET="ee"
|
2022-11-25 23:54:43 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
# Tag with commit SHA by default
|
|
|
|
QA_IMAGE="${CI_REGISTRY}/${CI_PROJECT_PATH}/${QA_IMAGE_NAME}:${CI_COMMIT_SHA}"
|
2023-01-13 00:05:48 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
# For branches, tag with slugified branch name. For tags, use the tag directly
|
2023-01-13 00:05:48 +05:30
|
|
|
# with v prefix removed
|
|
|
|
IMAGE_TAG=${CI_COMMIT_TAG#v}
|
|
|
|
IMAGE_TAG=${IMAGE_TAG:-$CI_COMMIT_REF_SLUG}
|
|
|
|
|
|
|
|
QA_IMAGE_BRANCH="${CI_REGISTRY}/${CI_PROJECT_PATH}/${QA_IMAGE_NAME}:${IMAGE_TAG}"
|
|
|
|
QA_IMAGE_MASTER="${CI_REGISTRY}/${CI_PROJECT_PATH}/${QA_IMAGE_NAME}:master"
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
DESTINATIONS="--tag ${QA_IMAGE} --tag ${QA_IMAGE_BRANCH}"
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
# Auto-deploy tag format uses first 12 letters of commit SHA. Tag with that
|
|
|
|
# reference also for EE images.
|
|
|
|
if [ "${QA_IMAGE_NAME}" == "gitlab-ee-qa" ]; then
|
|
|
|
QA_IMAGE_FOR_AUTO_DEPLOY="${CI_REGISTRY}/${CI_PROJECT_PATH}/${QA_IMAGE_NAME}:${CI_COMMIT_SHA:0:11}"
|
2023-01-13 00:05:48 +05:30
|
|
|
DESTINATIONS="${DESTINATIONS} --tag $QA_IMAGE_FOR_AUTO_DEPLOY"
|
2022-11-25 23:54:43 +05:30
|
|
|
fi
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
# On tag pipelines in Canonical projects (gitlab and gitlab-foss), release to
|
|
|
|
# Dockerhub also
|
|
|
|
if [ -n "${CI_COMMIT_TAG}" ] && [ "${CI_PROJECT_NAMESPACE}" == "gitlab-org" ]; then
|
|
|
|
# Temporarily control release to Dockerhub, until we confirm it works in a
|
|
|
|
# release and finally drops the release job from omnibus-gitlab pipeline.
|
|
|
|
if [ "${RELEASE_QA_IMAGE_TO_DOCKERHUB}" == "true" ]; then
|
|
|
|
echo "$DOCKERHUB_PASSWORD" | docker login "docker.io" -u "$DOCKERHUB_USERNAME" --password-stdin
|
|
|
|
|
|
|
|
DOCKERHUB_TAG_IMAGE="gitlab/${QA_IMAGE_NAME}:${IMAGE_TAG}"
|
|
|
|
DESTINATIONS="${DESTINATIONS} --tag ${DOCKERHUB_TAG_IMAGE}"
|
|
|
|
|
|
|
|
# If we are on latest tag (RC or stable), tag the image as RC
|
|
|
|
if is_latest_tag; then
|
|
|
|
DESTINATIONS="${DESTINATIONS} --tag gitlab/${QA_IMAGE_NAME}:rc"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we are on latest stable tag, tag the image as latest
|
|
|
|
if is_latest_stable_tag; then
|
|
|
|
DESTINATIONS="${DESTINATIONS} --tag gitlab/${QA_IMAGE_NAME}:latest"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "RELEASE_QA_IMAGE_TO_DOCKERHUB not set to true. Not releasing to Dockerhub."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
echo "Building QA image for '${QA_BUILD_TARGET}' for destinations: ${DESTINATIONS}"
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
if [ "${QA_IMAGE_BUILD_DRY_RUN}" == "true" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
docker buildx build \
|
|
|
|
--cache-to=type=inline \
|
|
|
|
--cache-from="$QA_IMAGE_BRANCH" \
|
|
|
|
--cache-from="$QA_IMAGE_MASTER" \
|
|
|
|
--platform=${ARCH:-amd64} \
|
2022-11-25 23:54:43 +05:30
|
|
|
--build-arg=CHROME_VERSION="${CHROME_VERSION}" \
|
|
|
|
--build-arg=DOCKER_VERSION="${DOCKER_VERSION}" \
|
2023-01-13 00:05:48 +05:30
|
|
|
--build-arg=RUBY_VERSION="${RUBY_VERSION}" \
|
2023-03-04 22:38:38 +05:30
|
|
|
--build-arg=QA_BUILD_TARGET="${QA_BUILD_TARGET}" \
|
2023-01-13 00:05:48 +05:30
|
|
|
--file="${CI_PROJECT_DIR}/qa/Dockerfile" \
|
|
|
|
--push \
|
|
|
|
${DESTINATIONS} \
|
|
|
|
${CI_PROJECT_DIR}
|