Skip to content

Commit

Permalink
ci: clean Makefile
Browse files Browse the repository at this point in the history
Change-Id: I594044a3e78af0cbdd3cd19fe87764b0373ede6c
  • Loading branch information
amwolff committed Jul 15, 2022
1 parent 4f1f9e1 commit 2e69c64
Showing 1 changed file with 35 additions and 63 deletions.
98 changes: 35 additions & 63 deletions Makefile
@@ -1,12 +1,7 @@
GO_VERSION ?= 1.17.12
BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD | sed "s!/!-!g")
LATEST_DEV_TAG := dev

#
# Common
#

.DEFAULT_GOAL := help
.PHONY: help
help:
@awk 'BEGIN { \
Expand All @@ -20,6 +15,8 @@ help:
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
}' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help

#
# Public Jenkins (commands below are used for local development and/or public Jenkins)
#
Expand Down Expand Up @@ -147,66 +144,55 @@ test-testsuite-do:
.PHONY: verify
verify: lint cross-vet test ## Execute pre-commit verification

# todo(artur, sean): these extra ldflags are required for the minio object
# browser to function, but should be automated. Use storj.io/minio/buildscripts/gen-ldflags.go
LDFLAGS := -X storj.io/minio/cmd.Version=2022-04-19T11:13:21Z \
-X storj.io/minio/cmd.ReleaseTag=DEVELOPMENT.2022-04-19T11-13-21Z \
-X storj.io/minio/cmd.CommitID=ae15cc41053bb0a65e543f71d81646dd2318fe10 \
-X storj.io/minio/cmd.ShortCommitID=ae15cc41053b
#
# Private Jenkins (commands below are used for releases/private Jenkins)
#

##@ Release/Private Jenkins/Build

GO_VERSION ?= 1.17.12
BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD | sed "s!/!-!g")

ifeq (${BRANCH_NAME},main)
TAG := $(shell git rev-parse --short HEAD)-go${GO_VERSION}
BRANCH_NAME :=
else
TAG := $(shell git rev-parse --short HEAD)-${BRANCH_NAME}-go${GO_VERSION}
ifneq (,$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*"))
ifneq ($(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*"),)
LATEST_STABLE_TAG := latest
endif
endif

DOCKER_BUILD := docker build --build-arg TAG=${TAG}

##@ Dependencies

.PHONY: build-dev-deps
build-dev-deps: ## Install dependencies for builds
go get golang.org/x/tools/cover
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo

.PHONY: goimports-fix
goimports-fix: ## Applies goimports to every go file (excluding vendored files)
goimports -w -local storj.io $$(find . -type f -name '*.go' -not -path "*/vendor/*")

.PHONY: goimports-st
goimports-st: ## Applies goimports to every go file in `git status` (ignores untracked files)
@git status --porcelain -uno|grep .go|grep -v "^D"|sed -E 's,\w+\s+(.+->\s+)?,,g'|xargs -I {} goimports -w -local storj.io {}

.PHONY: build-packages
build-packages: build-packages-normal build-packages-race ## Test docker images locally
build-packages-normal:
go build -v ./...
build-packages-race:
go build -v -race ./...

##@ Build
LATEST_DEV_TAG := dev

.PHONY: images
images: gateway-image ## Build gateway Docker images
echo Built version: ${TAG}

.PHONY: gateway-image
gateway-image: ## Build gateway Docker image
images: ## Build Docker images
${DOCKER_BUILD} --pull=true -t storjlabs/gateway:${TAG}-amd64 \
-f Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/gateway:${TAG}-arm32v6 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm32v6 \
--build-arg=GOARCH=arm \
--build-arg=DOCKER_ARCH=arm32v6 \
-f Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/gateway:${TAG}-arm64v8 \
--build-arg=GOARCH=arm64 --build-arg=DOCKER_ARCH=arm64v8 \
--build-arg=GOARCH=arm64 \
--build-arg=DOCKER_ARCH=arm64v8 \
-f Dockerfile .

docker tag storjlabs/gateway:${TAG}-amd64 storjlabs/gateway:${LATEST_DEV_TAG}

binaries: ## Build gateway binaries (jenkins)
@echo Built version: ${TAG}

# TODO(artur, sean): these extra ldflags are required for the minio object
# browser to function, but should be automated. Use storj.io/minio/buildscripts/gen-ldflags.go
LDFLAGS := -X storj.io/minio/cmd.Version=2022-04-19T11:13:21Z \
-X storj.io/minio/cmd.ReleaseTag=DEVELOPMENT.2022-04-19T11-13-21Z \
-X storj.io/minio/cmd.CommitID=ae15cc41053bb0a65e543f71d81646dd2318fe10 \
-X storj.io/minio/cmd.ShortCommitID=ae15cc41053b

.PHONY: binaries
binaries: ## Build binaries
CGO_ENABLED=0 LDFLAGS="${LDFLAGS}" storj-release \
--build-name gateway \
--build-tags kqueue \
Expand All @@ -222,10 +208,8 @@ binaries: ## Build gateway binaries (jenkins)
--branch "${BRANCH_NAME}" \
--osarches "freebsd/amd64"

##@ Deploy

.PHONY: push-images
push-images: ## Push Docker images to Docker Hub (jenkins)
push-images: ## Push Docker images to Docker Hub
# images have to be pushed before a manifest can be created
for c in gateway; do \
docker push storjlabs/$$c:${TAG}-amd64 \
Expand All @@ -244,7 +228,7 @@ push-images: ## Push Docker images to Docker Hub (jenkins)
; done

.PHONY: binaries-upload
binaries-upload: ## Upload binaries to Google Storage (jenkins)
binaries-upload: ## Upload release binaries to GCS
cd "release/${TAG}"; for f in *; do \
c="$${f%%_*}" \
&& if [ "$${f##*.}" != "$${f}" ]; then \
Expand All @@ -259,27 +243,15 @@ binaries-upload: ## Upload binaries to Google Storage (jenkins)
; done
cd "release/${TAG}"; gsutil -m cp -r *.zip "gs://storj-v3-alpha-builds/${TAG}/"

##@ Clean
##@ Release/Private Jenkins/Clean

.PHONY: clean
clean: test-docker-clean binaries-clean clean-images ## Clean docker test environment, local release binaries, and local Docker images
clean: clean-binaries clean-images ## Remove local release binaries and local Docker images

.PHONY: binaries-clean
binaries-clean: ## Remove all local release binaries (jenkins)
.PHONY: clean-binaries
clean-binaries: ## Remove local release binaries
rm -rf release

.PHONY: clean-images
clean-images:
-docker rmi storjlabs/gateway:${TAG}

.PHONY: test-docker-clean
test-docker-clean: ## Clean up Docker environment used in test-docker target
-docker-compose down --rmi all

.PHONY: bump-dependencies
bump-dependencies:
go get storj.io/common@main storj.io/private@main storj.io/uplink@main
go mod tidy
cd testsuite;\
go get storj.io/common@main storj.io/storj@main storj.io/uplink@main;\
go mod tidy

0 comments on commit 2e69c64

Please sign in to comment.