2022-04-19 12:01:08 +00:00
|
|
|
# Copyright 2021 Linka Cloud All rights reserved.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
MODULE = go.linka.cloud/d2vm
|
|
|
|
|
|
|
|
REPOSITORY = linkacloud
|
|
|
|
|
2022-09-11 02:01:05 +00:00
|
|
|
TAG = $(shell git diff --quiet && git describe --tags --exact-match 2> /dev/null)
|
2022-04-19 12:01:08 +00:00
|
|
|
VERSION_SUFFIX = $(shell git diff --quiet || echo "-dev")
|
|
|
|
VERSION = $(shell git describe --tags --exact-match 2> /dev/null || echo "`git describe --tags $$(git rev-list --tags --max-count=1) 2> /dev/null || echo v0.0.0`-`git rev-parse --short HEAD`")$(VERSION_SUFFIX)
|
|
|
|
show-version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
2022-08-05 11:05:37 +00:00
|
|
|
GORELEASER_VERSION := v1.10.1
|
|
|
|
GORELEASER_URL := https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_Linux_x86_64.tar.gz
|
|
|
|
|
|
|
|
BIN := $(PWD)/bin
|
|
|
|
export PATH := $(BIN):$(PATH)
|
|
|
|
|
2022-09-06 16:49:30 +00:00
|
|
|
CLI_REFERENCE_PATH := docs/content/reference
|
2022-08-09 16:55:54 +00:00
|
|
|
|
2022-08-05 11:05:37 +00:00
|
|
|
bin:
|
|
|
|
@mkdir -p $(BIN)
|
|
|
|
@curl -sL $(GORELEASER_URL) | tar -C $(BIN) -xz goreleaser
|
|
|
|
|
|
|
|
clean-bin:
|
|
|
|
@rm -rf $(BIN)
|
|
|
|
|
2022-04-19 12:01:08 +00:00
|
|
|
DOCKER_IMAGE := linkacloud/d2vm
|
|
|
|
|
2022-04-19 12:07:13 +00:00
|
|
|
docker: docker-build docker-push
|
|
|
|
|
2022-04-19 12:01:08 +00:00
|
|
|
docker-push:
|
2022-08-23 11:21:18 +00:00
|
|
|
@docker image push $(DOCKER_IMAGE):$(VERSION)
|
2022-08-05 11:05:37 +00:00
|
|
|
ifneq ($(TAG),)
|
|
|
|
@docker image push $(DOCKER_IMAGE):latest
|
|
|
|
endif
|
2022-04-19 12:01:08 +00:00
|
|
|
|
|
|
|
docker-build:
|
2022-05-20 14:36:36 +00:00
|
|
|
@docker image build -t $(DOCKER_IMAGE):$(VERSION) .
|
2022-08-05 11:05:37 +00:00
|
|
|
ifneq ($(TAG),)
|
|
|
|
@docker image tag $(DOCKER_IMAGE):$(TAG) $(DOCKER_IMAGE):latest
|
|
|
|
endif
|
2022-04-19 12:01:08 +00:00
|
|
|
|
|
|
|
docker-run:
|
|
|
|
@docker run --rm -i -t \
|
|
|
|
--privileged \
|
|
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
|
|
-v $(PWD):/build \
|
|
|
|
-w /build \
|
|
|
|
$(DOCKER_IMAGE) bash
|
2022-04-21 19:15:39 +00:00
|
|
|
|
2022-08-05 11:05:37 +00:00
|
|
|
.PHONY: tests
|
|
|
|
tests:
|
2022-08-05 15:57:51 +00:00
|
|
|
@go generate ./...
|
2022-08-05 17:08:38 +00:00
|
|
|
@go list ./...| xargs go test -exec sudo -count=1 -timeout 20m -v
|
2022-08-10 09:35:55 +00:00
|
|
|
|
|
|
|
docs-up-to-date:
|
2022-09-06 16:49:30 +00:00
|
|
|
@$(MAKE) cli-docs
|
2022-09-06 17:40:02 +00:00
|
|
|
@git diff --quiet -- docs ':(exclude)docs/content/reference/d2vm_run_qemu.md' || (git --no-pager diff -- docs ':(exclude)docs/content/reference/d2vm_run_qemu.md'; echo "Please regenerate the documentation with 'make docs'"; exit 1)
|
2022-08-05 11:05:37 +00:00
|
|
|
|
|
|
|
check-fmt:
|
|
|
|
@[ "$(gofmt -l $(find . -name '*.go') 2>&1)" = "" ]
|
|
|
|
|
|
|
|
vet:
|
|
|
|
@go list ./...|grep -v scratch|GOOS=linux xargs go vet
|
|
|
|
|
2022-08-09 12:30:03 +00:00
|
|
|
build-dev: docker-build .build
|
|
|
|
|
2022-09-12 07:23:33 +00:00
|
|
|
install: docker-build
|
|
|
|
@go install -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/d2vm
|
|
|
|
|
2022-08-05 11:05:37 +00:00
|
|
|
.build:
|
2022-08-05 15:39:04 +00:00
|
|
|
@go generate ./...
|
2022-08-05 11:05:37 +00:00
|
|
|
@go build -o d2vm -ldflags "-s -w -X '$(MODULE).Version=$(VERSION)' -X '$(MODULE).BuildDate=$(shell date)'" ./cmd/d2vm
|
|
|
|
|
|
|
|
.PHONY: build-snapshot
|
|
|
|
build-snapshot: bin
|
|
|
|
@VERSION=$(VERSION) IMAGE=$(DOCKER_IMAGE) goreleaser build --snapshot --rm-dist --parallelism 8
|
|
|
|
|
|
|
|
.PHONY: release-snapshot
|
|
|
|
release-snapshot: bin
|
|
|
|
@VERSION=$(VERSION) IMAGE=$(DOCKER_IMAGE) goreleaser release --snapshot --rm-dist --skip-announce --skip-publish --parallelism 8
|
|
|
|
|
|
|
|
.PHONY: build
|
2022-09-10 18:10:52 +00:00
|
|
|
build: bin
|
2022-08-06 09:19:58 +00:00
|
|
|
@VERSION=$(VERSION) IMAGE=$(DOCKER_IMAGE) goreleaser build --rm-dist --parallelism 8
|
2022-08-05 11:05:37 +00:00
|
|
|
|
|
|
|
.PHONY: release
|
2022-09-10 18:10:52 +00:00
|
|
|
release: bin
|
2022-08-05 11:05:37 +00:00
|
|
|
@VERSION=$(VERSION) IMAGE=$(DOCKER_IMAGE) goreleaser release --rm-dist --parallelism 8
|
2022-08-09 14:52:12 +00:00
|
|
|
|
2022-09-12 08:10:28 +00:00
|
|
|
.PHONY: completions
|
|
|
|
completions: .build
|
|
|
|
@rm -rf completions
|
|
|
|
@mkdir -p completions
|
|
|
|
@for shell in bash zsh fish powershell; do \
|
2022-09-12 08:13:41 +00:00
|
|
|
./d2vm completion $$shell > completions/d2vm.$$shell; \
|
2022-09-12 08:10:28 +00:00
|
|
|
done
|
|
|
|
|
2022-08-09 14:52:12 +00:00
|
|
|
.PHONY: examples
|
|
|
|
examples: build-dev
|
|
|
|
@mkdir -p examples/build
|
|
|
|
@for f in $$(find examples -type f -name '*Dockerfile' -maxdepth 1); do \
|
|
|
|
echo "Building $$f"; \
|
2022-09-12 09:19:51 +00:00
|
|
|
./d2vm build -o examples/build/$$(basename $$f|cut -d'.' -f1).qcow2 -p root -f $$f examples --force; \
|
2022-08-09 14:52:12 +00:00
|
|
|
done
|
|
|
|
@echo "Building examples/full/Dockerfile"
|
2022-09-12 09:19:51 +00:00
|
|
|
@./d2vm build -o examples/build/full.qcow2 --build-arg=USER=adphi --build-arg=PASSWORD=adphi examples/full --force
|
2022-08-09 16:55:54 +00:00
|
|
|
|
2022-09-06 16:49:30 +00:00
|
|
|
cli-docs: .build
|
2022-08-09 16:55:54 +00:00
|
|
|
@rm -rf $(CLI_REFERENCE_PATH)
|
|
|
|
@./d2vm docs $(CLI_REFERENCE_PATH)
|
2022-05-19 13:41:06 +00:00
|
|
|
|
|
|
|
serve-docs:
|
|
|
|
@docker run --rm -i -t --user=$(UID) -p 8000:8000 -v $(PWD):/docs linkacloud/mkdocs-material serve -f /docs/docs/mkdocs.yml -a 0.0.0.0:8000
|
|
|
|
|
|
|
|
.PHONY: build-docs
|
|
|
|
build-docs: clean-docs cli-docs
|
|
|
|
@docker run --rm -v $(PWD):/docs linkacloud/mkdocs-material build -f /docs/docs/mkdocs.yml -d build
|
|
|
|
|
|
|
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
|
|
|
|
GITHUB_PAGES_BRANCH := gh-pages
|
|
|
|
|
|
|
|
deploy-docs:
|
|
|
|
@git branch -D gh-pages &> /dev/null || true
|
|
|
|
@git checkout -b $(GITHUB_PAGES_BRANCH)
|
|
|
|
@rm .gitignore && mv docs docs-src && mv docs-src/build docs && rm -rf docs-src
|
|
|
|
@git add . && git commit -m "build docs" && git push origin --force $(GITHUB_PAGES_BRANCH)
|
|
|
|
@git checkout $(GIT_BRANCH)
|
|
|
|
|
|
|
|
docs: cli-docs build-docs deploy-docs
|
|
|
|
|
|
|
|
clean-docs:
|
|
|
|
@rm -rf docs/build
|