[#46] Add building in docker

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-08-12 12:17:46 +03:00 committed by Kirillov Denis
parent 97c8942684
commit afdc062723
2 changed files with 73 additions and 12 deletions

View file

@ -3,11 +3,12 @@
REPO ?= "$(shell go list -m)"
VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")"
GO_VERSION ?= 1.17
LINT_VERSION ?= v1.46.2
HUB_IMAGE ?= nspccdev/neofs-rest-gw
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
DOCKER_LIST_VERSION ?= v1.42
SWAGGER_VERSION ?= v0.29.0
UNAME = "$(shell uname)/$(shell uname -m)"
@ -20,8 +21,7 @@ ifeq ($(UNAME), "Darwin/x86_64")
SWAGGER_ARCH = darwin_amd64
endif
SWAGGER_URL = "$(shell curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/tags/$(SWAGGER_VERSION) | \
jq -r '.assets[] | select(.name | contains("swagger_$(SWAGGER_ARCH)")) | .browser_download_url')"
SWAGGER_URL = "https://github.com/go-swagger/go-swagger/releases/download/$(SWAGGER_VERSION)/swagger_$(SWAGGER_ARCH)"
# List of binaries to build. For now just one.
BINDIR = bin
@ -58,9 +58,6 @@ swagger:
ifeq (,$(wildcard ./bin/swagger))
curl --create-dirs -o ./bin/swagger -L'#' $(SWAGGER_URL)
chmod +x ./bin/swagger
# curl --create-dirs -o ./bin/swagger $(SWAGGER_URL)
# chmod +x ./bin/swagger
endif
# Generate server by swagger spec
@ -114,13 +111,35 @@ image-dirty:
lint:
@golangci-lint --timeout=5m run
# Make all binaries in clean docker environment
docker/all:
@echo "=> Running 'make all' in clean Docker environment" && \
docker run --rm -t \
-v `pwd`:/src \
-w /src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
golang:$(GO_VERSION) make all
# Generate server by swagger spec using swagger docker image
docker/generate-server:
@docker run --rm -t \
-v `pwd`:/src \
-w /src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
quay.io/goswagger/swagger:$(SWAGGER_VERSION) generate server \
-t gen -f ./spec/rest.yaml --exclude-main \
-A neofs-rest-gw -P models.Principal \
-C templates/server-config.yaml --template-dir templates
# Run linters in Docker
docker-lint:
docker/lint:
docker run --rm -it \
-v `pwd`:/src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
golangci/golangci-lint:$(DOCKER_LINT_VERSION) bash -c 'cd /src/ && make lint'
golangci/golangci-lint:$(LINT_VERSION) bash -c 'cd /src/ && make lint'
# Print version
version:
@ -138,5 +157,5 @@ help:
# Clean up
clean:
rm -rf vendor
rm -rf .cache
rm -rf $(BINDIR)

View file

@ -22,11 +22,53 @@ Before building make sure you have the following tools:
* go
* make
* jq
* git
* curl
* docker
To build neofs-rest-gw call `make` the cloned repository (the binary will end up in `bin/neofs-rest-gw`).
First clone this repository:
```shell
$ git clone https://github.com/nspcc-dev/neofs-rest-gw
```
Then run make to build `bin/neofs-rest-gw` binary:
```shell
$ make
```
Or you can build it using docker:
```shell
$ make docker/all
```
#### Generate go-swagger boilerplate code
If you change the [spec file](./spec/rest.yaml) you have to re-generate go-swagger server code.
You have several approaches:
1. Run make. It automatically downloads `swagger` and generates boilerplate.
```shell
$ make
```
2. Generate code separately:
```shell
$ make generate-server
```
Or using docker:
```shell
$ make docker/generate-server
```
#### Other targets
Notable make targets: