Skip to content

Commit

Permalink
add script/config for tagging & pushing images (#5343)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdabelf5 authored Apr 4, 2024
1 parent 639daee commit 3e089b1
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/config/config-gcr-retag
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export TARGET_REGISTRY=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev
declare -a PLUS_TAG_POSTFIX_LIST=("" "-ubi" "-alpine" "-alpine-fips" "-mktpl" "-alpine-mktpl" "-alpine-mktpl-fips")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl" "-alpine-fips")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl")
declare -a ADDITIONAL_TAGS=()
7 changes: 7 additions & 0 deletions .github/config/config-oss-dockerhub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TARGET_REGISTRY=docker.io
export TARGET_OSS_IMAGE_PREFIX="nginx/nginx-ingress"
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_PLUS=false
export PUBLISH_WAF=false
export PUBLISH_DOS=false
export PUBLISH_WAF_DOS=false
7 changes: 7 additions & 0 deletions .github/config/config-oss-ecr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TARGET_REGISTRY=public.ecr.aws
export TARGET_OSS_IMAGE_PREFIX="nginx/nginx-ingress"
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_PLUS=false
export PUBLISH_WAF=false
export PUBLISH_DOS=false
export PUBLISH_WAF_DOS=false
6 changes: 6 additions & 0 deletions .github/config/config-oss-gcr-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export TARGET_REGISTRY=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/release
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_PLUS=false
export PUBLISH_WAF=false
export PUBLISH_DOS=false
export PUBLISH_WAF_DOS=false
7 changes: 7 additions & 0 deletions .github/config/config-oss-github
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TARGET_REGISTRY=ghcr.io
export TARGET_OSS_IMAGE_PREFIX="nginxinc/kubernetes-ingress"
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_PLUS=false
export PUBLISH_WAF=false
export PUBLISH_DOS=false
export PUBLISH_WAF_DOS=false
7 changes: 7 additions & 0 deletions .github/config/config-oss-quay
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TARGET_REGISTRY=quay.io
export TARGET_OSS_IMAGE_PREFIX="nginx/nginx-ingress"
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_PLUS=false
export PUBLISH_WAF=false
export PUBLISH_DOS=false
export PUBLISH_WAF_DOS=false
11 changes: 11 additions & 0 deletions .github/config/config-plus-azure
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export TARGET_REGISTRY=nginxmktpl.azurecr.io
export TARGET_PLUS_IMAGE_PREFIX="marketplaceimages/nginx-plus-ingress"
export TARGET_NAP_WAF_IMAGE_PREFIX="marketplaceimages/nginx-plus-ingress-nap"
export TARGET_NAP_DOS_IMAGE_PREFIX="marketplaceimages/nginx-plus-ingress-dos"
export TARGET_NAP_WAF_DOS_IMAGE_PREFIX="marketplaceimages/nginx-plus-ingress-nap-dos"
declare -a PLUS_TAG_POSTFIX_LIST=("")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("")
declare -a ADDITIONAL_TAGS=()
export PUBLISH_OSS=false
11 changes: 11 additions & 0 deletions .github/config/config-plus-ecr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export TARGET_REGISTRY=709825985650.dkr.ecr.us-east-1.amazonaws.com
export TARGET_PLUS_IMAGE_PREFIX=nginx/nginx-plus-ingress
export TARGET_NAP_WAF_IMAGE_PREFIX=nginx/nginx-plus-ingress-nap
export TARGET_NAP_DOS_IMAGE_PREFIX=nginx/nginx-plus-ingress-dos
export TARGET_NAP_WAF_DOS_IMAGE_PREFIX=nginx/nginx-plus-ingress-dos-nap
declare -a PLUS_TAG_POSTFIX_LIST=("-mktpl" "-alpine-mktpl" "-alpine-mktpl-fips")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("-mktpl" "-ubi-mktpl")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("-mktpl" "-ubi-mktpl")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("-mktpl" "-ubi-mktpl")
declare -a ADDITIONAL_TAGS=()
export PUBLISH_OSS=false
10 changes: 10 additions & 0 deletions .github/config/config-plus-gcr-public
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export PUBLISH_OSS=false
export PUBLISH_WAF_DOS=false
export TARGET_REGISTRY=gcr.io/f5-7626-networks-public
export TARGET_PLUS_IMAGE_PREFIX=nginxinc/nginx-plus-ingress
export TARGET_NAP_WAF_IMAGE_PREFIX=nginxinc/nginx-plus-ingress-nap
export TARGET_NAP_DOS_IMAGE_PREFIX=nginxinc/nginx-plus-ingress-dos
declare -a PLUS_TAG_POSTFIX_LIST=("")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("")
declare -a ADDITIONAL_TAGS=(${ADDITIONAL_TAG})
7 changes: 7 additions & 0 deletions .github/config/config-plus-gcr-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TARGET_REGISTRY=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/release
declare -a PLUS_TAG_POSTFIX_LIST=("" "-ubi" "-alpine" "-alpine-fips" "-mktpl" "-alpine-mktpl" "-alpine-mktpl-fips")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl" "-alpine-fips")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("" "-ubi" "-mktpl" "-ubi-mktpl")
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_OSS=false
8 changes: 8 additions & 0 deletions .github/config/config-plus-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export TARGET_REGISTRY=docker-mgmt.nginx.com
export TARGET_NAP_WAF_DOS_IMAGE_PREFIX="nginx-ic-nap-dos/nginx-plus-ingress"
declare -a PLUS_TAG_POSTFIX_LIST=("" "-ubi" "-alpine" "-alpine-fips")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("" "-ubi" "-alpine-fips")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("" "-ubi")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("" "-ubi")
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")
export PUBLISH_OSS=false
213 changes: 213 additions & 0 deletions .github/scripts/copy-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env bash

