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

Signed-off-by: Carlos Panato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Jul 28, 2021
1 parent c86b377 commit c8b8dd3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
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/*

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

37 changes: 35 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ all: fulcio
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)
GO_INSTALL = ./scripts/go_install.sh

$(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_VER := v0.27.0
SWAGGER_BIN := swagger
SWAGGER := $(TOOLS_BIN_DIR)/$(SWAGGER_BIN)-$(SWAGGER_VER)


$(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 +51,8 @@ test:
go test ./...

clean:
rm -rf dist
rm -rf hack
rm -rf fulcio

up:
Expand All @@ -50,3 +62,24 @@ 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

# --------------------------------------
## 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): ## Build swagger from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/go-swagger/go-swagger/cmd/swagger $(SWAGGER_BIN) $(SWAGGER_VER)
1 change: 0 additions & 1 deletion 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
56 changes: 56 additions & 0 deletions scripts/go_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# 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.

set -o errexit
set -o nounset
set -o pipefail

if [ -z "${1}" ]; then
echo "must provide module as first parameter"
exit 1
fi

if [ -z "${2}" ]; then
echo "must provide binary name as second parameter"
exit 1
fi

if [ -z "${3}" ]; then
echo "must provide version as third parameter"
exit 1
fi

if [ -z "${GOBIN}" ]; then
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
exit 1
fi

tmp_dir=$(mktemp -d -t goinstall_XXXXXXXXXX)
function clean {
rm -rf "${tmp_dir}"
}
trap clean EXIT

rm "${GOBIN}/${2}"* || true

cd "${tmp_dir}"

# create a new module in the tmp directory
go mod init fake/mod

# install the golang module specified as the first argument
go get -tags tools "${1}@${3}"
mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}"
ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"

0 comments on commit c8b8dd3

Please sign in to comment.