From 80a4f9c13b5dfe7afaa4822713088d7c67d48623 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 8 May 2025 17:08:28 +0200 Subject: [PATCH 1/7] ci: publish image to Docker Hub --- .github/workflows/release.yml | 6 ++++++ .goreleaser.yml | 15 +++++++++++++++ README.md | 13 +++++++++++++ internal/state/config/config.go | 8 +++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ecf69bad1..e55af9944 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,6 +15,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/.goreleaser.yml b/.goreleaser.yml index 3f4d89785..b3c73bcc0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -35,6 +35,21 @@ builds: --ad-hoc={{ .IsSnapshot }} output: true +kos: + - id: container-images + build: hcloud-build + repositories: + - hetznercloud/cli + platforms: + - linux/amd64 + - linux/arm64 + base_import_paths: true + labels: + org.opencontainers.image.source: https://github.com/apricote/hcloud-upload-image + tags: + - latest + - "{{.Tag}}" + snapshot: version_template: "{{ .Version }}-dev+{{ .ShortCommit }}" diff --git a/README.md b/README.md index ee21c4037..d7463e5b3 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,19 @@ If you have Go installed, you can build and install the latest version of prebuilt binaries or check out [`.goreleaser.yml`](.goreleaser.yml) to learn how to embed it yourself. +### Docker + +A docker image is published at `hetznercloud/cli`. + +```bash +docker run --rm -e HCLOUD_TOKEN="" hetznercloud/cli:latest +``` + +If you want to use (and persist) your configuration, you can mount it to `/config.toml`: +```bash +docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest +``` + ## Getting Started 1. Visit the Hetzner Cloud Console at [console.hetzner.cloud](https://console.hetzner.cloud/), diff --git a/internal/state/config/config.go b/internal/state/config/config.go index a60c874f1..3cdd55fac 100644 --- a/internal/state/config/config.go +++ b/internal/state/config/config.go @@ -72,6 +72,8 @@ type config struct { schema Schema } +var defaultConfigPathOverride string + func New() Config { cfg := &config{} cfg.reset() @@ -117,7 +119,11 @@ func (cfg *config) Read(f any) error { } if cfg.path == "" { - cfg.path = DefaultConfigPath() + if defaultConfigPathOverride != "" { + cfg.path = defaultConfigPathOverride + } else { + cfg.path = DefaultConfigPath() + } } var cfgBytes []byte From 99cb31acd8933221e6a35f02ea597ca92894bef9 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 8 May 2025 17:13:12 +0200 Subject: [PATCH 2/7] add defaultConfigPathOverride to ko build --- .goreleaser.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index b3c73bcc0..019e37b84 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -49,6 +49,12 @@ kos: tags: - latest - "{{.Tag}}" + ldflags: + - -s + - -w + - -X {{ .ModulePath }}/internal/version.version={{ .Version }} + - -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}} + - -X {{ .ModulePath }}/internal/state/config.defaultConfigPathOverride=/config.toml snapshot: version_template: "{{ .Version }}-dev+{{ .ShortCommit }}" From efbee1a58fa4dc6b51cc8434ffa452e7508d704d Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 8 May 2025 17:26:05 +0200 Subject: [PATCH 3/7] don't reference go file --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 019e37b84..6162d603c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -38,6 +38,7 @@ builds: kos: - id: container-images build: hcloud-build + main: ./cmd/hcloud/ repositories: - hetznercloud/cli platforms: From 508766450e483f68c3a5b63848bf76862f5fe3e6 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 9 May 2025 10:32:58 +0200 Subject: [PATCH 4/7] wrong image source --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 6162d603c..73daf2489 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -46,7 +46,7 @@ kos: - linux/arm64 base_import_paths: true labels: - org.opencontainers.image.source: https://github.com/apricote/hcloud-upload-image + org.opencontainers.image.source: https://github.com/hetznercloud/cli tags: - latest - "{{.Tag}}" From 88825192bfe561e49e8b266083c9b9a212fd66f5 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 9 May 2025 15:50:27 +0200 Subject: [PATCH 5/7] add docker section to setup tutorial --- docs/tutorials/setup-hcloud-cli.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/tutorials/setup-hcloud-cli.md b/docs/tutorials/setup-hcloud-cli.md index 5f4e8a359..1b469046d 100644 --- a/docs/tutorials/setup-hcloud-cli.md +++ b/docs/tutorials/setup-hcloud-cli.md @@ -53,6 +53,19 @@ On Windows, you can install `hcloud` using scoop: scoop install hcloud ``` +### 1.5 Using hcloud with Docker + +Instead of installing hcloud on the host, you can also use our docker image at `hetznercloud/cli`. + +```bash +docker run --rm -e HCLOUD_TOKEN="" hetznercloud/cli:latest +``` + +If you want to use (and persist) your configuration, you can mount it to `/config.toml`: +```bash +docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest +``` + --- > [!WARNING] From 07d1b9338b0b4003496e163dfd723d6dd4f0f73f Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 9 May 2025 16:16:22 +0200 Subject: [PATCH 6/7] use alpine base image --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 73daf2489..e387f586a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -45,6 +45,7 @@ kos: - linux/amd64 - linux/arm64 base_import_paths: true + base_image: alpine labels: org.opencontainers.image.source: https://github.com/hetznercloud/cli tags: From 2523e90bc7767b72883a4c038d2f517c65e22b98 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 9 May 2025 17:17:04 +0200 Subject: [PATCH 7/7] mention base image in docs --- docs/tutorials/setup-hcloud-cli.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/tutorials/setup-hcloud-cli.md b/docs/tutorials/setup-hcloud-cli.md index 1b469046d..24c8f5a46 100644 --- a/docs/tutorials/setup-hcloud-cli.md +++ b/docs/tutorials/setup-hcloud-cli.md @@ -66,6 +66,12 @@ If you want to use (and persist) your configuration, you can mount it to `/confi docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest ``` +The image is based on Alpine Linux, so a shell is available in the image. You can use it to run commands interactively: + +```bash +docker run -it --rm --entrypoint /bin/sh hetznercloud/cli:latest +``` + --- > [!WARNING]