Skip to content

Commit aeade85

Browse files
committed
feat(container-pull): add ability to add custom tags when copying to a registry
Fixes #405 This PR introduces the `--copy-custom-tag` option for the container pull script that now allows a user to use a custom tag when copying an image to registry.
1 parent 86ff516 commit aeade85

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

bash/containers/falcon-container-sensor-pull/README.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ Optional Flags:
100100
101101
--runtime <RUNTIME> Use a different container runtime [docker, podman, skopeo] (Default: docker)
102102
--dump-credentials Print registry credentials to stdout to copy/paste into container tools
103-
--copy-omit-image-name Omit the image name from the destination path when copying
103+
--copy-omit-image-name Omit the image name from the destination path when copying (requires -c, --copy)
104+
--copy-custom-tag <TAG> Use custom tag when copying image (requires -c, --copy)
104105
--get-image-path Get the full image path including the registry, repository, and latest tag for the specified SENSOR_TYPE
105106
--get-pull-token Get the pull token of the selected SENSOR_TYPE for Kubernetes
106107
--get-cid Get the CID assigned to the API Credentials
@@ -131,7 +132,8 @@ Help Options:
131132
| `--runtime` | `$CONTAINER_TOOL` | `docker` (Optional) | Use a different container runtime [docker, podman, skopeo]. **Default is Docker**. |
132133
| `--dump-credentials` | `$CREDS` | `False` (Optional) | Print registry credentials to stdout to copy/paste into container tools |
133134
| `--get-image-path` | N/A | `None` | Get the full image path including the registry, repository, and latest tag for the specified `SENSOR_TYPE`. |
134-
| `--copy-omit-image-name` | N/A | `None` | Omit the image name from the destination path when copying |
135+
| `--copy-omit-image-name` | N/A | `None` | Omit the image name from the destination path when copying (requires -c, --copy) |
136+
| `--copy-custom-tag <TAG>` | N/A | `None` | Use custom tag when copying image (requires -c, --copy) |
135137
| `--get-pull-token` | N/A | `None` | Get the pull token of the selected `SENSOR_TYPE` for Kubernetes. |
136138
| `--get-cid` | N/A | `None` | Get the CID assigned to the API Credentials. |
137139
| `--list-tags` | `$LISTTAGS` | `False` (Optional) | List all tags available for the selected sensor |
@@ -267,6 +269,37 @@ Results in: `myregistry.com/mynamespace/falcon-sensor:<tag>`
267269

268270
Results in: `myregistry.com/mynamespace/myfalcon-sensor:<tag>`
269271

272+
#### Example copying an image with a custom tag
273+
274+
The following example will copy the `falcon-container` image to a different registry using a custom tag instead of the default version tag:
275+
276+
```shell
277+
./falcon-container-sensor-pull.sh \
278+
--client-id <FALCON_CLIENT_ID> \
279+
--client-secret <FALCON_CLIENT_SECRET> \
280+
--type falcon-container \
281+
--copy myregistry.com/mynamespace \
282+
--copy-custom-tag latest \
283+
--runtime docker
284+
```
285+
286+
Results in: `myregistry.com/mynamespace/falcon-container:latest`
287+
288+
You can also combine this with other options:
289+
290+
```shell
291+
./falcon-container-sensor-pull.sh \
292+
--client-id <FALCON_CLIENT_ID> \
293+
--client-secret <FALCON_CLIENT_SECRET> \
294+
--type falcon-sensor \
295+
--copy myregistry.com/mynamespace/custom-sensor \
296+
--copy-omit-image-name \
297+
--copy-custom-tag v1.2.3-production \
298+
--runtime skopeo
299+
```
300+
301+
Results in: `myregistry.com/mynamespace/custom-sensor:v1.2.3-production`
302+
270303
#### Example copying multi-arch image for a specific platform
271304

272305
The following example will copy the `falcon-sensor` multi-arch image for the `aarch64` platform to a different registry using Skopeo.

bash/containers/falcon-container-sensor-pull/falcon-container-sensor-pull.sh

