From c8b8dd3a48ab1ec29dffa515a5e4543b1f4efa8d Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Wed, 28 Jul 2021 14:05:14 +0200 Subject: [PATCH] makefile: add rule to download and set swagger and make rule to build the dist Signed-off-by: Carlos Panato --- .github/workflows/main.yml | 4 +-- .gitignore | 3 ++ Makefile | 37 +++++++++++++++++++++++-- README.md | 1 - scripts/go_install.sh | 56 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 6 deletions(-) create mode 100755 scripts/go_install.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76facd41a..60c7d1200 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.gitignore b/.gitignore index 37154dced..fbbd48312 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ # Dependency directories (remove the comment below to include it) # vendor/ +dist/* +hack/* # IDE Specifics # intellij @@ -30,3 +32,4 @@ /client /server /fulcio + diff --git a/Makefile b/Makefile index 7abf0cb7e..400e792c3 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -41,6 +51,8 @@ test: go test ./... clean: + rm -rf dist + rm -rf hack rm -rf fulcio up: @@ -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) diff --git a/README.md b/README.md index cbf3e1f96..c0b45b706 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/scripts/go_install.sh b/scripts/go_install.sh new file mode 100755 index 000000000..c0c9570c6 --- /dev/null +++ b/scripts/go_install.sh @@ -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}"