Skip to content

Commit

Permalink
refactor: move httpserver folder
Browse files Browse the repository at this point in the history
Signed-off-by: Binbin Li <[email protected]>
  • Loading branch information
binbin-li committed Nov 13, 2024
1 parent 997de25 commit bc677a6
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-dev-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: docker build ratify base
run: |
docker buildx create --use
docker buildx build -f ./httpserver/Dockerfile \
docker buildx build -f ./Dockerfile \
--attest type=sbom \
--attest type=provenance,mode=max \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
Expand All @@ -91,7 +91,7 @@ jobs:
- name: docker build ratify with plugin
run: |
docker buildx create --use
docker buildx build -f ./httpserver/Dockerfile \
docker buildx build -f ./Dockerfile \
--attest type=sbom \
--attest type=provenance,mode=max \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: docker build ratify base
run: |
docker buildx create --use
docker buildx build -f ./httpserver/Dockerfile \
docker buildx build -f ./Dockerfile \
--attest type=sbom \
--attest type=provenance,mode=max \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
Expand All @@ -71,7 +71,7 @@ jobs:
- name: docker build ratify with plugin
run: |
docker buildx create --use
docker buildx build -f ./httpserver/Dockerfile \
docker buildx build -f ./Dockerfile \
--attest type=sbom \
--attest type=provenance,mode=max \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Follow the steps below to build and deploy a Ratify image with your private chan
export REGISTRY=yourregistry
docker buildx create --use

