From 613f6e435002267d7c2394b9a79c2198ad5684e6 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 25 Mar 2022 16:08:13 +0300 Subject: [PATCH] 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. --- .github/workflows/build.yml | 2 +- .github/workflows/publish_to_dockerhub.yml | 4 +-- Makefile | 36 ++++++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d28e72cb..df34d8325 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -126,7 +126,7 @@ jobs: go-version: 1.18 - name: Build Docker image - run: make image-wsc + run: make image build_privnet_image_ubuntu: needs: build_cli_ubuntu diff --git a/.github/workflows/publish_to_dockerhub.yml b/.github/workflows/publish_to_dockerhub.yml index 551274139..d8cf5e969 100644 --- a/.github/workflows/publish_to_dockerhub.yml +++ b/.github/workflows/publish_to_dockerhub.yml @@ -156,7 +156,7 @@ jobs: go-version: 1.18 - name: Build image - run: make image-wsc + run: make image - name: Login to DockerHub uses: docker/login-action@v1 @@ -166,4 +166,4 @@ jobs: - name: Push image to registry 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 diff --git a/Makefile b/Makefile index d026423f0..1beb9250a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,10 @@ BINDIR = "/usr/bin" SYSTEMDUNIT_DIR = "/lib/systemd/system" 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)" 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 # 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 build: deps @@ -50,24 +53,21 @@ postinst: install && systemctl enable neo-go.service image: deps - @echo "=> Building image for Ubuntu" - @docker build -t $(IMAGE_REPO):$(VERSION) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . - -image-wsc: deps - @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) . + @echo "=> Building image" + @echo " Dockerfile: $(D_FILE)" + @echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)" + @docker build -f $(D_FILE) -t $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . image-latest: deps @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) . image-push: - @echo "=> Publish image for Ubuntu" - @docker push $(IMAGE_REPO):$(VERSION) - -image-wsc-push: - @echo "=> Publish image for Windows Server Core" - @docker push $(IMAGE_REPO):$(VERSION)_WindowsServerCore + @echo "=> Publish image" + @echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)" + @docker push $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX) image-push-latest: @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 tool cover -html=coverage.txt -o coverage.html -# --- Environment --- +# --- Ubuntu/Windows environment --- env_image: @echo "=> Building env image" + @echo " Dockerfile: $(D_FILE)" + @echo " Tag: $(ENV_IMAGE_TAG)" @docker build \ - -t env_neo_go_image \ + -f $(D_FILE) \ + -t $(ENV_IMAGE_TAG) \ --build-arg REPO=$(REPO) \ --build-arg VERSION=$(VERSION) . env_up: @echo "=> Bootup environment" + @echo " Docker-compose file: $(DC_FILE)" @docker-compose -f $(DC_FILE) up -d node_one node_two node_three node_four env_single: