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..e387f586a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 + 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/docs/tutorials/setup-hcloud-cli.md b/docs/tutorials/setup-hcloud-cli.md index 5f4e8a359..24c8f5a46 100644 --- a/docs/tutorials/setup-hcloud-cli.md +++ b/docs/tutorials/setup-hcloud-cli.md @@ -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="" 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 +``` + +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] 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