add `nerdctl version` and renew Makefile

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2020-12-09 21:07:07 +09:00
parent cd8fe4430c
commit be1c2bd615
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A
7 changed files with 148 additions and 70 deletions

View File

@ -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"]'

61
.github/workflows/release.yml vendored Normal file
View File

@ -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}"

View File

@ -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

View File

@ -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=<NS>`: `nerdctl --namespace=<NS> 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.

View File

@ -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
}

25
pkg/version/version.go Normal file
View File

@ -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 = "<unknown>"
// Revison is filled via Makefile
Revision = "<unknown>"
)

38
version.go Normal file
View File

@ -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
}