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

Add support to publish Snaps using goreleaser #353

Merged
merged 4 commits into from
Dec 25, 2023

Conversation

mhalano
Copy link
Contributor

@mhalano mhalano commented Apr 9, 2022

Add support to publish Snaps using goreleaser

Closes #351

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 72ceb0b to 9903e38 Compare April 9, 2022 12:18
@mhalano mhalano mentioned this pull request Apr 9, 2022
@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 9903e38 to 19e5460 Compare April 9, 2022 12:26
Copy link
Owner

@ahmetb ahmetb left a comment

Choose a reason for hiding this comment

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

Thank you. 🙏🏼

.goreleaser.yml Outdated
plugs:
dot-kube-config:
interface: personal-files
write: [$HOME/.kube/config]
Copy link
Owner

Choose a reason for hiding this comment

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

Some people specify custom paths with >1 files. How would this work here?

.goreleaser.yml Outdated
completer: completion/kubectx.bash
plugs:
- dot-kube-config
environment:
Copy link
Owner

Choose a reason for hiding this comment

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

Probably need $KUBECONFIG here as well.

@mhalano mhalano changed the title Add support to publish Snaps using goreleaser WIP: Add support to publish Snaps using goreleaser Apr 9, 2022
@mhalano
Copy link
Contributor Author

mhalano commented Apr 9, 2022

I need to do some review in the code. I think I will need a special authorization to use the classic confinement instead of strict one. I already submit the request and if and when I get it, I will do changes in the code. Please stay tuned.

@ahmetb
Copy link
Owner

ahmetb commented Apr 21, 2022

Any updates?

@mhalano
Copy link
Contributor Author

mhalano commented Apr 21, 2022

Any updates?

@ahmetb No updates yet. I need what we call a 'classic' confinement to snap, but it has been a little hard to get an answer about my request.

@mhalano
Copy link
Contributor Author

mhalano commented May 24, 2022

@ahmetb Just to keep you on the loop: I'm still working on it. They answer me back some days ago, and now I'm trying to a new line of action to be approved. Permissions with Snap can be hard, but I think I will make it. Stay tuned.

@mhalano
Copy link
Contributor Author

mhalano commented Jun 6, 2022

@ahmetb The process to get (or not) the final approval for classic confinement is almost done. I already submitted a version with the classic confinement to the store, and I will make the final code and submit the PR to your repo ASAP.

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 19e5460 to cd7baa5 Compare June 16, 2022 13:32
@mhalano mhalano changed the title WIP: Add support to publish Snaps using goreleaser Add support to publish Snaps using goreleaser Jun 16, 2022
@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

@ahmetb Everything is now in place. I got the approval I needed, and now the PR is complete. We can discuss further how to deploy Snaps automagically as part of the pipeline, together with the other assets.

@ahmetb
Copy link
Owner

ahmetb commented Jun 16, 2022

Thanks. How do we do that? Is that something Goreleaser does or we need to authenticate and upload a different way?

@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

We can use GitHub Actions. Do you already use it to publish the assets?

@ahmetb
Copy link
Owner

ahmetb commented Jun 16, 2022

@mhalano yeah, we upload to GitHub Releases using GitHub Actions. What's involved here? Do we need to call an external API to upload assets?

@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

We need the command snapcraft in the PATH of builder (container or VM) so it can build the Snapcraft. I will look about more details how to add a step to publish the .snap file generated by the Goreleaser.

@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

I sent to your email an invitation to manage with me the Snap in the Snap Store.

Here there is a build system in place integrated with GitHub, but the problem it demands a snapcraft.yaml, so we need to take the long way and do the commands manually to use snapcraft to login and push the assets.

@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

Here it is a very interesting page about a GitHub Action that could solve the problem. What do you think?

@ahmetb
Copy link
Owner

ahmetb commented Jun 16, 2022

so we need to take the long way and do the commands manually to use snapcraft to login and push the assets.

At that point I might question do we actually need this distribution method. So far I am spending zero effort on releases in the upstream repo and anyone packaging this software in apt/yum like repos are regularly picking up the releases from here.

very interesting page about a GitHub Action that could solve the problem

Yeah, if we can't automate it with a GitHub Action then we probably should leave it out of this upstream repo. I'm happy to add a token or whatever to GitHub repo secrets, but you should probably first test this on your fork and send the changes here.

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch 6 times, most recently from b07ec17 to f231501 Compare June 16, 2022 22:22
@mhalano
Copy link
Contributor Author

mhalano commented Jun 16, 2022

@ahmetb I added a commit that adds the Snapcraft to the build system, and now it's building correctly. I just got a problem with bats execution in my local machine because absence of assets. Can you help me with that, triggering your pipeline?

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch 3 times, most recently from 832895a to 6694ac6 Compare June 17, 2022 00:09
@mhalano
Copy link
Contributor Author

mhalano commented Jun 17, 2022

I think it's done. You will need to create an Ubuntu SSO account and to install snapcraft tool to get the token with this command:

snapcraft export-login --snaps kubectx --channels "edge stable" --acls package_upload -

When you execute this command, it will open a webpage to login with your Ubuntu SSO account. That should be a no brainer.

