Skip to content

Commit

Permalink
add nerdctl version and renew Makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Dec 9, 2020
1 parent cd8fe44 commit be1c2bd
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 70 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/publish.yml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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}"
46 changes: 12 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -52,33 +44,19 @@ 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 \
nerdctl \
clean \
binaries \
install \
install-nerdctl \
lint \
install.tools
artifacts
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -86,6 +88,7 @@ func newApp() *cli.App {
rmCommand,
pullCommand,
runCommand,
versionCommand,
}
return app
}
25 changes: 25 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -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 changes: 38 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit be1c2bd

Please sign in to comment.