+29-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Optional Flags:
3939
4040
--runtime <RUNTIME> Use a different container runtime [docker, podman, skopeo] (Default: docker)
4141
--dump-credentials Print registry credentials to stdout to copy/paste into container tools
42-
--copy-omit-image-name Omit the image name from the destination path when copying
42+
--copy-omit-image-name Omit the image name from the destination path when copying (requires -c, --copy)
43+
--copy-custom-tag <TAG> Use custom tag when copying image (requires -c, --copy)
4344
--get-image-path Get the full image path including the registry, repository, and latest tag for the specified SENSOR_TYPE
4445
--get-pull-token Get the pull token of the selected SENSOR_TYPE for Kubernetes
4546
--get-cid Get the CID assigned to the API Credentials
@@ -145,6 +146,12 @@ while [ $# != 0 ]; do
145146
COPY_OMIT_IMAGE_NAME=true
146147
fi
147148
;;
149+
--copy-custom-tag)
150+
if [ -n "${1}" ]; then
151+
CUSTOM_TAG="${2}"
152+
shift
153+
fi
154+
;;
148155
--get-pull-token)
149156
if [ -n "${1}" ]; then
150157
PULLTOKEN=true
@@ -415,7 +422,6 @@ copy_image() {
415422
"$CONTAINER_TOOL" tag "$source_path" "$destination_path"
416423
"$CONTAINER_TOOL" push "$destination_path"
417424
fi
418-
echo "Image copied to: $destination_path"
419425
}
420426

421427
detect_container_tool() {
@@ -730,11 +736,24 @@ if [ "${COPY_OMIT_IMAGE_NAME}" = "true" ] && [ -z "${COPY}" ]; then
730736
die "--copy-omit-image-name requires -c, --copy to be specified"
731737
fi
732738

739+
if [ -n "${CUSTOM_TAG}" ] && [ -z "${COPY}" ]; then
740+
die "--copy-custom-tag requires --copy to be specified"
741+
fi
742+
733743
# Construct destination path
734-
if [ "${COPY_OMIT_IMAGE_NAME}" = "true" ]; then
735-
COPYPATH="$COPY:$LATESTSENSOR"
744+
if [ -n "${CUSTOM_TAG}" ]; then
745+
# Use custom tag if specified
746+
if [ "${COPY_OMIT_IMAGE_NAME}" = "true" ]; then
747+
COPYPATH="$COPY:$CUSTOM_TAG"
748+
else
749+
COPYPATH="$COPY/$IMAGE_NAME:$CUSTOM_TAG"
750+
fi
736751
else
737-
COPYPATH="$COPY/$IMAGE_NAME:$LATESTSENSOR"
752+
if [ "${COPY_OMIT_IMAGE_NAME}" = "true" ]; then
753+
COPYPATH="$COPY:$LATESTSENSOR"
754+
else
755+
COPYPATH="$COPY/$IMAGE_NAME:$LATESTSENSOR"
756+
fi
738757
fi
739758

740759
# Handle multi-arch images first
@@ -743,7 +762,7 @@ if [ "$(is_multi_arch "$FULLIMAGEPATH")" = "true" ]; then
743762
if [ -n "$SENSOR_PLATFORM" ]; then
744763
# If Skopeo is being used, the platform must be overridden
745764
if grep -qw "skopeo" "$CONTAINER_TOOL"; then
746-
"$CONTAINER_TOOL" copy --override-arch "$(platform_override)" "docker://$FULLIMAGEPATH" "docker://$COPYPATH"
765+
"$CONTAINER_TOOL" copy --override-arch "$(platform_override)" --override-os linux "docker://$FULLIMAGEPATH" "docker://$COPYPATH"
747766
else
748767
# Podman/Docker can pull the specific platform
749768
pf_override="linux/$(platform_override)"
@@ -781,3 +800,7 @@ else
781800
fi
782801
fi
783802
fi
803+
804+
if [ -n "$COPY" ]; then
805+
echo "Image copied to: $COPYPATH"
806+
fi

0 commit comments

Comments
 (0)