Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): GHA - artifact build and push to GAR & GCS #329

Merged
merged 8 commits into from
Mar 18, 2022

Conversation

kskewes-sf
Copy link
Contributor

@kskewes-sf kskewes-sf commented Mar 11, 2022

Depends on #328 including removing RELEASE_PHASE as it is not supplied to docker build in the GHA yml files.

There has been requests for an official spin container image in Slack and GitHub issues - eg: spinnaker/spinnaker#4531. Per other services we can push latest, release branch and official release versions to GAR like other services.
Container registry location (repo to be created on first push): https://console.cloud.google.com/artifacts/docker/spinnaker-community/us/docker

Binaries were previously published to GCS by Jenkins and a replacement for this in GHA has been added.
GCS bucket: https://console.cloud.google.com/storage/browser/spinnaker-artifacts/spin?cloudshell=false&project=spinnaker-community

Helps with: spinnaker/spinnaker#6477

Each time a fork's master branch is resync'd with spinnaker/<repo> we
don't want to trigger GHA CI.
Maintain existing behaviours:

shared:
- build for darwin, linux, windows, all on amd64, we can add aarch64 if
  wish.

on release:
- publish to `spinnaker-artifacts/spin/<release>/<os>/<arch>/spin(.exe)`
- publish `spinnaker-artifacts/spin/latest` text file with new version
  if version is newest (version sort). eg: 1.23.0 newer than 1.22.5.
- publish `spinnaker-artifacts/spin/<MAJOR.MINOR>.x-latest` text file
  with version number, eg: 1.23.0 or 1.23.1. Assuming we always do
  increment patch versions.

on merge master or release-* branch:
- publish to `spinnaker-artifacts/spin/<branch>/<git sha>-<datetime>/<os>/<arch>/spin(.exe)`
- this is different see next paragraph

Changes from previous behaviour:

Previous builds were always `spinnaker-artifacts/spin/<tag>-<datetime>/<os>/<arch>/spin(.exe)`
except for final release versions (1.22.0).
eg:
```
1.17.3-20201209030017/
1.17.3-20201210030017/
1.17.3/
```

However I believe it is easier to sort and review with the extra branch or
release number directory, eg:
```
master/<git-sha>-<datetime>/...
release-1.17.x/<git-sha>-<datetime>/...
```
This is also consistent with the container image tags now generated in GHA.
This task has been moved into GHA per preceding commit.
@kskewes-sf kskewes-sf changed the title chore(ci): GHA - container image build and push chore(ci): GHA - artifact build and push to GAR & GCS Mar 14, 2022
@kskewes-sf
Copy link
Contributor Author

Docs PR: spinnaker/spinnaker.io#187

@kskewes-sf
Copy link
Contributor Author

Tested creating releases on my fork with #328 and this PR merged.

version 1.1.1 - akin to a new patch release: https://github.com/kskewes-sf/spin/runs/5532727053?check_suite_focus=true

gcs_latest: 1.22.0
release: 1.1.1
latest: 1.22.0

version 1.23.0 - new minor version: https://github.com/kskewes-sf/spin/runs/5532749163?check_suite_focus=true

gcs_latest: 1.22.0
release: 1.23.0
latest: 1.23.0

A few tags later confirming version supply via ldflag:

