Skip to content

Commit

Permalink
feat: add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
csvwolf committed Sep 8, 2023
1 parent d05d150 commit dec3816
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
docker:
name: Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hostker-ddns:{{github.action_ref}},${{ secrets.DOCKERHUB_USERNAME }}/hostker-ddns:latest,
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ builds:
- linux
- windows
- darwin

ldflags:
- -X github.com/csvwolf/hostker-ddns/command.version={{.Version}}
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM ubuntu:latest

VOLUME /root/.hostker/ddns_config.yaml
VOLUME /root/.hostker
## 安装依赖
RUN apt-get update && \
apt-get install -y curl

RUN curl -o /tmp/install.sh -L https://github.com/csvwolf/hostker-ddns/raw/master/build.sh && \
RUN curl -o /tmp/install.sh -L https://raw.githubusercontent.com/csvwolf/hostker-ddns/master/install.sh && \
chmod +x /tmp/install.sh && \
/tmp/install.sh
CMD ["hostker-ddns", "start"]
ENTRYPOINT bash
ENTRYPOINT ["hostker-ddns", "start"]
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Hostker DDNS 方便用户使用 DDNS 到 Hostker 域名解析服务

### 安装
现在可以基于 shell 脚本安装依赖了,支持 Mac / Linux;Windows 有 exe,不确定是否可用

```sh
curl -o /tmp/install.sh -L https://github.com/csvwolf/hostker-ddns/raw/master/build.sh && \
chmod +x /tmp/install.sh && \
Expand All @@ -29,6 +30,30 @@ hostker-ddns run # 单次运行,可以在平台中确认
hostker-ddns start # 会每分钟跑一次,可以配合 Dockerfile 使用
```

### 在容器中运行

要在容器中运行,你可以使用 `init` 命令初始化,也可以直接建立 `.ddns-config.yaml`

```yaml
# 以下信息都可以在 https://console.hostker.net/index.html#/Domain/manage/[域名] 中找到,如果不清楚,请使用 init
domain: [域名]
email: [登录邮箱]
record:
header: [主机头]
type: [类型,一般是 A 或者 AAAA]
ttl: [TTL]
value: [记录值(IP)]
token: [API 密钥]
```
之后拉镜像并执行
```shell
docker pull csvwolf/hostker-ddns:latest
docker run -d --name ddns --restart=always -v /Users/user/.hostker:/root/.hostker csvwolf/hostker-ddns
```


## DDNS 是个啥
家里的 IP 经常变,想绑个域名的话________,这么说你应该懂了。

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/bin/bash

go build -ldflags "-X main.version=$(git describe --tags --abbrev=0)"
go build -ldflags "-X github.com/csvwolf/hostker-ddns/command.version=$(git describe --tags --abbrev=0)"
16 changes: 16 additions & 0 deletions command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package command

import (
"fmt"
"github.com/spf13/cobra"
)

var version = "unknown"

var VersionCmd = &cobra.Command{
Use: "version",
Short: "Print hostker-ddns version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hostker-DDNS version: ", version)
},
}
Binary file added hostker-ddns
Binary file not shown.
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"log"
)

var verson string

func main() {

var (
Expand All @@ -23,7 +21,7 @@ func main() {
root.AddCommand(command.InitCmd)
root.AddCommand(command.RunCmd)
root.AddCommand(command.StartCmd)

root.AddCommand(command.VersionCmd)
if err := root.Execute(); err != nil {
log.Fatalln(err)
return
Expand Down

0 comments on commit dec3816

Please sign in to comment.