|
| 1 | +# Copyright 2024 WebVirtCloud |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +DISTRO ?= ubuntu2404 |
| 16 | +IMAGE ?= webvirtcompute |
| 17 | +TAG ?= $(DISTRO) |
| 18 | + |
| 19 | +.PHONY: build |
| 20 | +build: |
| 21 | + @echo "==> Building the docker image" |
| 22 | + @docker build --no-cache --platform linux/amd64 -f Dockerfile.$(DISTRO) -t $(IMAGE):$(TAG) . |
| 23 | + |
| 24 | +.PHONY: compile |
| 25 | +compile: |
| 26 | + @if [ ! `docker images $(IMAGE):$(TAG) -q` ]; then\ |
| 27 | + echo "==> Build docker image first";\ |
| 28 | + exit 1;\ |
| 29 | + fi |
| 30 | + @echo "==> Compile binary" |
| 31 | + @docker run --rm -it --platform linux/amd64 -v $(PWD)/src:/src -w /src $(IMAGE):$(TAG) bash -c \ |
| 32 | + "/usr/local/bin/pyinstaller -p /src --hiddenimport main -F webvirtcompute.py" |
| 33 | + @echo "==> Binary compiled" |
| 34 | + |
| 35 | +.PHONY: package |
| 36 | +package: |
| 37 | + @if [ ! -d src/dist ]; then\ |
| 38 | + echo "==> Compile the app first";\ |
| 39 | + exit 1;\ |
| 40 | + fi |
| 41 | + @cp configs/webvirtcompute.ini src/dist/ |
| 42 | + @cp configs/webvirtcompute.service src/dist/ |
| 43 | + @if [ ! -d release ]; then\ |
| 44 | + mkdir release;\ |
| 45 | + fi |
| 46 | + @docker run --rm -it --platform linux/amd64 -v $(PWD):/app -w /app $(IMAGE):$(TAG) bash -c \ |
| 47 | + "cd src; tar -czf ../release/webvirtcompute-$(DISTRO)-amd64.tar.gz --transform s/dist/webvirtcompute/ dist" |
| 48 | + @echo "==> Package archived to release directory" |
| 49 | + |
| 50 | +.PHONY: test |
| 51 | +test: |
| 52 | + @echo "==> Start testing" |
| 53 | + @docker run --rm -it --platform linux/amd64 -v $(PWD)/src:/src -w /src $(IMAGE):$(TAG) flake8 |
| 54 | + @echo "==> Testing complited" |
| 55 | + |
| 56 | +.PHONY: clean |
| 57 | +clean: |
| 58 | + @rm -rf src/build src/dist src/__pycache__ src/webvirtcompute.spec |
| 59 | + @echo "==> Cleaned" |
0 commit comments