Skip to content

Commit

Permalink
devops: improve release workflow (#4705)
Browse files Browse the repository at this point in the history
## Motivation
There have been inconsistencies with our release process recently. This PR addresses those and improves on it.

## Changes
- "Build and Release" workflow will now display "Release {{ tag_name }}" as title when executed
- "Push to Dockerhub" workflow had various improvements:
  - It will now use "Push {{ version }} to Dockerhub" as title
  - When triggered on a tag it will use the tag as version for the docker image, otherwise the short commit SHA is used (as before)
  - For some reason builds on `develop` were pushed to `go-spacemesh` and on other branches (and releases) to `go-spacemesh-dev`. Changed it to always push to `go-spacemesh-dev` unless instructed otherwise (by e.g. the release job when triggered through a tag).
- Updated Makefile: Push to go-spacemesh-dev with short sha by default, release job overwrites the ENV to push to go-spacemesh with tag.

## Test Plan
<!-- Please specify how these changes were tested 
(e.g. unit tests, manual testing, etc.) -->

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services (PoET, elasticsearch, etc.)
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)
  • Loading branch information
fasmat committed Aug 16, 2023
1 parent 24b19ee commit c7a7468
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generate latest build and push it to dockerhub on push to develop branch.
# NOTE: This workflow does not include any tests, nor any dependencies, since bors guarantees
# that only code that passes all tests is ever pushed to develop.
name: push to dockerhub
name: Push to Dockerhub
run-name: Pushing ${{ github.ref_name }} to Dockerhub
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
Expand All @@ -19,7 +20,21 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3
- name: push go-spacemesh
run: make dockerpush
- name: push go-bootstrapper
run: make dockerpush-bs
- name: Build docker images
run: |
make dockerbuild-go
make dockerbuild-bs
- name: Push docker images to dockerhub
run: |
make dockerpush-only
make dockerpush-bs-only
- name: Push docker images with version tag to dockerhub
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "DOCKER_IMAGE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
make dockerpush-only
make dockerpush-bs-only
"DOCKER_IMAGE_REPO=go-spacemesh" make dockerpush-only
"DOCKER_IMAGE_REPO=go-spacemesh" make dockerpush-bs-only
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build and Release

run-name: Release ${{ github.ref_name }}
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
Expand Down
40 changes: 17 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
VERSION ?= $(shell git describe --tags)
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"
include Makefile-libs.Inc

DOCKER_HUB ?= spacemeshos
UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v cmd/node | grep -v cmd/gen-p2p-identity | grep -v cmd/trace | grep -v genvm/cmd)

COMMIT = $(shell git rev-parse HEAD)
SHA = $(shell git rev-parse --short HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

export CGO_ENABLED := 1
export CGO_CFLAGS := $(CGO_CFLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1

# Add an indicator to the branch name if dirty and use commithash if running in detached mode
ifeq ($(BRANCH),HEAD)
BRANCH = $(SHA)
Expand All @@ -21,14 +11,18 @@ ifneq ($(.SHELLSTATUS),0)
BRANCH := $(BRANCH)-dirty
endif

ifeq ($(BRANCH),develop)
DOCKER_IMAGE_REPO := go-spacemesh
else
DOCKER_IMAGE_REPO := go-spacemesh-dev
endif
SHA = $(shell git rev-parse --short HEAD)
DOCKER_HUB ?= spacemeshos
DOCKER_IMAGE_REPO ?= go-spacemesh-dev
DOCKER_IMAGE_VERSION ?= $(SHA)

LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"
include Makefile-libs.Inc

UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v cmd/node | grep -v cmd/gen-p2p-identity | grep -v cmd/trace | grep -v genvm/cmd)

DOCKER_IMAGE = $(DOCKER_IMAGE_REPO):$(SHA)
DOCKER_BS_IMAGE = $(DOCKER_IMAGE_REPO)-bs:$(SHA)
export CGO_ENABLED := 1
export CGO_CFLAGS := $(CGO_CFLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1

# setting extra command line params for the CI tests pytest commands
ifdef namespace
Expand Down Expand Up @@ -146,7 +140,7 @@ list-versions:
.PHONY: list-versions

dockerbuild-go:
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_IMAGE) .
DOCKER_BUILDKIT=1 docker build -t go-spacemesh:$(SHA) .
.PHONY: dockerbuild-go

dockerpush: dockerbuild-go dockerpush-only
Expand All @@ -156,12 +150,12 @@ dockerpush-only:
ifneq ($(DOCKER_USERNAME):$(DOCKER_PASSWORD),:)
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
endif
docker tag $(DOCKER_IMAGE) $(DOCKER_HUB)/$(DOCKER_IMAGE)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE)
docker tag go-spacemesh:$(SHA) $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_VERSION)
.PHONY: dockerpush-only

dockerbuild-bs:
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_BS_IMAGE) -f ./bootstrap.Dockerfile .
DOCKER_BUILDKIT=1 docker build -t go-spacemesh-bs:$(SHA) -f ./bootstrap.Dockerfile .
.PHONY: dockerbuild-bs

dockerpush-bs: dockerbuild-bs dockerpush-bs-only
Expand All @@ -171,8 +165,8 @@ dockerpush-bs-only:
ifneq ($(DOCKER_USERNAME):$(DOCKER_PASSWORD),:)
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
endif
docker tag $(DOCKER_BS_IMAGE) $(DOCKER_HUB)/$(DOCKER_BS_IMAGE)
docker push $(DOCKER_HUB)/$(DOCKER_BS_IMAGE)
docker tag go-spacemesh-bs:$(SHA) $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO)-bs:$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_HUB)/$(DOCKER_IMAGE_REPO)-bs:$(DOCKER_IMAGE_VERSION)
.PHONY: dockerpush-bs-only

fuzz:
Expand Down

0 comments on commit c7a7468

Please sign in to comment.