doctl icon indicating copy to clipboard operation
doctl copied to clipboard

Make doctl available as a Flatpak

Open XOmniverse opened this issue 7 years ago • 12 comments

Since Flatpak is more or less the native app container solution on Fedora, it would be nice if doctl was available as a flatpak so that Fedora users don't have to have both flatpak and snap installed on their system in order to install/update doctl via a package manager.

XOmniverse avatar May 01 '18 12:05 XOmniverse

First time contributor. Would this be okay to work on?

fish-dango avatar Jun 17 '21 17:06 fish-dango

Hi @fish-dango,

We'd love it if a someone wanted to contribute a package. Though we are hoping that a contributor who is a Flatpak user with some existing domain knowledge can step up to do so. Our team does not currently have any Flatpak users, so we would not be able to help guide a contributor new to Flatpak since we are too!

andrewsomething avatar Jun 21 '21 19:06 andrewsomething

I've done the initial work on this and it runs.. I've yet to test it but have spent enough hours in front of my PC for today.

app-id: com.digitalocean.doctl
command: doctl
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.golang
cleanup:
  - /include
  - /lib/pkgconfig
  - /lib/*.a
  - /lib/*.la
  - /share/man
finish-args:
  - --device=dri
  - --filesystem=host
  - --share=ipc
  - --share=network
modules:
  - name: doctl
    buildsystem: simple
    build-options:
      prefix: /usr/lib/sdk/golang
      prepend-path: /usr/lib/sdk/golang/bin
    build-commands:
      - GO111MODULE=on CGO_ENABLED=0 go build -ldflags "${ldFlags}" -mod=vendor -o doctl cmd/doctl/main.go
      - install -Dm 755 doctl ${FLATPAK_DEST}/bin/doctl
    sources:
      - type: archive
        url: https://github.com/digitalocean/doctl/archive/refs/tags/v1.65.0.tar.gz
        sha256: b2ab4f123813ee3fdcc750b7c8f7bd9764dfa1647c54514413940449ef78cab5

Justinzobel avatar Oct 14 '21 09:10 Justinzobel

Feel free to comment on this, make suggestions, alterations etc.

Justinzobel avatar Oct 14 '21 09:10 Justinzobel

Unsure why it doesn't report the correct version, something to look into..

flatpak run com.digitalocean.doctl version
doctl version 0.0.0-dev
release 1.65.0 is available, check it out!

Justinzobel avatar Oct 14 '21 09:10 Justinzobel

I assume it has to do with this (where I stole other bits of code from): https://github.com/digitalocean/doctl/blob/main/snap/snapcraft.yaml#L35

Justinzobel avatar Oct 14 '21 09:10 Justinzobel

Hey @Justinzobel,

The doctl version is set using LDFLAGs at compile time. scripts/version.sh just attempts to detect the version by looking at git tags. Looks like this builds from the released tarball. So that probably won't work. Does flatpak has any built-in way of detecting the version from the downloaded file name?

You could hard-code it with something like:

build-commands:
  - ldFlags="-X github.com/digitalocean/doctl.Major=1"
  - ldFlags="${ldFlags} -X github.com/digitalocean/doctl.Minor=65"
  - ldFlags="${ldFlags} -X github.com/digitalocean/doctl.Patch=0"
  - GO111MODULE=on CGO_ENABLED=0 go build -ldflags "${ldFlags}" -mod=vendor -o doctl cmd/doctl/main.go
  - install -Dm 755 doctl ${FLATPAK_DEST}/bin/doctl

Thanks for working on this!

andrewsomething avatar Oct 14 '21 15:10 andrewsomething

Thank you @andrewsomething, I used your snippet and then tinkered a bit and got it to display 1.65.0 but it appends -dev to it:

doctl version 1.65.0-dev
release 1.65.0 is available, check it out!

I looked at the snap and found -X github.com/digitalocean/doctl.Label=release and that appended it ith -release and doesn't show the update available string.

Have tested it and got it to auth and list my droplets. Also tested --context for alternate teams I'm a part of.

However, since flatpak isn't quite 100% for command-line applications users will still need to run it using flatpak run com.digitalocean.com however if you're already working from a Terminal that much you are likely familiar with aliases and I just created alias doctl='flatpak run com.digitalocean.doctl and it works fine.

Andrew are you happy for me to submit the finished product to Flathub or would you prefer it go under the management of DO? I'm happy to do either. Managing updates shouldn't be hard as I can subscribe to the releases on Github.

Justinzobel avatar Oct 15 '21 01:10 Justinzobel

Full flatpak manifest for anyone's use:

app-id: com.digitalocean.doctl
command: doctl
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.golang
cleanup:
  - /include
  - /lib/pkgconfig
  - /lib/*.a
  - /lib/*.la
  - /share/man
finish-args:
  - --device=dri
  - --filesystem=host
  - --share=ipc
  - --share=network
modules:
  - name: doctl
    buildsystem: simple
    build-options:
      prefix: /usr/lib/sdk/golang
      prepend-path: /usr/lib/sdk/golang/bin
    build-commands:
        - GO111MODULE=on CGO_ENABLED=0 go build -ldflags "-X github.com/digitalocean/doctl.Label=release -X github.com/digitalocean/doctl.Major=1 -X github.com/digitalocean/doctl.Minor=65 -X github.com/digitalocean/doctl.Patch=0" -mod=vendor -o doctl cmd/doctl/main.go
        - install -Dm 755 doctl ${FLATPAK_DEST}/bin/doctl
    sources:
      - type: archive
        url: https://github.com/digitalocean/doctl/archive/refs/tags/v1.65.0.tar.gz
        sha256: b2ab4f123813ee3fdcc750b7c8f7bd9764dfa1647c54514413940449ef78cab5

To build and install:

flatpak-builder --force-clean --delete-build-dirs --arch=x86_64 --ccache --sandbox --user --install-deps-from=flathub --repo=staging-repo/ app com.digitalocean.doctl.yml
flatpak build-bundle staging-repo/ com.digitalocean.doctl.flatpak com.digitalocean.doctl
flatpak --user install -y com.digitalocean.doctl.flatpak

Justinzobel avatar Oct 15 '21 01:10 Justinzobel

Still no movement on this? I created a manifest two years ago. I'm happy to help maintain this if you'll allow me to submit it to Flathub?

Justinzobel avatar Nov 10 '23 01:11 Justinzobel