set -eo pipefail

## Setup inputs

SOURCE_TAG=${SOURCE_TAG:-stable}
TARGET_TAG=${TARGET_TAG:-edge}
ADDITIONAL_TAG=${ADDITIONAL_TAG:-""}

SOURCE_REGISTRY=${1:-"gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev"}
TARGET_REGISTRY=${2:-"gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/release"}

REGISTRY_USERNAME=${REGISTRY_USERNAME:-""}
REGISTRY_PASSWORD=${REGISTRY_PASSWORD:-""}

PUBLISH_OSS=${PUBLISH_OSS:-true}
PUBLISH_PLUS=${PUBLISH_PLUS:-true}
PUBLISH_WAF=${PUBLISH_WAF:-true}
PUBLISH_DOS=${PUBLISH_DOS:-true}
PUBLISH_WAF_DOS=${PUBLISH_WAF_DOS:-true}

DRY_RUN=${DRY_RUN:-false}

SOURCE_OSS_IMAGE_PREFIX=${SOURCE_OSS_IMAGE_PREFIX:-"nginx-ic/nginx-ingress"}

TARGET_OSS_IMAGE_PREFIX=${TARGET_OSS_IMAGE_PREFIX:-"nginx-ic/nginx-ingress"}

SOURCE_PLUS_IMAGE_PREFIX=${SOURCE_PLUS_IMAGE_PREFIX:-"nginx-ic/nginx-plus-ingress"}
SOURCE_NAP_WAF_IMAGE_PREFIX=${SOURCE_NAP_WAF_IMAGE_PREFIX:-"nginx-ic-nap/nginx-plus-ingress"}
SOURCE_NAP_DOS_IMAGE_PREFIX=${SOURCE_NAP_DOS_IMAGE_PREFIX:-"nginx-ic-dos/nginx-plus-ingress"}
SOURCE_NAP_WAF_DOS_IMAGE_PREFIX=${SOURCE_NAP_WAF_DOS_IMAGE_PREFIX:-"nginx-ic-dos-nap/nginx-plus-ingress"}

TARGET_PLUS_IMAGE_PREFIX=${TARGET_PLUS_IMAGE_PREFIX:-"nginx-ic/nginx-plus-ingress"}
TARGET_NAP_WAF_IMAGE_PREFIX=${TARGET_NAP_WAF_IMAGE_PREFIX:-"nginx-ic-nap/nginx-plus-ingress"}
TARGET_NAP_DOS_IMAGE_PREFIX=${TARGET_NAP_DOS_IMAGE_PREFIX:-"nginx-ic-dos/nginx-plus-ingress"}
TARGET_NAP_WAF_DOS_IMAGE_PREFIX=${TARGET_NAP_WAF_DOS_IMAGE_PREFIX:-"nginx-ic-dos-nap/nginx-plus-ingress"}

