Skip to content

Commit 51db55c

Browse files
authored
Merge pull request #30 from rchincha/compliance
compliance: initial commit
2 parents 2941b03 + b107d6d commit 51db55c

10 files changed

Lines changed: 249 additions & 116 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# zot [![Build Status](https://travis-ci.org/anuvu/zot.svg?branch=master)](https://travis-ci.org/anuvu/zot) [![codecov.io](http://codecov.io/github/anuvu/zot/coverage.svg?branch=master)](http://codecov.io/github/anuvu/zot?branch=master)
22

33
**zot** is a vendor-neutral OCI image repository server purely based on
4-
[OCI Distribution Specification]
5-
(https://github.com/opencontainers/distribution-spec).
4+
[OCI Distribution Specification](https://github.com/opencontainers/distribution-spec).
65

76
* Conforms to [OCI distribution spec](https://github.com/opencontainers/distribution-spec) APIs
87
* Uses [OCI storage layout](https://github.com/opencontainers/image-spec/blob/master/image-layout.md) for storage layout
98
* TLS support
109
* Authentication via TLS mutual authentication and HTTP *BASIC* (local _htpasswd_ and LDAP)
1110
* Doesn't require _root_ privileges
1211
* Swagger based documentation
12+
* Can run compliance checks against registries
1313
* Released under Apache 2.0 License
1414

1515
# Presentations
@@ -39,12 +39,19 @@ make
3939

4040
Build artifacts are in bin/
4141

42-
# Running
43-
42+
# Serving
43+
```
4444
bin/zot serve _config-file_
45+
```
4546

4647
Examples of config files are available in [examples/](examples/) dir.
4748

49+
# Compliance checks
50+
51+
```
52+
bin/zot -H hostIP -P port [-V "all"]
53+
```
54+
4855
# Ecosystem
4956

5057
## skopeo

pkg/api/BUILD.bazel

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ go_library(
3434
go_test(
3535
name = "go_default_test",
3636
timeout = "short",
37-
srcs = [
38-
"controller_test.go",
39-
"routes_test.go",
40-
],
37+
srcs = ["controller_test.go"],
4138
data = [
4239
"//:exported_testdata",
4340
],
4441
embed = [":go_default_library"],
4542
race = "on",
4643
deps = [
4744
"@com_github_nmcclain_ldap//:go_default_library",
48-
"@com_github_opencontainers_go_digest//:go_default_library",
49-
"@com_github_opencontainers_image_spec//specs-go/v1:go_default_library",
5045
"@com_github_smartystreets_goconvey//convey:go_default_library",
5146
"@in_gopkg_resty_v1//:go_default_library",
5247
],

pkg/api/routes.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ import (
2828
httpSwagger "github.com/swaggo/http-swagger"
2929
)
3030

31-
const RoutePrefix = "/v2"
32-
const DistAPIVersion = "Docker-Distribution-API-Version"
33-
const DistContentDigestKey = "Docker-Content-Digest"
34-
const BlobUploadUUID = "Blob-Upload-UUID"
31+
const (
32+
RoutePrefix = "/v2"
33+
DistAPIVersion = "Docker-Distribution-API-Version"
34+
DistContentDigestKey = "Docker-Content-Digest"
35+
BlobUploadUUID = "Blob-Upload-UUID"
36+
DefaultMediaType = "application/json"
37+
)
3538

3639
type RouteHandler struct {
3740
c *Controller
@@ -823,7 +826,7 @@ func WriteJSON(w http.ResponseWriter, status int, data interface{}) {
823826
if err != nil {
824827
w.WriteHeader(http.StatusInternalServerError)
825828
}
826-
WriteData(w, status, "application/json; charset=utf-8", body)
829+
WriteData(w, status, DefaultMediaType, body)
827830
}
828831

829832
func WriteData(w http.ResponseWriter, status int, mediaType string, data []byte) {

pkg/cli/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ go_library(
88
deps = [
99
"//errors:go_default_library",
1010
"//pkg/api:go_default_library",
11+
"//pkg/compliance:go_default_library",
12+
"//pkg/compliance/v1_0_0:go_default_library",
1113
"//pkg/storage:go_default_library",
1214
"@com_github_mitchellh_mapstructure//:go_default_library",
1315
"@com_github_opencontainers_distribution_spec//:go_default_library",

pkg/cli/root.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package cli
22

33
import (
4+
"testing"
5+
46
"github.com/anuvu/zot/errors"
57
"github.com/anuvu/zot/pkg/api"
8+
"github.com/anuvu/zot/pkg/compliance"
69
"github.com/anuvu/zot/pkg/storage"
710
"github.com/mitchellh/mapstructure"
811
dspec "github.com/opencontainers/distribution-spec"
912
"github.com/rs/zerolog/log"
1013
"github.com/spf13/cobra"
1114
"github.com/spf13/viper"
15+
16+
"github.com/anuvu/zot/pkg/compliance/v1_0_0"
1217
)
1318

1419
// metadataConfig reports metadata after parsing, which we use to track
@@ -23,6 +28,7 @@ func NewRootCmd() *cobra.Command {
2328
showVersion := false
2429
config := api.NewConfig()
2530

31+
// "serve"
2632
serveCmd := &cobra.Command{
2733
Use: "serve <config>",
2834
Aliases: []string{"serve"},
@@ -53,6 +59,7 @@ func NewRootCmd() *cobra.Command {
5359
},
5460
}
5561

62+
// "garbage-collect"
5663
gcDelUntagged := false
5764
gcDryRun := false
5865

@@ -79,6 +86,37 @@ func NewRootCmd() *cobra.Command {
7986
gcCmd.Flags().BoolVarP(&gcDryRun, "dry-run", "d", false,
8087
"do everything except remove the blobs")
8188

89+
// "compliance"
90+
complianceConfig := compliance.NewConfig()
91+
complianceCmd := &cobra.Command{
92+
Use: "compliance",
93+
Aliases: []string{"co"},
94+
Short: "`compliance` checks compliance with respect to OCI distribution-spec",
95+
Long: "`compliance` checks compliance with respect to OCI distribution-spec",
96+
Run: func(cmd *cobra.Command, args []string) {
97+
t := &testing.T{}
98+
switch complianceConfig.Version {
99+
case "all":
100+
fallthrough
101+
default:
102+
v1_0_0.CheckWorkflows(t, complianceConfig)
103+
}
104+
},
105+
}
106+
107+
complianceCmd.Flags().StringVarP(&complianceConfig.Address, "address", "H", "",
108+
"Registry server address")
109+
if err := complianceCmd.MarkFlagRequired("address"); err != nil {
110+
panic(err)
111+
}
112+
complianceCmd.Flags().StringVarP(&complianceConfig.Port, "port", "P", "",
113+
"Registry server port")
114+
if err := complianceCmd.MarkFlagRequired("port"); err != nil {
115+
panic(err)
116+
}
117+
complianceCmd.Flags().StringVarP(&complianceConfig.Version, "version", "V", "all",
118+
"OCI dist-spec version to check")
119+
82120
rootCmd := &cobra.Command{
83121
Use: "zot",
84122
Short: "`zot`",
@@ -93,6 +131,7 @@ func NewRootCmd() *cobra.Command {
93131

94132
rootCmd.AddCommand(serveCmd)
95133
rootCmd.AddCommand(gcCmd)
134+
rootCmd.AddCommand(complianceCmd)
96135
rootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "show the version and exit")
97136

98137
return rootCmd

pkg/compliance/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["config.go"],
6+
importpath = "github.com/anuvu/zot/pkg/compliance",
7+
visibility = ["//visibility:public"],
8+
)

pkg/compliance/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package compliance
2+
3+
type Config struct {
4+
Address string
5+
Port string
6+
Version string
7+
}
8+
9+
func NewConfig() *Config {
10+
return &Config{}
11+
}

pkg/compliance/v1_0_0/BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["check.go"],
6+
importpath = "github.com/anuvu/zot/pkg/compliance/v1_0_0",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/api:go_default_library",
10+
"//pkg/compliance:go_default_library",
11+
"@com_github_opencontainers_go_digest//:go_default_library",
12+
"@com_github_opencontainers_image_spec//specs-go/v1:go_default_library",
13+
"@com_github_smartystreets_goconvey//convey:go_default_library",
14+
"@in_gopkg_resty_v1//:go_default_library",
15+
],
16+
)
17+
18+
go_test(
19+
name = "go_default_test",
20+
timeout = "short",
21+
srcs = ["check_test.go"],
22+
embed = [":go_default_library"],
23+
deps = [
24+
"//pkg/api:go_default_library",
25+
"//pkg/compliance:go_default_library",
26+
"@in_gopkg_resty_v1//:go_default_library",
27+
],
28+
)

0 commit comments

Comments
 (0)