From 5e5b5047aad46c0c1c641806c39297133b9937f0 Mon Sep 17 00:00:00 2001 From: abdfnx Date: Thu, 14 Apr 2022 12:09:44 +0000 Subject: [PATCH] mv `cmd` to `cli`, update workflows, init taskfile --- .github/workflows/ci.yml | 2 +- .github/workflows/docker.yml | 10 +++++-- .github/workflows/go.yml | 2 +- .github/workflows/release.yml | 15 ++++------ .gitignore | 2 +- .goreleaser.yml | 2 +- Makefile | 29 ------------------- Taskfile.yaml | 51 +++++++++++++++++++++++++++++++++ cli/{ => commands}/settings.go | 2 +- {cmd => cli}/doko/help.go | 0 {cmd => cli}/doko/help_topic.go | 0 {cmd => cli}/doko/root.go | 6 ++-- {cmd => cli}/factory/default.go | 0 core/checker/checker.go | 2 +- main.go | 4 +-- 15 files changed, 76 insertions(+), 51 deletions(-) delete mode 100644 Makefile create mode 100644 Taskfile.yaml rename cli/{ => commands}/settings.go (99%) rename {cmd => cli}/doko/help.go (100%) rename {cmd => cli}/doko/help_topic.go (100%) rename {cmd => cli}/doko/root.go (93%) rename {cmd => cli}/factory/default.go (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd560dc..3d8627d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Building From Source run: | - go mod tidy -compat=1.18 + go mod tidy go run ./scripts/date.go >> date.txt go build -ldflags "-X main.version=$(git describe --abbrev=0 --tags) -X main.buildDate=$(cat date.txt)" -o doko diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 29222c4..97dca21 100755 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -24,7 +24,10 @@ jobs: password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - name: Build Doko Container - run: make brcwc + run: | + docker pull $DK_CONTAINER:latest + docker build -t $DK_CONTAINER --cache-from $DK_CONTAINER:latest . + docker push $DK_CONTAINER dk_container_run: runs-on: ubuntu-latest @@ -51,4 +54,7 @@ jobs: password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - name: Build Doko Full Container - run: make bfrcwc + run: | + docker pull $DK_FULL_CONTAINER:latest + docker build -t $DK_FULL_CONTAINER --cache-from $DK_FULL_CONTAINER:latest . + docker push $DK_FULL_CONTAINER diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index aec924b..ae54bdf 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: - name: Build run: | - go mod tidy -compat=1.18 + go mod tidy go run ./scripts/date.go >> date.txt go build -ldflags "-X main.version=$(git describe --abbrev=0 --tags) -X main.buildDate=$(cat date.txt)" -o doko diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b5549fe..c210a35 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,15 +30,14 @@ jobs: with: install-only: true - - name: Set up `Tag` - id: ghtag - run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + - name: Set up `Task` + uses: arduino/setup-task@v1 - - name: Set up `Date` - run: go run ./scripts/date.go >> date.txt + - name: Set up Build Info + run: task setup - name: Build - run: BuildDate="$(cat date.txt)" goreleaser release --rm-dist --timeout 100m + run: task release - name: Login to Docker Hub uses: docker/login-action@v1 @@ -47,6 +46,4 @@ jobs: password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - name: Build Doko Containers - run: | - make brc - make bfrc + run: task build-docker diff --git a/.gitignore b/.gitignore index ba53e89..faa58ed 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ *.so *.dylib /doko -date.txt +*.txt # Test binary, built with `go test -c` *.test diff --git a/.goreleaser.yml b/.goreleaser.yml index 222b3bf..9e4473e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -10,7 +10,7 @@ release: before: hooks: - - go mod tidy -compat=1.18 + - go mod tidy builds: - <<: &build_defaults diff --git a/Makefile b/Makefile deleted file mode 100644 index d25d1a1..0000000 --- a/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -.PHONY: build - -TAG=$(shell git describe --abbrev=0 --tags) -DATE=$(shell go run ./scripts/date.go) - -build: - @go mod tidy -compat=1.18 && \ - go build -ldflags "-X main.version=$(TAG) -X main.buildDate=$(DATE)" -o doko - -install: doko - @mv doko /usr/local/bin - -brc: # build doko container - @docker build -t dokocli/doko . && \ - docker push dokocli/doko - -bfrc: # build full doko container - @docker build -t dokocli/doko-full --file ./docker/doko-full/Dockerfile . && \ - docker push dokocli/doko-full - -brcwc: # build doko container with cache - @docker pull dokocli/doko:latest && \ - docker build -t dokocli/doko --cache-from dokocli/doko:latest . && \ - docker push dokocli/doko - -bfrcwc: # build full doko container with cache - @docker pull dokocli/doko-full:latest && \ - docker build -t dokocli/doko-full --cache-from dokocli/doko-full:latest . && \ - docker push dokocli/doko-full diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..c4bdc34 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,51 @@ +# https://taskfile.dev + +version: "3" + +vars: + DOKO_UNIX_PATH: /usr/local/bin + +tasks: + default: + cmds: + - task: build + + setup: + cmds: + - if [ -f "date.txt" ]; then rm date.txt; fi + - if [ -f "tag.txt" ]; then rm tag.txt; fi + - go run ./scripts/date.go >> date.txt + - git describe --abbrev=0 --tags >> tag.txt + + remove: + cmds: + - sudo rm -rf "{{ .DOKO_UNIX_PATH }}"/doko + + install: + cmds: + - sudo mv doko "{{ .DOKO_UNIX_PATH }}" + + release: + cmds: + - BuildDate="$(cat date.txt)" goreleaser release --rm-dist --timeout 100m + + build: + cmds: + - task: setup + - go mod tidy + - go build -ldflags "-X main.version=$(cat tag.txt) -X main.buildDate=$(cat date.txt)" -o doko + + build-docker: + cmds: + - task: build-docker-cli + + build-docker-cli: + cmds: + - docker build -t dokocli/doko . + - docker push dokocli/doko + + build-docker-full: + dir: ./docker/doko-full + cmds: + - docker build -t dokocli/doko-full . + - docker push dokocli/doko-full diff --git a/cli/settings.go b/cli/commands/settings.go similarity index 99% rename from cli/settings.go rename to cli/commands/settings.go index ecdb875..eca0d6a 100644 --- a/cli/settings.go +++ b/cli/commands/settings.go @@ -1,4 +1,4 @@ -package cli +package commands import ( "fmt" diff --git a/cmd/doko/help.go b/cli/doko/help.go similarity index 100% rename from cmd/doko/help.go rename to cli/doko/help.go diff --git a/cmd/doko/help_topic.go b/cli/doko/help_topic.go similarity index 100% rename from cmd/doko/help_topic.go rename to cli/doko/help_topic.go diff --git a/cmd/doko/root.go b/cli/doko/root.go similarity index 93% rename from cmd/doko/root.go rename to cli/doko/root.go index 0e49f61..6f0f5df 100755 --- a/cmd/doko/root.go +++ b/cli/doko/root.go @@ -6,8 +6,8 @@ import ( "os" "runtime" - "github.com/abdfnx/doko/cli" - "github.com/abdfnx/doko/cmd/factory" + "github.com/abdfnx/doko/cli/commands" + "github.com/abdfnx/doko/cli/factory" "github.com/abdfnx/doko/core" "github.com/abdfnx/doko/core/opts" "github.com/abdfnx/doko/docker" @@ -134,7 +134,7 @@ func Execute(f *factory.Factory, version string, buildDate string) *cobra.Comman rootCmd.SetFlagErrorFunc(rootFlagErrorFunc) // add `versionCmd` to root command - rootCmd.AddCommand(cli.SettingsCMD(), versionCmd) + rootCmd.AddCommand(commands.SettingsCMD(), versionCmd) // add flags rootCmd.Flags().StringVarP(&dokoOpts.Endpoint, "endpoint", "e", client.DefaultDockerHost, "The docker endpoint to use") diff --git a/cmd/factory/default.go b/cli/factory/default.go similarity index 100% rename from cmd/factory/default.go rename to cli/factory/default.go diff --git a/core/checker/checker.go b/core/checker/checker.go index 404fe24..09e76ef 100644 --- a/core/checker/checker.go +++ b/core/checker/checker.go @@ -6,7 +6,7 @@ import ( "github.com/abdfnx/doko/tools" "github.com/abdfnx/doko/core/api" - "github.com/abdfnx/doko/cmd/factory" + "github.com/abdfnx/doko/cli/factory" "github.com/mgutz/ansi" "github.com/tidwall/gjson" diff --git a/main.go b/main.go index 812f28d..4998b4d 100755 --- a/main.go +++ b/main.go @@ -7,8 +7,8 @@ import ( "runtime" "github.com/abdfnx/doko/tools" - "github.com/abdfnx/doko/cmd/doko" - "github.com/abdfnx/doko/cmd/factory" + "github.com/abdfnx/doko/cli/doko" + "github.com/abdfnx/doko/cli/factory" "github.com/abdfnx/doko/core/checker" "github.com/AlecAivazis/survey/v2/terminal"