declare -a OSS_TAG_POSTFIX_LIST=("" "-ubi" "-alpine")
declare -a PLUS_TAG_POSTFIX_LIST=("" "-ubi" "-alpine" "-alpine-fips")
declare -a NAP_WAF_TAG_POSTFIX_LIST=("" "-ubi" "-alpine-fips")
declare -a NAP_DOS_TAG_POSTFIX_LIST=("" "-ubi")
declare -a NAP_WAF_DOS_TAG_POSTFIX_LIST=("" "-ubi")
declare -a ADDITIONAL_TAGS=("latest" "${ADDITIONAL_TAG}")

CONFIG_PATH=${CONFIG_PATH:-~/.nic-release/config}
if [ -f "$CONFIG_PATH" ]; then
# shellcheck source=/dev/null
. "$CONFIG_PATH"
fi

SOURCE_OPTS=${SOURCE_OPTS:-""}
if [[ $SOURCE_REGISTRY =~ mgmt ]] || [[ $SOURCE_REGISTRY =~ private ]] ; then
if [ "${CI}" != 'true' ]; then
SOURCE_OPTS="--src-username ${REGISTRY_USERNAME} --src-password ${REGISTRY_PASSWORD}"
fi
fi

TARGET_OPTS=${TARGET_OPTS:-""}
if [[ $TARGET_REGISTRY =~ mgmt ]]; then
if [ "${CI}" != 'true' ]; then
TARGET_OPTS="--dest-username ${REGISTRY_USERNAME} --dest-password ${REGISTRY_PASSWORD}"
fi
fi

# cannot push the same tag twice
IS_IMMUTABLE=false
if [[ $TARGET_REGISTRY =~ 709825985650.dkr.ecr ]]; then
IS_IMMUTABLE=true
fi

ARCH_OPTS="-a"
if [[ $TARGET_REGISTRY =~ f5-7626-networks-public ]] || [[ $TARGET_REGISTRY =~ nginxmktpl ]]; then
ARCH_OPTS="--override-os linux --override-arch amd64"
fi

## Main publish loops

if $PUBLISH_OSS; then
for postfix in "${OSS_TAG_POSTFIX_LIST[@]}"; do
image=${SOURCE_REGISTRY}/${SOURCE_OSS_IMAGE_PREFIX}:${SOURCE_TAG}${postfix}
echo "Processing image ${image}"
new_tag=${TARGET_REGISTRY}/${TARGET_OSS_IMAGE_PREFIX}:${TARGET_TAG}${postfix}
echo " Pushing image OSS ${new_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${new_tag}
fi
for tag in "${ADDITIONAL_TAGS[@]}"; do
if [ -z "${tag}" ]; then
continue
fi
additional_tag=${TARGET_REGISTRY}/${TARGET_OSS_IMAGE_PREFIX}:${tag}${postfix}
echo " Pushing image OSS ${additional_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${additional_tag}
fi
done
done
else
echo "Skipping Publish OSS flow"
fi

if $PUBLISH_PLUS; then
for postfix in "${PLUS_TAG_POSTFIX_LIST[@]}"; do
image=${SOURCE_REGISTRY}/${SOURCE_PLUS_IMAGE_PREFIX}:${SOURCE_TAG}${postfix}
echo "Processing image ${image}"
new_tag=${TARGET_REGISTRY}/${TARGET_PLUS_IMAGE_PREFIX}:${TARGET_TAG}${postfix}
if $IS_IMMUTABLE && skopeo --override-os linux --override-arch amd64 inspect docker://${new_tag} > /dev/null 2>&1; then
echo " ECR is immutable & tag ${new_tag} already exists, skipping."
else
echo " Pushing image Plus ${new_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${new_tag}
fi
for tag in "${ADDITIONAL_TAGS[@]}"; do
if [ -z "${tag}" ]; then
continue
fi
additional_tag=${TARGET_REGISTRY}/${TARGET_PLUS_IMAGE_PREFIX}:${tag}${postfix}
echo " Pushing image Plus ${additional_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${additional_tag}
fi
done
fi
done
else
echo "Skipping Publish Plus flow"
fi

