Skip to content

scripts: Add --tag and --list-tags arguments to wkdev scripts #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions docs/03-Tagged-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
Over time the SDK will introduce major changes that will break behavior;
In order to easily use older versions we support tagged versions.

There are two parts to a SDK version the scripts and the image.
To use a specific tag the `wkdev-create` and `wkdev-sdk-bakery` commands take a `--tag`
argument. You can also set the `WKDEV_SDK_TAG` environment variable.

## Images
To get a list of available tags you can pass `--list-tags` to `wkdev-create`.

To use an older image with the latest scripts you can set `WKDEV_SDK_TAG`, e.g.:
For example using an older image when creating a container:

```sh
export WKDEV_SDK_TAG='23.04'
wkdev-create --name='example-name'
wkdev-create --name='example-name' --tag='23.04'
```

As the scripts diverge from older images this *may* fail but for now should work fine.

## Scripts

To use older scripts you can simply checkout the branch for that tag: `git checkout tag/23.04`.

This will use the `23.04` image by default but you may override it with `WKDEV_SDK_TAG`.
However to use older scripts you can simply checkout the branch for that tag: `git checkout tag/23.04`.
This will use the `23.04` image by default but you may override as mentioned above.

## Creating a tag

Expand Down
12 changes: 11 additions & 1 deletion scripts/host-only/wkdev-create
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ argsparse_use_option =name: "Name of container" default:wkdev
argsparse_use_option rm "Force removal of container if it already exists."
argsparse_use_option attach "Attach to container as it starts up."
argsparse_use_option no-pull "Do not login or pull images."
argsparse_use_option list-tags "List available image tags."
argsparse_use_option =tag: "Create the container using a specific tag, see-also --list-tags." default:$(get_default_container_tag)

argsparse_usage_description="$(cat <<EOF
<< Purpose >>
Expand Down Expand Up @@ -56,6 +58,14 @@ process_command_line_arguments() {
argsparse_parse_options "${@}"
argsparse_is_option_set "trace" && set -o xtrace

if argsparse_is_option_set "list-tags"; then
echo ""
podman search "$(get_sdk_qualified_name)" --list-tags --format='{{ .Tag }}'
exit 0
fi

container_tag="${program_options["tag"]}"

container_shell="${program_options["shell"]}"
container_name="${program_options["name"]}"
container_user_home="${program_options["home"]}"
Expand Down Expand Up @@ -450,7 +460,7 @@ build_podman_create_arguments() {
try_process_podman ${1}
set -o nounset

arguments+=("$(get_sdk_qualified_name_and_tag)")
arguments+=("$(get_sdk_qualified_name):${container_tag}")

# Entry point
arguments+=("/wkdev-sdk/scripts/container-only/.wkdev-init")
Expand Down
8 changes: 5 additions & 3 deletions scripts/host-only/wkdev-sdk-bakery
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ argsparse_use_option =verbose "Increase verbosity of this script"
argsparse_use_option =name: "Name of container image" mandatory default:wkdev-sdk
argsparse_use_option =mode: "Operation mode: 'build', 'deploy', or 'export'" mandatory
argsparse_use_option idle-cores: "Number of CPU cores to leave idle, when building the image" type:uint default:2
argsparse_use_option =tag: "Tag to use for created image." default:$(get_default_container_tag)

argsparse_usage_description="$(cat <<EOF
<< Purpose >>
Expand All @@ -33,21 +34,22 @@ argsparse_usage_description="$(cat <<EOF
EOF
)"

get_tag_for_build() { get_qualified_name_and_tag "${container_image_name}" "$(get_container_tag)"; }
get_number_of_cores_for_build() { nproc --ignore=${idle_cores}; }

process_command_line_arguments() {

argsparse_parse_options "${@}"
argsparse_is_option_set "trace" && set -o xtrace

container_image_name="${program_options["name"]}"
container_tag="${program_options["tag"]}"
idle_cores=${program_options["idle-cores"]}

operation_mode="${program_options["mode"]}"
[ "${operation_mode}" != 'build' ] && [ "${operation_mode}" != 'deploy' ] && [ "${operation_mode}" != 'export' ] && _abort_ "Unknown operation mode: '${operation_mode}' (valid choices are 'build', 'deploy', or 'export')"
}

get_tag_for_build() { echo "$(get_qualified_name "${container_image_name}"):${container_tag}"; }
get_number_of_cores_for_build() { nproc --ignore=${idle_cores}; }

build_image() {

echo ""
Expand Down
12 changes: 2 additions & 10 deletions utilities/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ get_default_container_registry_user_name() { echo "${WKDEV_SDK_CONTAINER_REGISTR
#####
##### Container naming/versioning
#####
get_container_tag() {
get_default_container_tag() {
local default='latest'

if [[ "$(git rev-parse --abbrev-ref HEAD)" =~ tag/(.*) ]]; then
Expand All @@ -40,18 +40,10 @@ get_qualified_name() {
echo "$(get_default_container_registry)/$(get_default_container_registry_user_name)/${image_name}"
}

# Given an image name, return the tagged, qualified image name "<registry>/<registry-user-name>/<image-name>:<image-tag>"
get_qualified_name_and_tag() {

local image_name="${1}"
local image_tag="${2}"
echo "$(get_qualified_name "${image_name}"):${image_tag}"
}

# Get absolute path to 'user_home_directory_defaults' directory in the wkdev-sdk.
get_container_home_defaults_directory_name() { echo "${WKDEV_SDK}/images/wkdev_sdk/user_home_directory_defaults"; }

##### wkdev-sdk definitions
get_sdk_image_name() { echo "wkdev-sdk"; }
get_sdk_image_tag() { get_container_tag; }
get_sdk_qualified_name_and_tag() { get_qualified_name_and_tag "$(get_sdk_image_name)" "$(get_sdk_image_tag)"; }
get_sdk_qualified_name() { get_qualified_name "$(get_sdk_image_name)"; }