Then you have to create a secret called SNAPCRAFT_TOKEN.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@ahmetb
Copy link
Owner

ahmetb commented Jun 21, 2022

I just got a problem with bats execution in my local machine because absence of assets.

you should be able to run bats locally or in your fork. maybe things broke since the last time we ran it.

@ahmetb
Copy link
Owner

ahmetb commented Jun 21, 2022

@mhalano I've started to think this alternative approach:

What if you had a separate ~empty repository where you have a GitHub Action that runs once per day to see if there's a new tag on ahmetb/kubectx (by keeping track of last seen version in git), and when there's a new release, you'd wget the published assets and upload a snap release from your repo? That way:

  1. we keep build times low in this repo
  2. we don't have to maintain per-distribution-method details in the upstream repo (I don't think we have any today, despite kubectx is packaged for many package managers)
  3. you can better manage what goes to Snap (description, versions etc) by taking me out of the loop as you'd be the packager.

Executing on this possibility probably depends on what goreleaser spits out here and whether you can repeat the same functionality on a separate repo.

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 6694ac6 to c55a2bf Compare June 21, 2022 23:22
@mhalano
Copy link
Contributor Author

mhalano commented Jun 21, 2022

@ahmetb I really like the way we are going to. I think the use of Goreleaser is a nice approach and in the future we could have packaging for other formats. I think this is important because sometimes if you depend on distro-packaging, like in kubectx case, to get the software installed nicely, using a package management solution, you probably need to sit and wait, dying in the process. I created the Snap version because I use kubectx/kubens and like them a lot, but Debian still didn't package and Ubuntu neither. Snap is nicer because is cross-distro and easier to create than Flatpak

@mhalano
Copy link
Contributor Author

mhalano commented Jun 21, 2022

I just got a problem with bats execution in my local machine because absence of assets.

you should be able to run bats locally or in your fork. maybe things broke since the last time we ran it.

The problem seems to be the directory name. The directory present inside dist/ is called kubectx_linux_amd64_v1 with _v1 in the end.

@ahmetb
Copy link
Owner

ahmetb commented Jun 22, 2022

Ah it seems like goreleaser itself has changed. No idea where that _v1 comes from. master branch's probably broken too.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@ahmetb
Copy link
Owner

ahmetb commented Jun 24, 2022

opened goreleaser/goreleaser#3192 to track the binary name change issue, but feel free to send a PR to master pinning goreleaser version to 1.7.0 for the time being.

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 0173f3e to 025f341 Compare June 24, 2022 12:27
@mhalano
Copy link
Contributor Author

mhalano commented Jun 24, 2022

@ahmetb I added a commit to change Goreleaser version from latest to 1.7.0 and at least the CI pipeline worked flawlessly (I didn't try the release pipeline). I read the answer for your Goreleaser issue and it seems a quite tricky problem to solve. Not impossible, just tricky.

@mhalano
Copy link
Contributor Author

mhalano commented Dec 16, 2023

Hello, I saw you released a new version and now I'm working to rebase my changes on it and also release a new version on Snap Store.

@mhalano mhalano force-pushed the add-snap-support-goreleaser branch 3 times, most recently from 6dce805 to 407b9e4 Compare December 16, 2023 22:59
@mhalano
Copy link
Contributor Author

mhalano commented Dec 16, 2023

@ahmetb please review my final PR. I also released on Snap Store the version 0.9.5 of kubectx.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@mhalano mhalano force-pushed the add-snap-support-goreleaser branch from 407b9e4 to 9d9f27b Compare December 17, 2023 00:39
- name: Publish Snaps to the Snap Store (stable channel)
run: for snap in $(ls dist/*.snap); do snapcraft upload --release=stable $snap; done
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
Copy link
Owner

Choose a reason for hiding this comment

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

I just realized I added a $SNAPCRAFT_TOKEN to the repo last year. Can we just use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 32 to 35
- name: Setup Snapcraft
run: |
mkdir -p $HOME/.cache/snapcraft/download
mkdir -p $HOME/.cache/snapcraft/stage-packages
Copy link
Owner

Choose a reason for hiding this comment

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

This step feels odd. Why doesn't the action above (or the snap command create these)? It doesn't seem you're using this cache between runs either? (we don't need, just asking.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These couple lines are necessary because of this problem. If it doesn't exist when snapcraft command is executed things go wild. Kidding. It just crash and burns. :)

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 had one more link about this as a comment in the file, but I think I lost that commit. :/

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, let's add a comment as to why we're adding this step. I definitely won't remember this in a few months :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@ahmetb Do you have any other considerations?

Copy link
Owner

Choose a reason for hiding this comment

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

I clicked on "Run action" and CI seems to be failing. I think we need a way to configure goreleaser to skip snapcraft step while just building/packaging (and skip publishing).

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 saw it. I already have an idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahmetb Done. Please check again.

@ahmetb ahmetb merged commit 8fb8c9f into ahmetb:master Dec 25, 2023
1 check passed
@ahmetb
Copy link
Owner

ahmetb commented Dec 25, 2023

Thanks for the patience here. It’ll go out with the new release, hopefully not too far from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snap support
2 participants