docker buildx build -f httpserver/Dockerfile --platform linux/amd64 --build-arg build_sbom=true --build-arg build_licensechecker=true --build-arg build_schemavalidator=true --build-arg build_vulnerabilityreport=true -t ${REGISTRY}/ratify-project/ratify:yourtag .
docker buildx build -f Dockerfile --platform linux/amd64 --build-arg build_sbom=true --build-arg build_licensechecker=true --build-arg build_schemavalidator=true --build-arg build_vulnerabilityreport=true -t ${REGISTRY}/ratify-project/ratify:yourtag .
docker build --progress=plain --build-arg KUBE_VERSION="1.29.2" --build-arg TARGETOS="linux" --build-arg TARGETARCH="amd64" -f crd.Dockerfile -t ${REGISTRY}/localbuildcrd:yourtag ./charts/ratify/crds
```

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ e2e-deploy-ratify: e2e-notation-setup e2e-notation-leaf-cert-setup e2e-cosign-se

e2e-build-local-ratify-base-image:
docker build --progress=plain --no-cache \
-f ./httpserver/Dockerfile \
-f ./Dockerfile \
-t baselocalbuild:test .
kind load docker-image --name kind baselocalbuild:test

Expand All @@ -574,7 +574,7 @@ e2e-build-local-ratify-image:
--build-arg build_licensechecker=true \
--build-arg build_schemavalidator=true \
--build-arg build_vulnerabilityreport=true \
-f ./httpserver/Dockerfile \
-f ./Dockerfile \
-t localbuild:test .

load-local-ratify-image:
Expand Down
5 changes: 2 additions & 3 deletions charts/ratify/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ spec:
seccompProfile:
type: RuntimeDefault
command:
- "/app/ratify"
- "/app/ratifymain"
args:
- "serve"
- "--http"
- ":6001"
- "-c"
- "--config"
- "/usr/local/ratify/config.json"
- "--enable-crd-manager"
- --cert-dir=/usr/local/tls
Expand Down
2 changes: 1 addition & 1 deletion scripts/azure-ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ REGISTRY="${ACR_NAME}.azurecr.io"

build_push_to_acr() {
echo "Building and pushing images to ACR"
docker build --progress=plain --no-cache --build-arg build_sbom=true --build-arg build_licensechecker=true --build-arg build_schemavalidator=true --build-arg build_vulnerabilityreport=true -f ./httpserver/Dockerfile -t "${ACR_NAME}.azurecr.io/test/localbuild:${TAG}" .
docker build --progress=plain --no-cache --build-arg build_sbom=true --build-arg build_licensechecker=true --build-arg build_schemavalidator=true --build-arg build_vulnerabilityreport=true -f ./Dockerfile -t "${ACR_NAME}.azurecr.io/test/localbuild:${TAG}" .
docker push "${REGISTRY}/test/localbuild:${TAG}"

docker build --progress=plain --no-cache --build-arg KUBE_VERSION=${KUBERNETES_VERSION} --build-arg TARGETOS="linux" --build-arg TARGETARCH="amd64" -f crd.Dockerfile -t "${ACR_NAME}.azurecr.io/test/localbuildcrd:${TAG}" ./charts/ratify/crds
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/manager/manager.go → server/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
"github.com/open-policy-agent/cert-controller/pkg/rotator"
"github.com/ratify-project/ratify/config"
"github.com/ratify-project/ratify/httpserver"
"github.com/ratify-project/ratify/server/httpserver"
"github.com/ratify-project/ratify/pkg/featureflag"
_ "github.com/ratify-project/ratify/pkg/policyprovider/configpolicy" // register config policy provider
_ "github.com/ratify-project/ratify/pkg/policyprovider/regopolicy" // register rego policy provider
Expand Down
67 changes: 67 additions & 0 deletions server/ratifymain/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright The Ratify 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 ratifymain

import (
"flag"
"fmt"
"time"

"github.com/ratify-project/ratify/server/httpserver"
"github.com/ratify-project/ratify/pkg/cache"
"github.com/sirupsen/logrus"
)

// options defines the command line options to start the ratify server.
type options struct {
configFilePath string
httpServerAddress string
certDirectory string
caCertFile string
enableCrdManager bool
cacheEnabled bool
cacheType string
cacheName string
cacheSize int
cacheTTL time.Duration
metricsEnabled bool
metricsType string
metricsPort int
healthPort string
}

// parse parses the command line arguments and returns the options.
func parse() *options {
opts := options{}
flag.StringVar(&opts.httpServerAddress, "http", "", "HTTP Address")
flag.StringVar(&opts.configFilePath, "config", "", "Config File Path")
flag.StringVar(&opts.certDirectory, "cert-dir", "", "Path to ratify certs")
flag.StringVar(&opts.caCertFile, "ca-cert-file", "", "Path to CA cert file")
flag.BoolVar(&opts.enableCrdManager, "enable-crd-manager", false, "Start crd manager if enabled (default: false)")
flag.BoolVar(&opts.cacheEnabled, "cache-enabled", false, "Enable cache if enabled (default: false)")
flag.StringVar(&opts.cacheType, "cache-type", cache.DefaultCacheType, fmt.Sprintf("Cache type to use (default: %s)", cache.DefaultCacheType))
flag.StringVar(&opts.cacheName, "cache-name", cache.DefaultCacheName, fmt.Sprintf("Cache implementation name to use (default: %s)", cache.DefaultCacheName))
flag.IntVar(&opts.cacheSize, "cache-size", cache.DefaultCacheSize, fmt.Sprintf("Cache max size to use in MB (default: %d)", cache.DefaultCacheSize))
flag.DurationVar(&opts.cacheTTL, "cache-ttl", cache.DefaultCacheTTL, fmt.Sprintf("Cache TTL for the verifier http server (default: %fs)", cache.DefaultCacheTTL.Seconds()))
flag.BoolVar(&opts.metricsEnabled, "metrics-enabled", false, "Enable metrics exporter if enabled (default: false)")
flag.StringVar(&opts.metricsType, "metrics-type", httpserver.DefaultMetricsType, fmt.Sprintf("Metrics exporter type to use (default: %s)", httpserver.DefaultMetricsType))
flag.IntVar(&opts.metricsPort, "metrics-port", httpserver.DefaultMetricsPort, fmt.Sprintf("Metrics exporter port to use (default: %d)", httpserver.DefaultMetricsPort))
flag.StringVar(&opts.healthPort, "health-port", httpserver.DefaultHealthPort, fmt.Sprintf("Health port to use (default: %s)", httpserver.DefaultHealthPort))
flag.Parse()

logrus.Infof("Starting Ratify: %+v", opts)
return &opts
}
47 changes: 2 additions & 45 deletions server/ratifymain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ package ratifymain

import (
"context"
"flag"
"fmt"
"time"

"github.com/ratify-project/ratify/config"
"github.com/ratify-project/ratify/httpserver"
"github.com/ratify-project/ratify/internal/logger"
"github.com/ratify-project/ratify/pkg/cache"
"github.com/ratify-project/ratify/pkg/manager"
"github.com/ratify-project/ratify/server/httpserver"
"github.com/ratify-project/ratify/server/manager"
"github.com/sirupsen/logrus"

_ "github.com/ratify-project/ratify/pkg/cache/dapr" // register dapr cache
Expand All @@ -37,54 +35,13 @@ import (
_ "github.com/ratify-project/ratify/pkg/verifier/notation" // register notation verifier
)

// options defines the command line options to start the ratify server.
type options struct {
configFilePath string
httpServerAddress string
certDirectory string
caCertFile string
enableCrdManager bool
cacheEnabled bool
cacheType string
cacheName string
cacheSize int
cacheTTL time.Duration
metricsEnabled bool
metricsType string
metricsPort int
healthPort string
}

func Main() {
opts := parse()
if err := startRatify(opts); err != nil {
logrus.Errorf("Error starting Ratify: %v", err)
}
}

// parse parses the command line arguments and returns the options.
func parse() *options {
opts := options{}
flag.StringVar(&opts.httpServerAddress, "http", "", "HTTP Address")
flag.StringVar(&opts.configFilePath, "config", "", "Config File Path")
flag.StringVar(&opts.certDirectory, "cert-dir", "", "Path to ratify certs")
flag.StringVar(&opts.caCertFile, "ca-cert-file", "", "Path to CA cert file")
flag.BoolVar(&opts.enableCrdManager, "enable-crd-manager", false, "Start crd manager if enabled (default: false)")
flag.BoolVar(&opts.cacheEnabled, "cache-enabled", false, "Enable cache if enabled (default: false)")
flag.StringVar(&opts.cacheType, "cache-type", cache.DefaultCacheType, fmt.Sprintf("Cache type to use (default: %s)", cache.DefaultCacheType))
flag.StringVar(&opts.cacheName, "cache-name", cache.DefaultCacheName, fmt.Sprintf("Cache implementation name to use (default: %s)", cache.DefaultCacheName))
flag.IntVar(&opts.cacheSize, "cache-size", cache.DefaultCacheSize, fmt.Sprintf("Cache max size to use in MB (default: %d)", cache.DefaultCacheSize))
flag.DurationVar(&opts.cacheTTL, "cache-ttl", cache.DefaultCacheTTL, fmt.Sprintf("Cache TTL for the verifier http server (default: %fs)", cache.DefaultCacheTTL.Seconds()))
flag.BoolVar(&opts.metricsEnabled, "metrics-enabled", false, "Enable metrics exporter if enabled (default: false)")
flag.StringVar(&opts.metricsType, "metrics-type", httpserver.DefaultMetricsType, fmt.Sprintf("Metrics exporter type to use (default: %s)", httpserver.DefaultMetricsType))
flag.IntVar(&opts.metricsPort, "metrics-port", httpserver.DefaultMetricsPort, fmt.Sprintf("Metrics exporter port to use (default: %d)", httpserver.DefaultMetricsPort))
flag.StringVar(&opts.healthPort, "health-port", httpserver.DefaultHealthPort, fmt.Sprintf("Health port to use (default: %s)", httpserver.DefaultHealthPort))
flag.Parse()

logrus.Infof("Starting Ratify: %+v", opts)
return &opts
}

// startRatify starts the ratify server.
func startRatify(opts *options) error {
if opts.cacheEnabled {
Expand Down

0 comments on commit bc677a6

Please sign in to comment.