diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 015a253..c94063f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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, \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c6e00a5..6b4e01b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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. diff --git a/Dockerfile b/Dockerfile index b4bb3d4..7c88406 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file +ENTRYPOINT ["hostker-ddns", "start"] \ No newline at end of file diff --git a/README.md b/README.md index f372c5f..4137249 100644 --- a/README.md +++ b/README.md @@ -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 && \ @@ -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 经常变,想绑个域名的话________,这么说你应该懂了。 diff --git a/build.sh b/build.sh index 916986b..9d8419f 100644 --- a/build.sh +++ b/build.sh @@ -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)" diff --git a/command/version.go b/command/version.go new file mode 100644 index 0000000..d536b5d --- /dev/null +++ b/command/version.go @@ -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) + }, +} diff --git a/hostker-ddns b/hostker-ddns new file mode 100755 index 0000000..138af08 Binary files /dev/null and b/hostker-ddns differ diff --git a/main.go b/main.go index bef99c9..70c8847 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,6 @@ import ( "log" ) -var verson string - func main() { var ( @@ -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