forked from TrueCloudLab/frostfs-http-gw
Clean up Makefile and image build
Signed-off-by: Stanislav Bogatyrev <stanislav@nspcc.ru>
This commit is contained in:
parent
e3dbecf844
commit
b2e7a2cb61
8 changed files with 173 additions and 98 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
||||||
|
.idea
|
||||||
bin
|
bin
|
||||||
temp
|
temp
|
||||||
cmd/test
|
|
||||||
/plugins/
|
/plugins/
|
||||||
/vendor/
|
/vendor/
|
||||||
|
|
||||||
|
@ -10,3 +10,5 @@ test.sh
|
||||||
testfile
|
testfile
|
||||||
.blast.yml
|
.blast.yml
|
||||||
.neofs-cli.yml
|
.neofs-cli.yml
|
||||||
|
|
||||||
|
.cache
|
||||||
|
|
47
.golangci.yml
Normal file
47
.golangci.yml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# This file contains all available configuration options
|
||||||
|
# with their default values.
|
||||||
|
|
||||||
|
# options for analysis running
|
||||||
|
run:
|
||||||
|
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||||
|
timeout: 5m
|
||||||
|
|
||||||
|
# include test files or not, default is true
|
||||||
|
tests: false
|
||||||
|
|
||||||
|
# output configuration options
|
||||||
|
output:
|
||||||
|
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
|
||||||
|
format: tab
|
||||||
|
|
||||||
|
# all available settings of specific linters
|
||||||
|
linters-settings:
|
||||||
|
exhaustive:
|
||||||
|
# indicates that switch statements are to be considered exhaustive if a
|
||||||
|
# 'default' case is present, even if all enum members aren't listed in the
|
||||||
|
# switch
|
||||||
|
default-signifies-exhaustive: true
|
||||||
|
govet:
|
||||||
|
# report about shadowed variables
|
||||||
|
check-shadowing: false
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
# mandatory linters
|
||||||
|
- govet
|
||||||
|
- golint
|
||||||
|
|
||||||
|
# some default golangci-lint linters
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- typecheck
|
||||||
|
|
||||||
|
# extra linters
|
||||||
|
- exhaustive
|
||||||
|
- gofmt
|
||||||
|
- whitespace
|
||||||
|
- goimports
|
||||||
|
disable-all: true
|
||||||
|
fast: false
|
28
Dockerfile
28
Dockerfile
|
@ -1,33 +1,23 @@
|
||||||
FROM golang:1 as builder
|
FROM golang:1.16-alpine as basebuilder
|
||||||
|
RUN apk add --update make bash ca-certificates
|
||||||
|
|
||||||
|
FROM basebuilder as builder
|
||||||
ENV GOGC off
|
ENV GOGC off
|
||||||
ENV CGO_ENABLED 0
|
ENV CGO_ENABLED 0
|
||||||
|
ARG BUILD=now
|
||||||
RUN set -x \
|
ARG VERSION=dev
|
||||||
&& apt update \
|
ARG REPO=repository
|
||||||
&& apt install -y upx-ucl
|
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY . /src
|
COPY . /src
|
||||||
|
|
||||||
ARG VERSION=dev
|
RUN make
|
||||||
ENV LDFLAGS "-w -s -X main.Version=${VERSION}"
|
|
||||||
RUN set -x \
|
|
||||||
&& go build \
|
|
||||||
-v \
|
|
||||||
-mod=vendor \
|
|
||||||
-trimpath \
|
|
||||||
-ldflags "${LDFLAGS} -X main.Build=$(date -u +%s%N)" \
|
|
||||||
-o /go/bin/neofs-gw ./ \
|
|
||||||
&& upx -3 /go/bin/neofs-gw
|
|
||||||
|
|
||||||
# Executable image
|
# Executable image
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
COPY --from=builder /go/bin/neofs-gw /bin/neofs-gw
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
COPY --from=builder /src/bin/neofs-http-gw /bin/neofs-http-gw
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/neofs-gw"]
|
ENTRYPOINT ["/bin/neofs-http-gw"]
|
||||||
|
|
8
Dockerfile.dirty
Normal file
8
Dockerfile.dirty
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
FROM alpine
|
||||||
|
RUN apk add --update --no-cache bash ca-certificates
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
COPY bin/neofs-http-gw /bin/neofs-http-gw
|
||||||
|
|
||||||
|
CMD ["neofs-http-gw"]
|
143
Makefile
143
Makefile
|
@ -1,63 +1,108 @@
|
||||||
-include .env
|
#!/usr/bin/make -f
|
||||||
-include help.mk
|
|
||||||
|
|
||||||
VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')"
|
REPO ?= $(shell go list -m)
|
||||||
|
VERSION ?= $(shell git describe --tags --dirty --always)
|
||||||
|
BUILD ?= $(shell date -u --iso=seconds)
|
||||||
|
DEBUG ?= false
|
||||||
|
|
||||||
GRPC_VERSION=$(shell go list -m google.golang.org/grpc | cut -d " " -f 2)
|
HUB_IMAGE ?= nspccdev/neofs-http-gw
|
||||||
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
||||||
|
|
||||||
HUB_IMAGE=nspccdev/neofs
|
# List of binaries to build. For now just one.
|
||||||
|
BINDIR = bin
|
||||||
|
DIRS = $(BINDIR)
|
||||||
|
BINS = "$(BINDIR)/neofs-http-gw"
|
||||||
|
|
||||||
B=\033[0;1m
|
.PHONY: help all dep clean fmts fmt imports test lint docker/lint
|
||||||
G=\033[0;92m
|
|
||||||
R=\033[0m
|
|
||||||
|
|
||||||
.PHONY: version deps image publish
|
# Make all binaries
|
||||||
|
all: $(BINS)
|
||||||
|
|
||||||
# Show current version
|
$(BINS): $(DIRS) dep
|
||||||
version:
|
@echo "⇒ Build $@"
|
||||||
@echo "Current version: $(VERSION)-$(GRPC_VERSION)"
|
CGO_ENABLED=0 \
|
||||||
|
GO111MODULE=on \
|
||||||
|
go build -v -trimpath \
|
||||||
|
-ldflags "-X main.Version=$(VERSION) \
|
||||||
|
-X main.Build=$(BUILD) \
|
||||||
|
-X main.Debug=$(DEBUG)" \
|
||||||
|
-o $@ ./
|
||||||
|
|
||||||
# Check and ensure dependencies
|
$(DIRS):
|
||||||
deps:
|
@echo "⇒ Ensure dir: $@"
|
||||||
@printf "${B}${G}⇒ Ensure vendor${R}: "
|
@mkdir -p $@
|
||||||
@go mod tidy -v && echo OK || (echo fail && exit 2)
|
|
||||||
@printf "${B}${G}⇒ Download requirements${R}: "
|
|
||||||
@go mod download && echo OK || (echo fail && exit 2)
|
|
||||||
@printf "${B}${G}⇒ Store vendor localy${R}: "
|
|
||||||
@go mod vendor && echo OK || (echo fail && exit 2)
|
|
||||||
|
|
||||||
# Build docker image
|
# Pull go dependencies
|
||||||
image: VERSION?=
|
dep:
|
||||||
image: deps
|
@printf "⇒ Download requirements: "
|
||||||
@echo "${B}${G}⇒ Build GW docker-image with $(GRPC_VERSION) ${R}"
|
@CGO_ENABLED=0 \
|
||||||
|
GO111MODULE=on \
|
||||||
|
go mod download && echo OK
|
||||||
|
@printf "⇒ Tidy requirements: "
|
||||||
|
@CGO_ENABLED=0 \
|
||||||
|
GO111MODULE=on \
|
||||||
|
go mod tidy -v && echo OK
|
||||||
|
|
||||||
|
# Run all code formatters
|
||||||
|
fmts: fmt imports
|
||||||
|
|
||||||
|
# Reformat code
|
||||||
|
fmt:
|
||||||
|
@echo "⇒ Processing gofmt check"
|
||||||
|
@GO111MODULE=on gofmt -s -w ./
|
||||||
|
|
||||||
|
# Reformat imports
|
||||||
|
imports:
|
||||||
|
@echo "⇒ Processing goimports check"
|
||||||
|
@GO111MODULE=on goimports -w ./
|
||||||
|
|
||||||
|
# Build clean Docker image
|
||||||
|
image:
|
||||||
|
@echo "⇒ Build NeoFS HTTP Gateway docker image "
|
||||||
@docker build \
|
@docker build \
|
||||||
|
--build-arg REPO=$(REPO) \
|
||||||
--build-arg VERSION=$(VERSION) \
|
--build-arg VERSION=$(VERSION) \
|
||||||
|
--rm \
|
||||||
-f Dockerfile \
|
-f Dockerfile \
|
||||||
-t $(HUB_IMAGE)-http-gate:$(VERSION) .
|
-t $(HUB_IMAGE):$(HUB_TAG) .
|
||||||
|
|
||||||
# Publish docker image
|
# Build dirty Docker image
|
||||||
publish:
|
dirty-image:
|
||||||
@echo "${B}${G}⇒ publish docker image ${R}"
|
@echo "⇒ Build NeoFS HTTP Gateway dirty docker image "
|
||||||
@docker push $(HUB_IMAGE)-http-gate:$(VERSION)
|
@docker build \
|
||||||
|
--build-arg REPO=$(REPO) \
|
||||||
|
--build-arg VERSION=$(VERSION) \
|
||||||
|
--rm \
|
||||||
|
-f Dockerfile.dirty \
|
||||||
|
-t $(HUB_IMAGE)-dirty:$(HUB_TAG) .
|
||||||
|
|
||||||
.PHONY: dev
|
# Run linters
|
||||||
|
lint:
|
||||||
|
@golangci-lint --timeout=5m run
|
||||||
|
|
||||||
# Build development docker images
|
# Run linters in Docker
|
||||||
dev: VERSIONS?=$(GRPC_VERSION)
|
docker/lint:
|
||||||
dev:
|
docker run --rm -it \
|
||||||
@echo "=> Build multiple images for $(VERSIONS)"; \
|
-v `pwd`:/src \
|
||||||
git checkout go.{sum,mod}; \
|
-u `stat -c "%u:%g" .` \
|
||||||
for v in $(VERSIONS); do \
|
--env HOME=/src \
|
||||||
curdir=$$(pwd); \
|
golangci/golangci-lint:v1.39 bash -c 'cd /src/ && make lint'
|
||||||
echo "=> Checkout gRPC to $${v}"; \
|
|
||||||
cd ../grpc-go; \
|
# Print version
|
||||||
git checkout $${v} &> /dev/null || (echo "Release $${v} not found" && exit 2); \
|
version:
|
||||||
cd ../neofs-api; \
|
@echo $(VERSION)
|
||||||
git checkout go.{sum,mod}; \
|
|
||||||
go get google.golang.org/grpc@$${v}; \
|
# Show this help prompt
|
||||||
cd $${curdir}; \
|
help:
|
||||||
cp go_dev.mod go.mod; \
|
@echo ' Usage:'
|
||||||
go get google.golang.org/grpc@$${v}; \
|
@echo ''
|
||||||
make image VERSION=$(VERSION)-$${v}; \
|
@echo ' make <target>'
|
||||||
git checkout go.{sum,mod}; \
|
@echo ''
|
||||||
done
|
@echo ' Targets:'
|
||||||
|
@echo ''
|
||||||
|
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
clean:
|
||||||
|
rm -rf vendor
|
||||||
|
rm -rf $(BINDIR)
|
||||||
|
|
25
README.md
25
README.md
|
@ -1,24 +1,17 @@
|
||||||
# NeoFS HTTP Gate
|
# NeoFS HTTP Protocol Gateway
|
||||||
|
|
||||||
NeoFS HTTP Gate is example of tool that provides basic interactions with NeoFS.
|
NeoFS HTTP Protocol Gateway bridges NeoFS internal protocol and HTTP standard.
|
||||||
|
- you can download one file per request from NeoFS Network
|
||||||
- you can download one file per request from NeoFS Network using NeoFS Gate
|
- you can upload one file per request into the NeoFS Network
|
||||||
- you can upload one file per request into NeoFS Network using NeoFS Gate
|
|
||||||
|
|
||||||
## Notable make targets
|
## Notable make targets
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage:
|
dep Check and ensure dependencies
|
||||||
|
image Build clean docker image
|
||||||
make <target>
|
dirty-image Build diry docker image with host-built binaries
|
||||||
|
fmts Run all code formatters
|
||||||
Targets:
|
lint Run linters
|
||||||
|
|
||||||
deps Check and ensure dependencies
|
|
||||||
dev Build development docker images
|
|
||||||
help Show this help prompt
|
|
||||||
image Build docker image
|
|
||||||
publish Publish docker image
|
|
||||||
version Show current version
|
version Show current version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
11
help.mk
11
help.mk
|
@ -1,11 +0,0 @@
|
||||||
.PHONY: help
|
|
||||||
|
|
||||||
# Show this help prompt
|
|
||||||
help:
|
|
||||||
@echo ' Usage:'
|
|
||||||
@echo ''
|
|
||||||
@echo ' make <target>'
|
|
||||||
@echo ''
|
|
||||||
@echo ' Targets:'
|
|
||||||
@echo ''
|
|
||||||
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq
|
|
1
misc.go
1
misc.go
|
@ -5,4 +5,5 @@ const Prefix = "HTTP_GW"
|
||||||
var (
|
var (
|
||||||
Build = "now"
|
Build = "now"
|
||||||
Version = "dev"
|
Version = "dev"
|
||||||
|
Debug = "false"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue