Skip to content

Commit

Permalink
makefile: add rule to download and set swagger and make rule to build…
Browse files Browse the repository at this point in the history
… the dist (#154)

Signed-off-by: Carlos Panato <ctadeu@gmail.com>
  • Loading branch information
cpanato authored Jul 28, 2021
1 parent 485846c commit ea8e5a3
Show file tree
Hide file tree
Showing 8 changed files with 903 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "./hack/tools"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ jobs:
with:
go-version: ${{ env.GOVERSION }}

- name: download go-swagger
run : go install github.com/go-swagger/go-swagger/cmd/swagger@v0.27.0
- name: Validate OpenAPI with Swagger
run: swagger validate openapi.yaml
run: make validate-openapi

- name: Build
run: make -C $GITHUB_WORKSPACE all
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# Dependency directories (remove the comment below to include it)
# vendor/
dist/*
hack/tools/bin

# IDE Specifics
# intellij
Expand All @@ -30,3 +32,4 @@
/client
/server
/fulcio

44 changes: 42 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
.PHONY: all test clean lint gosec

all: fulcio
# Ensure Make is run with bash shell as some syntax below is bash-specific
SHELL:=/usr/bin/env bash

GENSRC = pkg/generated/models/%.go pkg/generated/restapi/%.go
OPENAPIDEPS = openapi.yaml
SRCS = $(shell find cmd -iname "*.go") $(shell find pkg -iname "*.go"|grep -v pkg/generated) pkg/generated/restapi/configure_fulcio_server.go $(GENSRC)
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
BIN_DIR := $(abspath $(ROOT_DIR)/bin)

$(GENSRC): $(OPENAPIDEPS)
swagger generate server -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --exclude-main -A fulcio_server --exclude-spec --flag-strategy=pflag -P github.com/coreos/go-oidc/v3/oidc.IDToken
# Binaries
SWAGGER := $(TOOLS_BIN_DIR)/swagger

$(GENSRC): $(SWAGGER) $(OPENAPIDEPS)
$(SWAGGER) generate server -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --exclude-main -A fulcio_server --exclude-spec --flag-strategy=pflag -P github.com/coreos/go-oidc/v3/oidc.IDToken

# this exists to override pattern match rule above since this file is in the generated directory but should not be treated as generated code
pkg/generated/restapi/configure_fulcio_server.go: $(OPENAPIDEPS)
Expand All @@ -41,6 +49,8 @@ test:
go test ./...

clean:
rm -rf dist
rm -rf hack/tools/bin
rm -rf fulcio

up:
Expand All @@ -50,3 +60,33 @@ up:
debug:
docker-compose -f docker-compose.yml -f docker-compose.debug.yml build fulcio-server-debug
docker-compose -f docker-compose.yml -f docker-compose.debug.yml up fulcio-server-debug


.PHONY: validate-openapi
validate-openapi: $(SWAGGER)
$(SWAGGER) validate openapi.yaml

## --------------------------------------
## Modules
## --------------------------------------

.PHONY: modules
modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
cd $(TOOLS_DIR); go mod tidy

# --------------------------------------
## Release
## --------------------------------------

.PHONY: dist
dist:
mkdir -p dist
docker run -it -v $(PWD):/go/src/sigstore/fulcio -w /go/src/sigstore/fulcio golang:1.16.6 /bin/bash -c "GOOS=linux GOARCH=amd64 go build -o dist/fulcio-server-linux-amd64"

## --------------------------------------
## Tooling Binaries
## --------------------------------------

$(SWAGGER): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); go build -tags=tools -o $(TOOLS_BIN_DIR)/swagger github.com/go-swagger/go-swagger/cmd/swagger
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ We **WILL** change this and add intermediaries in the future.
After cloning the repository:

```
$ go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.26.1
$ make
```

Expand Down Expand Up @@ -94,7 +93,7 @@ log.level = INFO
Export the `config/softhsm2.conf`

```
export SOFTHSM2_CONF=`pwd`/config/softhsm2.cfg
export SOFTHSM2_CONF=`pwd`/config/softhsm2.cfg
```

### Start a SoftHSM instance
Expand Down
5 changes: 5 additions & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/sigstore/fulcio/hack/tools

go 1.16

require github.com/go-swagger/go-swagger v0.27.0
824 changes: 824 additions & 0 deletions hack/tools/go.sum

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build tools

// Copyright 2021 The Sigstore 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.
//

// This package imports things required by build scripts, to force `go mod` to see them as dependencies
package tools

import (
_ "github.com/go-swagger/go-swagger/cmd/swagger"
)

0 comments on commit ea8e5a3

Please sign in to comment.