Skip to content
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

Release separated archives for each platform (#697) #699

Merged
merged 1 commit into from
Jun 13, 2021
Merged

Release separated archives for each platform (#697) #699

merged 1 commit into from
Jun 13, 2021

Conversation

zigarn
Copy link
Contributor

@zigarn zigarn commented Mar 13, 2021

Fixes #697

In install instructions, use --archive (and therefore --manifest-url) to not download again the tarball when launching krew install command.

@k8s-ci-robot
Copy link
Contributor

Welcome @zigarn!

It looks like this is your first PR to kubernetes-sigs/krew 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/krew has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 13, 2021
@zigarn
Copy link
Contributor Author

zigarn commented Mar 13, 2021

/assign @corneliusweig

Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! This is a welcome improvement.

Please take a look at my comments.

@@ -80,7 +80,7 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: out/krew.*
file: out/krew*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file: out/krew*
file: out/krew-*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would exclude the krew.exe[.sha256] and krew.yaml

Comment on lines 16 to 21
KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS=darwin \
$krew install --manifest=out/krew.yaml --archive=out/krew.tar.gz && \
$krew install --manifest=out/krew.yaml --archive=out/krew-darwin_amd64.tar.gz && \
KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS=linux \
$krew install --manifest=out/krew.yaml --archive=out/krew.tar.gz && \
$krew install --manifest=out/krew.yaml --archive=out/krew-linux_amd64.tar.gz && \
KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS=windows \
$krew install --manifest=out/krew.yaml --archive=out/krew.tar.gz
$krew install --manifest=out/krew.yaml --archive=out/krew-windows_amd64.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please do something like this instead:

for osarch in darwin_amd64 darwin_arm64 linux_amd64 linux_arm linux_arm64 windows_amd64; do
   KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS="${osarch%_*}" \
     $krew install --manifest=out/krew.yaml --archive="out/krew-${osarch}.tar.gz"
done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it but didn't know if not everything was tested on purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! It was on purpose to not mix architectures. Will add KREW_ARCH.

site/content/docs/user-guide/setup/install.md Outdated Show resolved Hide resolved
KREWNAME="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREWNAME}.tar.gz" &&
tar zxvf "${KREWNAME}.tar.gz" &&
./"${KREWNAME}" install --manifest-url https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.yaml --archive ./${KREWNAME}.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
./"${KREWNAME}" install --manifest-url https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.yaml --archive ./${KREWNAME}.tar.gz
./"${KREWNAME}" install krew

The --manifest and --archive options are only for testing. When a plugin is installed like this, it will be in a detached state where it is not updated when new versions are published on krew-index. So we do need to download twice here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arf, too bad.
Maybe would be possible to allow --archive without --manifest[-url] to use local archive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does not work either, I'm afraid. It should not be a big deal though. Installation is only done once, and you are already cutting down the download size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it works, by removing the lines doing the check in cmd/krew/cmd/install.go and compiling.

diff --git i/cmd/krew/cmd/install.go w/cmd/krew/cmd/install.go
index a574346..ac4b265 100644
--- i/cmd/krew/cmd/install.go
+++ w/cmd/krew/cmd/install.go
@@ -96,10 +96,6 @@ Remarks:
                                return errors.New("must specify either specify either plugin names (via positional arguments or STDIN), or --manifest/--manifest-url; not both")
                        }
 
-                       if *archiveFileOverride != "" && *manifest == "" && *manifestURL == "" {
-                               return errors.New("--archive can be specified only with --manifest or --manifest-url")
-                       }
-
                        var install []pluginEntry
                        for _, name := range pluginNames {
                                indexName, pluginName := pathutil.CanonicalPluginName(name)
$ curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz"
$ ./out/bin/krew-linux_amd64 install krew --archive ./krew.tar.gz
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
Updated the local copy of plugin index.
Installing plugin: krew
Installed plugin: krew
\
 | Use this plugin:
 | 	kubectl krew
 | Documentation:
 | 	https://krew.sigs.k8s.io/
 | Caveats:
 | \
 |  | krew is now installed! To start using kubectl plugins, you need to add
 |  | krew's installation directory to your PATH:
 |  | 
 |  |   * macOS/Linux:
 |  |     - Add the following to your ~/.bashrc or ~/.zshrc:
 |  |         export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
 |  |     - Restart your shell.
 |  | 
 |  |   * Windows: Add %USERPROFILE%\.krew\bin to your PATH environment variable
 |  | 
 |  | To list krew commands and to get help, run:
 |  |   $ kubectl krew
 |  | For a full list of available plugins, run:
 |  |   $ kubectl krew search
 |  | 
 |  | You can find documentation at
 |  |   https://krew.sigs.k8s.io/docs/user-guide/quickstart/.
 | /
/

$ tail ~/.krew/receipts/krew.yaml
      matchLabels:
        arch: amd64
        os: windows
    sha256: a26deea175f70264260d59a4e061778a892f8a8e301ac261660dd7d24c551c99
    uri: https://github.com/kubernetes-sigs/krew/releases/download/v0.4.1/krew.tar.gz
  shortDescription: Package manager for kubectl plugins.
  version: v0.4.1
status:
  source:
    name: default

Source is not 'detached'.
And I can confirm tat there is no download of archive through the install.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we reserved those arguments specifically for local testing so they are used for installing "detached" plugins. I’m not sure if it's worth changing that just to prevent downloading a small tarball once more.

site/content/docs/user-guide/setup/install.md Outdated Show resolved Hide resolved
Comment on lines 27 to 30
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &&
tar zxvf krew.tar.gz &&
KREW=./krew-"${OS}_${ARCH}" &&
"$KREW" install krew
KREWNAME="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREWNAME}.tar.gz" &&
tar zxvf "${KREWNAME}.tar.gz" &&
./"${KREWNAME}" install --manifest-url https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.yaml --archive ./${KREWNAME}.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file will affect the installation instructions seen by users for the current release. However, these instructions only become effective, once we craft a new release with the other changes within this PR. So the doc updates must go into a different PR that will be merged after the next release.
So please extract this into a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted in #700

Previous comments on it have been applied.

(
cd "${archive_dir}"
# consistent timestamps for files in archive dir to ensure consistent checksums
TZ=UTC touch -amt "0001010000" ./*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this could make trouble on Mac/BSD, because the man says

-a change only the access time
-m change only the modification time

So I'm worried they take the only too seriously. If you can check it works then great.

However, we can still make the change, because nowadays the release is only done by GH actions and they run on Linux where I have verified that the result is the same.

Copy link
Contributor Author

@zigarn zigarn Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc start with:

Update the access and modification times of each FILE to the current time.

So I guess the only means that this option will change this one only compared to both.
And at the end, using both options is same as using none...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D good catch

archive_dir="$(mktemp -d)"
cp "$f" "${archive_dir}"
cp -- "${SCRIPTDIR}/../LICENSE" "${archive_dir}"
archive="$(basename "$f" .exe).tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this into a variable, because it is reused a few times.

Suggested change
archive="$(basename "$f" .exe).tar.gz"
name=$(basename "$f" .exe)
archive="${name}.tar.gz"

checksum_cmd="sha256sum"
fi
# prepare krew manifest sed
checksum_sed="${checksum_sed};s/KREW_$(basename "$f" .exe | sed 's/krew-\(.*\)/\U\1/')_CHECKSUM/${checksum}/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the intent clearer by using tr here:

Suggested change
checksum_sed="${checksum_sed};s/KREW_$(basename "$f" .exe | sed 's/krew-\(.*\)/\U\1/')_CHECKSUM/${checksum}/"
checksum_sed="${checksum_sed};s/$(tr "[[:lower:]-]" "[[:upper:]_]" <<< ${name}
)_CHECKSUM/${checksum}/"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ah, I did hesitate between both.

@@ -75,6 +76,6 @@ if [[ ! "${git_describe}" =~ v.* ]]; then
fi
krew_version="${TAG_NAME:-$git_describe}"
cp ./hack/krew.yaml ./out/krew.yaml
sed -i "s/KREW_TAR_CHECKSUM/${tar_checksum}/g" ./out/krew.yaml
sed -i "${checksum_sed}" ./out/krew.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sed -i "${checksum_sed}" ./out/krew.yaml
sed "${checksum_sed}" ./hack/krew.yaml > ./out/krew.yaml

And remove the cp ./hack/krew.yaml ./out/krew.yaml in the previous line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did also integrated the next sed in it.

Co-authored-by: Cornelius Weig <corneliusweig@users.noreply.github.com>
Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works flawlessly, thanks! The only thing that I could not verify is that our release automation uploads the right files. It looks right though.

/lgtm
/approve
/hold
In case @ahmetb wants to take a look too.

KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS=windows \
$krew install --manifest=out/krew.yaml --archive=out/krew.tar.gz
for osarch in darwin_amd64 darwin_arm64 linux_amd64 linux_arm linux_arm64 windows_amd64; do
KREW_ROOT="$(mktemp -d --tmpdir krew-XXXXXXXXXX)" KREW_OS="${osarch%_*}" KREW_ARCH="${osarch#*_}" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) I didn't even think of setting KREW_ARCH. Great that we do now!

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 14, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: corneliusweig, zigarn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 14, 2021
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 13, 2021
@zigarn
Copy link
Contributor Author

zigarn commented Jun 13, 2021

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 13, 2021
@corneliusweig
Copy link
Contributor

/hold cancel
Sorry, this slipped through. Feel free to be more impatient and ping me next time :)

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 13, 2021
@k8s-ci-robot k8s-ci-robot merged commit 4c16711 into kubernetes-sigs:master Jun 13, 2021
@zigarn zigarn deleted the issue-697 branch June 15, 2021 04:12
@zigarn
Copy link
Contributor Author

zigarn commented Jun 15, 2021

@corneliusweig, it has to wait for a release anyway, so no reason to be impatient.
BTW, any ETA for next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[releases] provide platform-specific binaries instead of tarball
5 participants