-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
45 lines (35 loc) · 2.84 KB
/
entrypoint.sh
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
#!/bin/sh
set -e
set -x
TAG=$(echo "${INPUT_TAG_REF}" | sed -e 's|refs/tags||' | sed -e 's/^v//' | sed -e 's/+.*$//')
DOCKER_IMAGE_TAG_MAJOR=$(echo "$TAG" | cut -d"." -f1)
DOCKER_IMAGE_TAG_MINOR=$(echo "$TAG" | cut -d"." -f2)
DOCKER_IMAGE_TAG_PATCH=$(echo "$TAG" | cut -d"." -f3 | sed -e 's/-.*$//')
DOCKER_IMAGE_TAG_PATCH_WITH_PRE_RELEASE=$(echo "$TAG" | cut -d"." -f3 | sed -e 's/+.*$//')
echo "Tagging ${DOCKER_IMAGE_TAG_MAJOR}, ${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}, ${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH} and ${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH_WITH_PRE_RELEASE} for ${INPUT_TARGET_IMAGE_NAME} ..."
echo "${INPUT_SOURCE_REGISTRY_PASSWORD}" | docker login -u "${INPUT_SOURCE_REGISTRY_USERNAME}" --password-stdin "${INPUT_SOURCE_REGISTRY_ENDPOINT}"
echo "${INPUT_TARGET_REGISTRY_PASSWORD}" | docker login -u "${INPUT_TARGET_REGISTRY_USERNAME}" --password-stdin "${INPUT_TARGET_REGISTRY_ENDPOINT}"
docker pull "${INPUT_SOURCE_IMAGE_NAME}:${TAG}"
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}"
docker push "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}"
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}"
docker push "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}"
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH}"
docker push "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH}"
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH_WITH_PRE_RELEASE}"
docker push "${INPUT_TARGET_IMAGE_NAME}:${DOCKER_IMAGE_TAG_MAJOR}.${DOCKER_IMAGE_TAG_MINOR}.${DOCKER_IMAGE_TAG_PATCH_WITH_PRE_RELEASE}"
if [ "${INPUT_TAG_LATEST}" = "yes" ] || [ "${INPUT_TAG_LATEST}" = "true" ]; then
echo 'Creating and publishing "latest" tag ...'
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:latest"
docker push "${INPUT_TARGET_IMAGE_NAME}:latest"
fi
if [ "${INPUT_TAG_CUSTOM}" != "" ]; then
echo "Creating and publishing custom tag '${INPUT_TAG_CUSTOM}' ..."
docker tag "${INPUT_SOURCE_IMAGE_NAME}:${TAG}" "${INPUT_TARGET_IMAGE_NAME}:${INPUT_TAG_CUSTOM}"
docker push "${INPUT_TARGET_IMAGE_NAME}:${INPUT_TAG_CUSTOM}"
fi
echo "image_tag=${TAG}" >> $GITHUB_OUTPUT
echo "image_tag_major=${DOCKER_IMAGE_TAG_MAJOR}" >> $GITHUB_OUTPUT
echo "image_tag_minor={DOCKER_IMAGE_TAG_MINOR}" >> $GITHUB_OUTPUT
echo "image_tag_patch={DOCKER_IMAGE_TAG_PATCH}" >> $GITHUB_OUTPUT
echo "image_tag_patch_with_pre_release={DOCKER_IMAGE_TAG_PATCH_WITH_PRE_RELEASE}" >> $GITHUB_OUTPUT