Run # build binaries
  # build binaries
  GOARCH=amd64 GOOS=darwin go build -ldflags "${LDFLAGS}" -o dist/1.[2](https://github.com/kskewes-sf/spin/runs/5532819187?check_suite_focus=true#step:12:2)6.0/darwin/amd6[4](https://github.com/kskewes-sf/spin/runs/5532819187?check_suite_focus=true#step:12:4)/spin .
  GOARCH=amd64 GOOS=linux go build -ldflags "${LDFLAGS}" -o dist/1.26.0/linux/amd64/spin .
  GOARCH=amd64 GOOS=windows go build -ldflags "${LDFLAGS}" -o dist/1.26.0/windows/amd64/spin.exe .
  # confirm binary version as expected
  dist/1.26.0/linux/amd64/spin --version
  shell: /usr/bin/bash -e {0}
  env:
    CONTAINER_REGISTRY: us-docker.pkg.dev/spinnaker-community/docker
    GOROOT: /opt/hostedtoolcache/go/1.1[5](https://github.com/kskewes-sf/spin/runs/5532819187?check_suite_focus=true#step:12:5).15/x[6](https://github.com/kskewes-sf/spin/runs/5532819187?check_suite_focus=true#step:12:6)4
    LDFLAGS: -X github.com/spinnaker/spin/version.Version=1.26.0
version 1.26.0

We don't need extra job for test when `go test` is fast and we are
performing the same setup steps for `build` job.

Also Dockerfile doesn't have `go test` step.
@kskewes-sf kskewes-sf marked this pull request as ready for review March 14, 2022 21:52
# use service account flow defined at: https://github.com/google-github-actions/upload-cloud-storage#authenticating-via-service-account-key-json
with:
credentials_json: '${{ secrets.GAR_JSON_KEY }}'
- name: Upload spin CLI binaries to GCS
Copy link
Contributor Author

@kskewes-sf kskewes-sf Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is questionable about whether we want to publish binaries and container images on every merge master and release-* branch. It does create a lot of artifacts that one might need to sort through.

Currently in the GCS Bucket the folder naming convention is:

  1. spin/<tag>/..., and
  2. spin/<tag>-<date>/... - << perhaps this was done on merge master and other cadences? Can't tell because Jenkins is dead.

It's possible to sort the bucket to get to final releases but by default 1.17, etc will be at the end of the list of 800+ items shown.

The naming convention in this PR puts master and release-* commits into subfolder's.
This makes it easier to browse the bucket and filter for an artifact "in between" official releases. One can also search by git sha, etc.
It would be even easier to casually browse through if older spin/<tag>-<date>/ versions were deleted or moved to their own "older" folder.
Proposed convention:

  1. spin/<tag>/... for releases,
  2. spin/master/<git sha>-<date time>/...
  3. spin/release-1.26.x/<git sha>-<date time>/...
  4. spin/release-1.27.x/<git sha>-<date time>/...

- collapse version info gathering steps into single `build_variables` step
- collapse version info parts into single string and use everywhere.
- use short git sha: `(git rev-parse --short HEAD)`
@dbyron-sf
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Mar 18, 2022

update

✅ Branch has been successfully updated

@kskewes-sf kskewes-sf deleted the gha-c branch March 18, 2022 01:59
@dbyron-sf
Copy link
Contributor

@Mergifyio backport release-1.27.x

mergify bot pushed a commit that referenced this pull request Apr 28, 2022
* chore(ci): GHA - container image build and push

* fix(ci): for PR's build container without GAR login

* fix(ci): dont't run GHA build on forks

Each time a fork's master branch is resync'd with spinnaker/<repo> we
don't want to trigger GHA CI.

* chore(ci): GHA - Build and Publish spin binaries to GCS

Maintain existing behaviours:

shared:
- build for darwin, linux, windows, all on amd64, we can add aarch64 if
  wish.

on release:
- publish to `spinnaker-artifacts/spin/<release>/<os>/<arch>/spin(.exe)`
- publish `spinnaker-artifacts/spin/latest` text file with new version
  if version is newest (version sort). eg: 1.23.0 newer than 1.22.5.
- publish `spinnaker-artifacts/spin/<MAJOR.MINOR>.x-latest` text file
  with version number, eg: 1.23.0 or 1.23.1. Assuming we always do
  increment patch versions.

on merge master or release-* branch:
- publish to `spinnaker-artifacts/spin/<branch>/<git sha>-<datetime>/<os>/<arch>/spin(.exe)`
- this is different see next paragraph

Changes from previous behaviour:

Previous builds were always `spinnaker-artifacts/spin/<tag>-<datetime>/<os>/<arch>/spin(.exe)`
except for final release versions (1.22.0).
eg:
```
1.17.3-20201209030017/
1.17.3-20201210030017/
1.17.3/
```

However I believe it is easier to sort and review with the extra branch or
release number directory, eg:
```
master/<git-sha>-<datetime>/...
release-1.17.x/<git-sha>-<datetime>/...
```
This is also consistent with the container image tags now generated in GHA.

* chore(ci): Remove binary upload to GCS bucket script

This task has been moved into GHA per preceding commit.

* chore(ci): GHA - Test and build binaries before containers

We don't need extra job for test when `go test` is fast and we are
performing the same setup steps for `build` job.

Also Dockerfile doesn't have `go test` step.

* chore(ci): GHA - simplify build versioning

- collapse version info gathering steps into single `build_variables` step
- collapse version info parts into single string and use everywhere.
- use short git sha: `(git rev-parse --short HEAD)`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 95b72f7)

# Conflicts:
#	.github/workflows/build.yml
@mergify
Copy link
Contributor

mergify bot commented Apr 28, 2022

backport release-1.27.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants