Skip to content

Commit 794e544

Browse files
authored
feat: publish image to Docker Hub (#1043)
This PR adds CI to release OCI images to Docker Hub using ko.
1 parent 7279a08 commit 794e544

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v4
1717

18+
- name: Login to DockerHub
19+
uses: docker/login-action@v3
20+
with:
21+
username: ${{ secrets.DOCKER_USER }}
22+
password: ${{ secrets.DOCKER_PASSWORD }}
23+
1824
- name: Set up Go
1925
uses: actions/setup-go@v5
2026
with:

.goreleaser.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ builds:
3535
--ad-hoc={{ .IsSnapshot }}
3636
output: true
3737
38+
kos:
39+
- id: container-images
40+
build: hcloud-build
41+
main: ./cmd/hcloud/
42+
repositories:
43+
- hetznercloud/cli
44+
platforms:
45+
- linux/amd64
46+
- linux/arm64
47+
base_import_paths: true
48+
base_image: alpine
49+
labels:
50+
org.opencontainers.image.source: https://github.com/hetznercloud/cli
51+
tags:
52+
- latest
53+
- "{{.Tag}}"
54+
ldflags:
55+
- -s
56+
- -w
57+
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
58+
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
59+
- -X {{ .ModulePath }}/internal/state/config.defaultConfigPathOverride=/config.toml
60+
3861
snapshot:
3962
version_template: "{{ .Version }}"
4063

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ If you have Go installed, you can build and install the latest version of
4242
prebuilt binaries or check out [`.goreleaser.yml`](.goreleaser.yml) to learn
4343
how to embed it yourself.
4444

45+
### Docker
46+
47+
A docker image is published at `hetznercloud/cli`.
48+
49+
```bash
50+
docker run --rm -e HCLOUD_TOKEN="<your token>" hetznercloud/cli:latest <command>
51+
```
52+
53+
If you want to use (and persist) your configuration, you can mount it to `/config.toml`:
54+
```bash
55+
docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest <command>
56+
```
57+
4558
## Getting Started
4659

4760
1. Visit the Hetzner Cloud Console at [console.hetzner.cloud](https://console.hetzner.cloud/),

docs/tutorials/setup-hcloud-cli.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ On Windows, you can install `hcloud` using scoop:
5353
scoop install hcloud
5454
```
5555

56+
### 1.5 Using hcloud with Docker
57+
58+
Instead of installing hcloud on the host, you can also use our docker image at `hetznercloud/cli`.
59+
60+
```bash
61+
docker run --rm -e HCLOUD_TOKEN="<your token>" hetznercloud/cli:latest <command>
62+
```
63+
64+
If you want to use (and persist) your configuration, you can mount it to `/config.toml`:
65+
```bash
66+
docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest <command>
67+
```
68+
69+
The image is based on Alpine Linux, so a shell is available in the image. You can use it to run commands interactively:
70+
71+
```bash
72+
docker run -it --rm --entrypoint /bin/sh hetznercloud/cli:latest
73+
```
74+
5675
---
5776

5877
> [!WARNING]

internal/state/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type config struct {
7272
schema Schema
7373
}
7474

75+
var defaultConfigPathOverride string
76+
7577
func New() Config {
7678
cfg := &config{}
7779
cfg.reset()
@@ -117,7 +119,11 @@ func (cfg *config) Read(f any) error {
117119
}
118120

119121
if cfg.path == "" {
120-
cfg.path = DefaultConfigPath()
122+
if defaultConfigPathOverride != "" {
123+
cfg.path = defaultConfigPathOverride
124+
} else {
125+
cfg.path = DefaultConfigPath()
126+
}
121127
}
122128

123129
var cfgBytes []byte

0 commit comments

Comments
 (0)