From e64a6178440e5c24e051c8c224301f1f2fa4a667 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Fri, 19 Nov 2021 15:23:51 +0300 Subject: [PATCH] .github: add action to build WSC image --- .docker/privnet-entrypoint.ps1 | 15 ++++++++++++++ .github/workflows/build.yml | 23 ++++++++++++++++----- .github/workflows/run_tests.yml | 6 +++--- Dockerfile.wsc | 36 +++++++++++++++++++++++++++++++++ Makefile | 8 ++++++-- 5 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 .docker/privnet-entrypoint.ps1 create mode 100644 Dockerfile.wsc diff --git a/.docker/privnet-entrypoint.ps1 b/.docker/privnet-entrypoint.ps1 new file mode 100644 index 000000000..94cd4fc99 --- /dev/null +++ b/.docker/privnet-entrypoint.ps1 @@ -0,0 +1,15 @@ +#!C:\Program Files\PowerShell\7\pwsh.EXE -File + +$bin = '/usr/bin/neo-go.exe' + +for ( $i = 0; $i -lt $args.count; $i++ ) { + if ($args[$i] -eq "node"){ + Write-Host "=> Try to restore blocks before running node" + if (($Env:ACC -ne $null) -and (Test-Path $Env:ACC -PathType Leaf)) { + & $bin db restore -p --config-path /config -i $Env:ACC + } + break + } +} + +& $bin $args diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e91de926..27d4f338f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,9 +40,9 @@ jobs: - name: Build CLI run: make build - build_cli_win: - name: Build CLI (Windows) - runs-on: windows-2019 + build_cli_wsc: + name: Build CLI (Windows Server Core) + runs-on: windows-2022 steps: - uses: actions/checkout@v2 @@ -66,9 +66,9 @@ jobs: - name: Build CLI run: make build - build_image: + build_image_ubuntu: needs: build_cli_ubuntu - name: Build Docker image + name: Build Docker image (Ubuntu) runs-on: ubuntu-20.04 steps: @@ -78,3 +78,16 @@ jobs: - name: Build Docker image run: make image + + build_image_wsc: + needs: build_cli_wsc + name: Build Docker image (Windows Server Core) + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build Docker image + run: make image-wsc diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 95585515c..4d434a19c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -99,9 +99,9 @@ jobs: - name: Run tests run: go test -v -race ./... - tests_win: - name: Windows, Go (1.17) - runs-on: windows-2019 + tests_wsc: + name: Windows Server Core, Go (1.17) + runs-on: windows-2022 steps: - uses: actions/checkout@v2 with: diff --git a/Dockerfile.wsc b/Dockerfile.wsc new file mode 100644 index 000000000..6ed9760ab --- /dev/null +++ b/Dockerfile.wsc @@ -0,0 +1,36 @@ +# Builder image +FROM golang:windowsservercore-ltsc2022 as builder + +COPY . /neo-go + +WORKDIR /neo-go + +ARG REPO=repository +ARG VERSION=dev + +SHELL ["cmd", "/S", "/C"] +RUN go env -w CGO_ENABLED=0 +ENV GOGC=off + +RUN go build -trimpath -v -o ./bin/neo-go.exe -ldflags="-X %REPO%/pkg/config.Version=%VERSION%" ./cli/main.go + +# Executable image +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +ARG VERSION +LABEL version=%VERSION% + +WORKDIR / + +COPY --from=builder /neo-go/config /config +COPY --from=builder /neo-go/.docker/privnet-entrypoint.ps1 /usr/bin/privnet-entrypoint.ps1 +COPY --from=builder /neo-go/bin/neo-go.exe /usr/bin/neo-go.exe + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';", "$ProgressPreference = 'SilentlyContinue';"] + +# Check executable version. +RUN /usr/bin/neo-go.exe --version + +ENTRYPOINT ["powershell", "-File", "/usr/bin/privnet-entrypoint.ps1"] + +CMD ["node", "--config-path", "/config", "--privnet"] diff --git a/Makefile b/Makefile index 60fc274d6..0ca1116a7 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,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-latest image-push image-push-latest check-version clean-cluster push-tag \ +.PHONY: build deps image image-wsc image-latest image-push image-push-latest check-version clean-cluster push-tag \ test vet lint fmt cover build: deps @@ -49,9 +49,13 @@ postinst: install && systemctl enable neo-go.service image: deps - @echo "=> Building image" + @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) . + image-latest: deps @echo "=> Building image with 'latest' tag" @docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .