Makefile: allow to build privnet image for WSC

1. Build privnet image for WSC.
2. Automatically define OS to build image and privnet image.
3. Unify image building code for Ubuntu and WSC.
This commit is contained in:
Anna Shaleva 2022-03-25 16:08:13 +03:00 committed by AnnaShaleva
parent be14d8325b
commit 613f6e4350
3 changed files with 23 additions and 19 deletions

View file

@ -126,7 +126,7 @@ jobs:
go-version: 1.18 go-version: 1.18
- name: Build Docker image - name: Build Docker image
run: make image-wsc run: make image
build_privnet_image_ubuntu: build_privnet_image_ubuntu:
needs: build_cli_ubuntu needs: build_cli_ubuntu

View file

@ -156,7 +156,7 @@ jobs:
go-version: 1.18 go-version: 1.18
- name: Build image - name: Build image
run: make image-wsc run: make image
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v1
@ -166,4 +166,4 @@ jobs:
- name: Push image to registry - name: Push image to registry
if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }}
run: make image-wsc-push run: make image-push

View file

@ -8,7 +8,10 @@ BINDIR = "/usr/bin"
SYSTEMDUNIT_DIR = "/lib/systemd/system" SYSTEMDUNIT_DIR = "/lib/systemd/system"
UNITWORKDIR = "/var/lib/neo-go" UNITWORKDIR = "/var/lib/neo-go"
DC_FILE=.docker/docker-compose.yml IMAGE_SUFFIX="$(shell if [ "$(OS)" = Windows_NT ]; then echo "_WindowsServerCore"; fi)"
D_FILE ?= "$(shell if [ "$(OS)" = Windows_NT ]; then echo "Dockerfile.wsc"; else echo "Dockerfile"; fi)"
DC_FILE ?= ".docker/docker-compose.yml" # Single docker-compose for Ubuntu/WSC, should be kept in sync with ENV_IMAGE_TAG.
ENV_IMAGE_TAG="env_neo_go_image"
REPO ?= "$(shell go list -m)" REPO ?= "$(shell go list -m)"
VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')" VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')"
@ -19,7 +22,7 @@ IMAGE_REPO=nspccdev/neo-go
# All of the targets are phony here because we don't really use make dependency # All of the targets are phony here because we don't really use make dependency
# tracking for files # tracking for files
.PHONY: build deps image image-wsc image-latest image-push image-wsc-push image-push-latest check-version clean-cluster push-tag \ .PHONY: build deps image image-latest image-push image-push-latest check-version clean-cluster push-tag \
test vet lint fmt cover test vet lint fmt cover
build: deps build: deps
@ -50,24 +53,21 @@ postinst: install
&& systemctl enable neo-go.service && systemctl enable neo-go.service
image: deps image: deps
@echo "=> Building image for Ubuntu" @echo "=> Building image"
@docker build -t $(IMAGE_REPO):$(VERSION) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . @echo " Dockerfile: $(D_FILE)"
@echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)"
image-wsc: deps @docker build -f $(D_FILE) -t $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
@echo "=> Building image for Windows Server Core"
@docker build -f Dockerfile.wsc -t $(IMAGE_REPO):$(VERSION)_WindowsServerCore --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
image-latest: deps image-latest: deps
@echo "=> Building image with 'latest' tag" @echo "=> Building image with 'latest' tag"
@echo " Dockerfile: Dockerfile" # Always use default Dockerfile for Ubuntu as `latest`.
@echo " Tag: $(IMAGE_REPO):latest"
@docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . @docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
image-push: image-push:
@echo "=> Publish image for Ubuntu" @echo "=> Publish image"
@docker push $(IMAGE_REPO):$(VERSION) @echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)"
@docker push $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)
image-wsc-push:
@echo "=> Publish image for Windows Server Core"
@docker push $(IMAGE_REPO):$(VERSION)_WindowsServerCore
image-push-latest: image-push-latest:
@echo "=> Publish image for Ubuntu with 'latest' tag" @echo "=> Publish image for Ubuntu with 'latest' tag"
@ -104,16 +104,20 @@ cover:
@go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./pkg/...,./cli/... @go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./pkg/...,./cli/...
@go tool cover -html=coverage.txt -o coverage.html @go tool cover -html=coverage.txt -o coverage.html
# --- Environment --- # --- Ubuntu/Windows environment ---
env_image: env_image:
@echo "=> Building env image" @echo "=> Building env image"
@echo " Dockerfile: $(D_FILE)"
@echo " Tag: $(ENV_IMAGE_TAG)"
@docker build \ @docker build \
-t env_neo_go_image \ -f $(D_FILE) \
-t $(ENV_IMAGE_TAG) \
--build-arg REPO=$(REPO) \ --build-arg REPO=$(REPO) \
--build-arg VERSION=$(VERSION) . --build-arg VERSION=$(VERSION) .
env_up: env_up:
@echo "=> Bootup environment" @echo "=> Bootup environment"
@echo " Docker-compose file: $(DC_FILE)"
@docker-compose -f $(DC_FILE) up -d node_one node_two node_three node_four @docker-compose -f $(DC_FILE) up -d node_one node_two node_three node_four
env_single: env_single: