.github: add job to publish image for WSC

Also, remove Go setup from publishing jobs because we don't need Go on runner.
This commit is contained in:
AnnaShaleva 2021-11-25 11:32:44 +03:00 committed by Anna Shaleva
parent d2d75b8ba5
commit 5ef9f4498e
2 changed files with 92 additions and 24 deletions

View file

@ -15,11 +15,11 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
ref: ref:
description: 'Ref to build Docker image [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' description: 'Ref to build Docker images for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]'
required: false required: false
default: '' default: ''
push_image: push_image:
description: 'Push image to DockerHub [default: false; examples: true, false]' description: 'Push images to DockerHub [default: false; examples: true, false]'
required: false required: false
default: 'false' default: 'false'
@ -29,8 +29,8 @@ env:
# A workflow run. # A workflow run.
jobs: jobs:
test: tests_ubuntu:
name: Run tests before publishing name: Run Ubuntu-based tests before publishing
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
@ -70,10 +70,10 @@ jobs:
- name: Run tests - name: Run tests
run: make test run: make test
publish: publish_ubuntu:
# Ensure test job passes before pushing image. # Ensure test job passes before pushing image.
needs: test needs: tests_ubuntu
name: Publish image to DockerHub name: Publish Ubuntu-based image to DockerHub
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout (manual run) - name: Checkout (manual run)
@ -91,20 +91,6 @@ jobs:
# Allows to fetch all history for all branches and tags. Need this for proper versioning. # Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0 fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Restore go modules from cache
uses: actions/cache@v2
with:
path: /home/runner/go/pkg/mod
key: deps-${{ hashFiles('go.sum') }}
- name: Update Go modules
run: go mod download -json
- name: Build image - name: Build image
run: make image run: make image
@ -125,3 +111,81 @@ jobs:
- name: Push image with 'latest' tag to registry - name: Push image with 'latest' tag to registry
if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }} if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }}
run: make image-push-latest run: make image-push-latest
tests_wsc:
name: Run WindowsServerCore-based tests before publishing
runs-on: windows-2022
steps:
- name: Checkout (manual run)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref }}
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0
- name: Checkout (automatical run)
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: actions/checkout@v2
with:
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0
- name: Sync VM submodule
run: |
git submodule sync
git submodule update --init
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Restore go modules from cache
uses: actions/cache@v2
with:
path: /home/runner/go/pkg/mod
key: deps-${{ hashFiles('go.sum') }}
- name: Update Go modules
run: go mod download -json
- name: Run tests
run: make test
publish_wsc:
# Ensure test job passes before pushing image.
# TODO: currently test_wsc job is failing, so we have `always()` condition.
# After #2269 and #2268 this condition should be removed.
if: ${{ always() }}
needs: tests_wsc
name: Publish WindowsServerCore-based image to DockerHub
runs-on: windows-2022
steps:
- name: Checkout (manual run)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref }}
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0
- name: Checkout (automatical run)
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: actions/checkout@v2
with:
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0
- name: Build image
run: make image-wsc
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- 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

View file

@ -18,7 +18,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-push-latest check-version clean-cluster push-tag \ .PHONY: build deps image image-wsc image-latest image-push image-wsc-push image-push-latest check-version clean-cluster push-tag \
test vet lint fmt cover test vet lint fmt cover
build: deps build: deps
@ -61,11 +61,15 @@ image-latest: deps
@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" @echo "=> Publish image for Ubuntu"
@docker push $(IMAGE_REPO):$(VERSION) @docker push $(IMAGE_REPO):$(VERSION)
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 with 'latest' tag" @echo "=> Publish image for Ubuntu with 'latest' tag"
@docker push $(IMAGE_REPO):latest @docker push $(IMAGE_REPO):latest
check-version: check-version: