[#46] Add building in docker
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
97c8942684
commit
afdc062723
2 changed files with 73 additions and 12 deletions
39
Makefile
39
Makefile
|
@ -3,11 +3,12 @@
|
||||||
REPO ?= "$(shell go list -m)"
|
REPO ?= "$(shell go list -m)"
|
||||||
VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")"
|
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_IMAGE ?= nspccdev/neofs-rest-gw
|
||||||
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
||||||
|
|
||||||
DOCKER_LIST_VERSION ?= v1.42
|
|
||||||
|
|
||||||
SWAGGER_VERSION ?= v0.29.0
|
SWAGGER_VERSION ?= v0.29.0
|
||||||
|
|
||||||
UNAME = "$(shell uname)/$(shell uname -m)"
|
UNAME = "$(shell uname)/$(shell uname -m)"
|
||||||
|
@ -20,8 +21,7 @@ ifeq ($(UNAME), "Darwin/x86_64")
|
||||||
SWAGGER_ARCH = darwin_amd64
|
SWAGGER_ARCH = darwin_amd64
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SWAGGER_URL = "$(shell curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/tags/$(SWAGGER_VERSION) | \
|
SWAGGER_URL = "https://github.com/go-swagger/go-swagger/releases/download/$(SWAGGER_VERSION)/swagger_$(SWAGGER_ARCH)"
|
||||||
jq -r '.assets[] | select(.name | contains("swagger_$(SWAGGER_ARCH)")) | .browser_download_url')"
|
|
||||||
|
|
||||||
# List of binaries to build. For now just one.
|
# List of binaries to build. For now just one.
|
||||||
BINDIR = bin
|
BINDIR = bin
|
||||||
|
@ -58,9 +58,6 @@ swagger:
|
||||||
ifeq (,$(wildcard ./bin/swagger))
|
ifeq (,$(wildcard ./bin/swagger))
|
||||||
curl --create-dirs -o ./bin/swagger -L'#' $(SWAGGER_URL)
|
curl --create-dirs -o ./bin/swagger -L'#' $(SWAGGER_URL)
|
||||||
chmod +x ./bin/swagger
|
chmod +x ./bin/swagger
|
||||||
|
|
||||||
# curl --create-dirs -o ./bin/swagger $(SWAGGER_URL)
|
|
||||||
# chmod +x ./bin/swagger
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Generate server by swagger spec
|
# Generate server by swagger spec
|
||||||
|
@ -114,13 +111,35 @@ image-dirty:
|
||||||
lint:
|
lint:
|
||||||
@golangci-lint --timeout=5m run
|
@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
|
# Run linters in Docker
|
||||||
docker-lint:
|
docker/lint:
|
||||||
docker run --rm -it \
|
docker run --rm -it \
|
||||||
-v `pwd`:/src \
|
-v `pwd`:/src \
|
||||||
-u `stat -c "%u:%g" .` \
|
-u `stat -c "%u:%g" .` \
|
||||||
--env HOME=/src \
|
--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
|
# Print version
|
||||||
version:
|
version:
|
||||||
|
@ -138,5 +157,5 @@ help:
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
clean:
|
clean:
|
||||||
rm -rf vendor
|
rm -rf .cache
|
||||||
rm -rf $(BINDIR)
|
rm -rf $(BINDIR)
|
||||||
|
|
46
README.md
46
README.md
|
@ -22,11 +22,53 @@ Before building make sure you have the following tools:
|
||||||
|
|
||||||
* go
|
* go
|
||||||
* make
|
* make
|
||||||
* jq
|
|
||||||
* git
|
* git
|
||||||
* curl
|
* 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:
|
Notable make targets:
|
||||||
|
|
||||||
|
|
Reference in a new issue