Skip to content

Commit b4dab44

Browse files
authored
Merge pull request #29 from crazy-max/go-1.18
update to Go 1.18
2 parents 573929f + 281354c commit b4dab44

File tree

8 files changed

+135
-176
lines changed

8 files changed

+135
-176
lines changed

.golangci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
run:
2+
timeout: 10m
3+
4+
linters:
5+
enable:
6+
- deadcode
7+
- depguard
8+
- gofmt
9+
- goimports
10+
- revive
11+
- govet
12+
- importas
13+
- ineffassign
14+
- misspell
15+
- typecheck
16+
- varcheck
17+
- errname
18+
- makezero
19+
- whitespace
20+
disable-all: true
21+
22+
linters-settings:
23+
depguard:
24+
list-type: blacklist
25+
include-go-root: true
26+
packages:
27+
# The io/ioutil package has been deprecated.
28+
# https://go.dev/doc/go1.16#ioutil
29+
- io/ioutil
30+
importas:
31+
no-unaliased: true
32+
33+
issues:
34+
exclude-rules:
35+
- linters:
36+
- revive
37+
text: "stutters"

Dockerfile

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Copyright 2021 cli-docs-tool authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
ARG GO_VERSION="1.18"
18+
ARG GOLANGCI_LINT_VERSION="v1.45"
19+
ARG ADDLICENSE_VERSION="v1.0.0"
20+
21+
ARG LICENSE_ARGS="-c cli-docs-tool -l apache"
22+
ARG LICENSE_FILES=".*\(Dockerfile\|\.go\|\.hcl\|\.sh\)"
23+
24+
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
25+
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
26+
27+
FROM golang:${GO_VERSION}-alpine AS base
28+
RUN apk add --no-cache cpio findutils git linux-headers
29+
ENV CGO_ENABLED=0
30+
WORKDIR /src
31+
32+
FROM base AS vendored
33+
RUN --mount=type=bind,target=.,rw \
34+
--mount=type=cache,target=/go/pkg/mod \
35+
go mod tidy && go mod download && \
36+
mkdir /out && cp go.mod go.sum /out
37+
38+
FROM scratch AS vendor-update
39+
COPY --from=vendored /out /
40+
41+
FROM vendored AS vendor-validate
42+
RUN --mount=type=bind,target=.,rw <<EOT
43+
set -e
44+
git add -A
45+
cp -rf /out/* .
46+
diff=$(git status --porcelain -- go.mod go.sum)
47+
if [ -n "$diff" ]; then
48+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"'
49+
echo "$diff"
50+
exit 1
51+
fi
52+
EOT
53+
54+
FROM base AS lint
55+
RUN --mount=type=bind,target=. \
56+
--mount=type=cache,target=/root/.cache \
57+
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
58+
golangci-lint run ./...
59+
60+
FROM base AS license-set
61+
ARG LICENSE_ARGS
62+
ARG LICENSE_FILES
63+
RUN --mount=type=bind,target=.,rw \
64+
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
65+
find . -regex "${LICENSE_FILES}" | xargs addlicense ${LICENSE_ARGS} \
66+
&& mkdir /out \
67+
&& find . -regex "${LICENSE_FILES}" | cpio -pdm /out
68+
69+
FROM scratch AS license-update
70+
COPY --from=set /out /
71+
72+
FROM base AS license-validate
73+
ARG LICENSE_ARGS
74+
ARG LICENSE_FILES
75+
RUN --mount=type=bind,target=. \
76+
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
77+
find . -regex "${LICENSE_FILES}" | xargs addlicense -check ${LICENSE_ARGS}
78+
79+
FROM vendored AS test
80+
RUN --mount=type=bind,target=. \
81+
--mount=type=cache,target=/root/.cache \
82+
--mount=type=cache,target=/go/pkg/mod \
83+
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./...
84+
85+
FROM scratch AS test-coverage
86+
COPY --from=test /tmp/coverage.txt /coverage.txt

docker-bake.hcl

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
variable "GO_VERSION" {
16-
default = "1.16"
17-
}
18-
1915
group "default" {
2016
targets = ["test"]
2117
}
@@ -25,49 +21,31 @@ group "validate" {
2521
}
2622

2723
target "lint" {
28-
args = {
29-
GO_VERSION = GO_VERSION
30-
}
31-
dockerfile = "./hack/lint.Dockerfile"
3224
target = "lint"
3325
output = ["type=cacheonly"]
3426
}
3527

3628
target "vendor-validate" {
37-
args = {
38-
GO_VERSION = GO_VERSION
39-
}
40-
dockerfile = "./hack/vendor.Dockerfile"
41-
target = "validate"
29+
target = "vendor-validate"
4230
output = ["type=cacheonly"]
4331
}
4432

4533
target "vendor-update" {
46-
args = {
47-
GO_VERSION = GO_VERSION
48-
}
49-
dockerfile = "./hack/vendor.Dockerfile"
50-
target = "update"
34+
target = "vendor-update"
5135
output = ["."]
5236
}
5337

5438
target "test" {
55-
args = {
56-
GO_VERSION = GO_VERSION
57-
}
58-
dockerfile = "./hack/test.Dockerfile"
5939
target = "test-coverage"
6040
output = ["."]
6141
}
6242

6343
target "license-validate" {
64-
dockerfile = "./hack/license.Dockerfile"
65-
target = "validate"
44+
target = "license-validate"
6645
output = ["type=cacheonly"]
6746
}
6847

6948
target "license-update" {
70-
dockerfile = "./hack/license.Dockerfile"
71-
target = "update"
49+
target = "license-update"
7250
output = ["."]
7351
}

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module github.com/docker/cli-docs-tool
22

3-
go 1.16
3+
go 1.18
44

55
require (
66
github.com/spf13/cobra v1.2.1
77
github.com/spf13/pflag v1.0.5
88
github.com/stretchr/testify v1.7.0
99
gopkg.in/yaml.v2 v2.4.0
1010
)
11+
12+
require (
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
15+
github.com/pmezard/go-difflib v1.0.0 // indirect
16+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
17+
)

hack/license.Dockerfile

Lines changed: 0 additions & 43 deletions
This file was deleted.

hack/lint.Dockerfile

Lines changed: 0 additions & 31 deletions
This file was deleted.

hack/test.Dockerfile

Lines changed: 0 additions & 36 deletions
This file was deleted.

hack/vendor.Dockerfile

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)