Skip to content
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
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ builds:
--ad-hoc={{ .IsSnapshot }}
output: true

kos:
- id: container-images
build: hcloud-build
main: ./cmd/hcloud/
repositories:
- hetznercloud/cli
platforms:
- linux/amd64
- linux/arm64
base_import_paths: true
base_image: alpine
labels:
org.opencontainers.image.source: https://github.com/hetznercloud/cli
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

@jooola jooola May 9, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does that work if the user extract the binary to use outside the container? Do we want to support this?

Or mount / inside the container (similar to network_mode: host but for the fs)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree that extracting the binary from the image would be problematic.
However I think mounting the entire FS into the container would be a bad idea because:

  • $HOME will still resolve to /home/nonroot so the config would be located at /home/nonroot/.config/hcloud/cli.toml
  • We should scope the possible file access as small as possible for security reasons

Maybe there is a way to detect if the binary is running inside a container dynamically during runtime? Or could we set HCLOUD_CONFIG somehow?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think we need to support extracting the binary explicitly. I like that we try to make defaults nicer for container users here.

ko unfortunately does not allow adding env variables to the image, so no possibility to do it through HCLOUD_CONFIG with ko.

If a user really wants to extract this binary, they can still set HCLOUD_CONFIG on their end to change the default.


snapshot:
version_template: "{{ .Version }}-dev+{{ .ShortCommit }}"

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="<your token>" hetznercloud/cli:latest <command>
```

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 <command>
```

## Getting Started

1. Visit the Hetzner Cloud Console at [console.hetzner.cloud](https://console.hetzner.cloud/),
Expand Down
19 changes: 19 additions & 0 deletions docs/tutorials/setup-hcloud-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ 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="<your token>" hetznercloud/cli:latest <command>
```

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 <command>
```

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]
Expand Down
8 changes: 7 additions & 1 deletion internal/state/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type config struct {
schema Schema
}

var defaultConfigPathOverride string

func New() Config {
cfg := &config{}
cfg.reset()
Expand Down Expand Up @@ -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
Expand Down