if $PUBLISH_WAF; then
for postfix in "${NAP_WAF_TAG_POSTFIX_LIST[@]}"; do
image=${SOURCE_REGISTRY}/${SOURCE_NAP_WAF_IMAGE_PREFIX}:${SOURCE_TAG}${postfix}
echo "Processing image ${image}"
new_tag=${TARGET_REGISTRY}/${TARGET_NAP_WAF_IMAGE_PREFIX}:${TARGET_TAG}${postfix}
if $IS_IMMUTABLE && skopeo --override-os linux --override-arch amd64 inspect docker://${new_tag} > /dev/null 2>&1; then
echo " ECR is immutable & tag ${new_tag} already exists, skipping."
else
echo " Pushing image NAP WAF ${new_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${new_tag}
fi
for tag in "${ADDITIONAL_TAGS[@]}"; do
if [ -z "${tag}" ]; then
continue
fi
additional_tag=${TARGET_REGISTRY}/${TARGET_NAP_WAF_IMAGE_PREFIX}:${tag}${postfix}
echo " Pushing image NAP WAF ${additional_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${additional_tag}
fi
done
fi
done
else
echo "Skipping Publish Plus WAF flow"
fi

if $PUBLISH_DOS; then
for postfix in "${NAP_DOS_TAG_POSTFIX_LIST[@]}"; do
image=${SOURCE_REGISTRY}/${SOURCE_NAP_DOS_IMAGE_PREFIX}:${SOURCE_TAG}${postfix}
echo "Processing image ${image}"
new_tag=${TARGET_REGISTRY}/${TARGET_NAP_DOS_IMAGE_PREFIX}:${TARGET_TAG}${postfix}
if $IS_IMMUTABLE && skopeo --override-os linux --override-arch amd64 inspect docker://${new_tag} > /dev/null 2>&1; then
echo " ECR is immutable & tag ${new_tag} already exists, skipping."
else
echo " Pushing image NAP DOS ${new_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${new_tag}
fi
for tag in "${ADDITIONAL_TAGS[@]}"; do
if [ -z "${tag}" ]; then
continue
fi
additional_tag=${TARGET_REGISTRY}/${TARGET_NAP_DOS_IMAGE_PREFIX}:${tag}${postfix}
echo " Pushing image NAP DOS ${additional_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${additional_tag}
fi
done
fi
done
else
echo "Skipping Publish Plus DOS flow"
fi

if $PUBLISH_WAF_DOS; then
for postfix in "${NAP_WAF_DOS_TAG_POSTFIX_LIST[@]}"; do
image=${SOURCE_REGISTRY}/${SOURCE_NAP_WAF_DOS_IMAGE_PREFIX}:${SOURCE_TAG}${postfix}
echo "Processing image ${image}"
new_tag=${TARGET_REGISTRY}/${TARGET_NAP_WAF_DOS_IMAGE_PREFIX}:${TARGET_TAG}${postfix}
if $IS_IMMUTABLE && skopeo --override-os linux --override-arch amd64 inspect docker://${new_tag} > /dev/null 2>&1; then
echo " ECR is immutable & tag ${new_tag} already exists, skipping."
else
echo " Pushing image NAP WAF/DOS ${new_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${new_tag}
fi
for tag in "${ADDITIONAL_TAGS[@]}"; do
if [ -z "${tag}" ]; then
continue
fi
additional_tag=${TARGET_REGISTRY}/${TARGET_NAP_WAF_DOS_IMAGE_PREFIX}:${tag}${postfix}
echo " Pushing image NAP WAF/DOS ${additional_tag}..."
if ! $DRY_RUN; then
skopeo copy --retry-times 5 ${ARCH_OPTS} ${SOURCE_OPTS} ${TARGET_OPTS} docker://${image} docker://${additional_tag}
fi
done
fi
done
else
echo "Skipping Publish Plus WAF/DOS flow"
fi

0 comments on commit 3e089b1

Please sign in to comment.