From be1c2bd615b26425560df4f089a27c9730bc441f Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 9 Dec 2020 21:07:07 +0900 Subject: [PATCH] add `nerdctl version` and renew Makefile Signed-off-by: Akihiro Suda --- .github/workflows/publish.yml | 30 ----------------- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++++++++++ Makefile | 46 +++++++------------------- README.md | 15 +++++---- main.go | 3 ++ pkg/version/version.go | 25 ++++++++++++++ version.go | 38 ++++++++++++++++++++++ 7 files changed, 148 insertions(+), 70 deletions(-) delete mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 pkg/version/version.go create mode 100644 version.go diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 8cf098bde27..00000000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: publish - -on: - push: - tags: - - '*' - -jobs: - publish: - strategy: - matrix: - go-version: [ 1.15.x ] - os: [ ubuntu-20.04 ] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Make all - run: make all - - name: Upload release binaries - uses: alexellis/upload-assets@0.2.2 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - asset_paths: '["./_output/nerdctl"]' \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..bdeda0e7a3a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Release +on: + push: + tags: + - 'v*' + - 'test-action-release-*' +env: + GO111MODULE: on +jobs: + release: + strategy: + matrix: + go-version: [1.15.x] + os: [ubuntu-20.04] + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + steps: + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - uses: actions/checkout@v2 + with: + path: go/src/github.com/AkihiroSuda/nerdctl + - name: "Compile binaries" + working-directory: go/src/github.com/AkihiroSuda/nerdctl + run: make artifacts + - name: "SHA256SUMS" + working-directory: go/src/github.com/AkihiroSuda/nerdctl + run: | + ( cd _output; sha256sum nerdctl-* ) | tee /tmp/SHA256SUMS + mv /tmp/SHA256SUMS _output/SHA256SUMS + - name: "The sha256sum of the SHA256SUMS file" + working-directory: go/src/github.com/AkihiroSuda/nerdctl + run: (cd _output; sha256sum SHA256SUMS) + - name: "Prepare the release note" + working-directory: go/src/github.com/AkihiroSuda/nerdctl + run: | + tag="${GITHUB_REF##*/}" + shasha=$(sha256sum _output/SHA256SUMS | awk '{print $1}') + cat << EOF | tee /tmp/release-note.txt + ${tag} + + #### Changes + (To be documented) + + #### About the binaries + The binaries were built automatically on GitHub Actions. + See the log to verify SHA256SUMS. + https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + + The sha256sum of the SHA256SUMS file itself is ${shasha} . + EOF + - name: "Create release" + working-directory: go/src/github.com/AkihiroSuda/nerdctl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag="${GITHUB_REF##*/}" + asset_flags=() + for f in _output/*; do asset_flags+=("-a" "$f"); done + hub release create "${asset_flags[@]}" -F /tmp/release-note.txt --draft "${tag}" diff --git a/Makefile b/Makefile index 7d98bef4d5a..be51f689db4 100644 --- a/Makefile +++ b/Makefile @@ -16,19 +16,14 @@ GO ?= go -export GO_BUILD=$(GO) build -export GO_TEST=$(GO) test -PROJECT := github.com/AkihiroSuda/nerdctl +PACKAGE := github.com/AkihiroSuda/nerdctl BINDIR ?= /usr/local/bin -VERSION := $(shell git describe --tags --dirty --always) -VERSION := $(VERSION:v%=%) +VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) +REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) -BUILD_BIN_PATH := $(shell pwd)/build/bin - -GOLANGCI_LINT := $(BUILD_BIN_PATH)/golangci-lint -GOLANGCI_LINT_VERSION := "v1.32.2" +export GO_BUILD=GO111MODULE=on CGO_ENABLED=0 $(GO) build -ldflags "-X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.Revision=$(REVISION)" all: binaries @@ -40,10 +35,7 @@ help: @echo " * 'clean' - Clean artifacts." nerdctl: - CGO_ENABLED=0 $(GO_BUILD) -o $(CURDIR)/_output/nerdctl \ - -ldflags '$(GO_LDFLAGS)' \ - -tags '$(BUILDTAGS)' \ - $(PROJECT) + $(GO_BUILD) -o $(CURDIR)/_output/nerdctl $(PACKAGE) clean: find . -name \*~ -delete @@ -52,26 +44,14 @@ clean: binaries: nerdctl -build: nerdctl - -install-nerdctl: +install: install -D -m 755 $(CURDIR)/_output/nerdctl $(DESTDIR)$(BINDIR)/nerdctl -install: install-nerdctl - -lint: $(GOLANGCI_LINT) - $(GOLANGCI_LINT) run - -install.tools: install.lint - -install.lint: $(GOLANGCI_LINT) - -$(GOLANGCI_LINT): - export \ - VERSION=$(GOLANGCI_LINT_VERSION) \ - URL=https://raw.githubusercontent.com/golangci/golangci-lint \ - BINDIR=${BUILD_BIN_PATH} && \ - curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION +artifacts: + rm -f $(CURDIR)/_output/nerdctl + GOOS=linux GOARCH=amd64 $(GO_BUILD) -o $(CURDIR)/_output/nerdctl-$(VERSION)-linux-amd64 $(PACKAGE) + GOOS=linux GOARCH=arm64 $(GO_BUILD) -o $(CURDIR)/_output/nerdctl-$(VERSION)-linux-arm64 $(PACKAGE) + GOOS=linux GOARCH=arm GOARM=7 $(GO_BUILD) -o $(CURDIR)/_output/nerdctl-$(VERSION)-linux-arm-v7 $(PACKAGE) .PHONY: \ help \ @@ -79,6 +59,4 @@ $(GOLANGCI_LINT): clean \ binaries \ install \ - install-nerdctl \ - lint \ - install.tools + artifacts diff --git a/README.md b/README.md index 850f5d2e7fe..510d2616b00 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,7 @@ To list Kubernetes containers: ``` ## Install - -Run `make && sudo make install`, or just use `go get`: - -```console -# go get github.com/AkihiroSuda/nerdctl -``` +Binaries are available for amd64, arm64, and arm-v7: https://github.com/AkihiroSuda/nerdctl/releases In addition to containerd, the following components should be installed (optional): - [CNI plugins](https://github.com/containernetworking/plugins): for internet connectivity. @@ -85,12 +80,20 @@ Also, `nerdctl` might be potentially useful for debugging Kubernetes clusters, b - `--security-opt no-new-privileges` - `--privileged` +- `nerdctl version` + Lots of commands and flags are currently missing. Pull requests are highly welcome. ## Features present in `nerdctl` but not present in Docker - Namespacing as in `kubectl --namespace=`: `nerdctl --namespace= ps` - [Lazy-pulling using Stargz Snapshotter](./docs/stargz.md): `nerdctl --snapshotter=stargz run` +## Compiling nerdctl from source + +Run `make && sudo make install`. + +Using `go get github.com/AkihiroSuda/nerdctl` is possible, but unrecommended because it does not fill version strings printed in `nerdctl version` + ## Contributing to nerdctl - Please certify your [Developer Certificate of Origin (DCO)](https://developercertificate.org/), by signing off your commit with `git commit -s` and with your real name. diff --git a/main.go b/main.go index d807e3a3154..d3a0c1ef721 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "os" "strings" + "github.com/AkihiroSuda/nerdctl/pkg/version" "github.com/containerd/containerd" "github.com/containerd/containerd/defaults" "github.com/containerd/containerd/namespaces" @@ -41,6 +42,7 @@ func newApp() *cli.App { app.Name = "nerdctl" app.Usage = "Docker-compatible CLI for containerd" app.UseShortOptionHandling = true + app.Version = version.Version app.Flags = []cli.Flag{ &cli.BoolFlag{ Name: "debug", @@ -86,6 +88,7 @@ func newApp() *cli.App { rmCommand, pullCommand, runCommand, + versionCommand, } return app } diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 00000000000..b410d93bbc5 --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,25 @@ +/* + Copyright (C) nerdctl authors. + Copyright (C) containerd authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package version + +var ( + // Version is filled via Makefile + Version = "" + // Revison is filled via Makefile + Revision = "" +) diff --git a/version.go b/version.go new file mode 100644 index 00000000000..9ef28915b7e --- /dev/null +++ b/version.go @@ -0,0 +1,38 @@ +/* + Copyright (C) nerdctl authors. + Copyright (C) containerd authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package main + +import ( + "fmt" + + "github.com/AkihiroSuda/nerdctl/pkg/version" + "github.com/urfave/cli/v2" +) + +var versionCommand = &cli.Command{ + Name: "version", + Usage: "Show the nerdctl version information", + Action: versionAction, +} + +func versionAction(clicontext *cli.Context) error { + fmt.Fprintf(clicontext.App.Writer, "Client:\n") + fmt.Fprintf(clicontext.App.Writer, " Version: %s\n", version.Version) + fmt.Fprintf(clicontext.App.Writer, " Git commit: %s\n", version.Revision) + return nil +}