Skip to content

Commit

Permalink
.github: add job to publish image for WSC
Browse files Browse the repository at this point in the history
Also, remove Go setup from publishing jobs because we don't need Go on runner.
  • Loading branch information
AnnaShaleva committed Nov 25, 2021
1 parent 6b07128 commit 94e3c67
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 20 deletions.
98 changes: 81 additions & 17 deletions .github/workflows/publish_to_dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ on:
workflow_dispatch:
inputs:
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
default: ''
push_image:
description: 'Push image to DockerHub [default: false; examples: true, false]'
description: 'Push images to DockerHub [default: false; examples: true, false]'
required: false
default: 'false'

Expand All @@ -29,8 +29,8 @@ env:

# A workflow run.
jobs:
test:
name: Run tests before publishing
tests_ubuntu:
name: Run Ubuntu-based tests before publishing
runs-on: ubuntu-20.04

steps:
Expand Down Expand Up @@ -70,10 +70,10 @@ jobs:

- name: Run tests
run: make test
publish:
publish_ubuntu:
# Ensure test job passes before pushing image.
needs: test
name: Publish image to DockerHub
needs: test_ubuntu
name: Publish Ubuntu-based image to DockerHub
runs-on: ubuntu-20.04
steps:
- name: Checkout (manual run)
Expand All @@ -91,6 +91,52 @@ jobs:
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
fetch-depth: 0

- name: Build image
run: make image

- name: Build image with 'latest' tag
if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }}
run: make image-latest

- 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-push

- name: Push image with 'latest' tag to registry
if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }}
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:
Expand All @@ -105,12 +151,34 @@ jobs:
- name: Update Go modules
run: go mod download -json

- name: Build image
run: make image
- 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: test_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: Build image with 'latest' tag
if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }}
run: make image-latest
- 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
Expand All @@ -120,8 +188,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-push

- name: Push image with 'latest' tag to registry
if: ${{ github.event_name == 'release' && github.event.release.target_commitish == 'master' }}
run: make image-push-latest
run: make image-wsc-push
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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-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

build: deps
Expand Down Expand Up @@ -61,11 +61,15 @@ image-latest: deps
@docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .

image-push:
@echo "=> Publish image"
@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

image-push-latest:
@echo "=> Publish image with 'latest' tag"
@echo "=> Publish image for Ubuntu with 'latest' tag"
@docker push $(IMAGE_REPO):latest

check-version:
Expand Down

0 comments on commit 94e3c67

Please sign in to comment.