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

Add a command to push to OCI registries #362

Merged
merged 20 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `package-and-push-oci` command.

## [4.16.0] - 2022-04-13

### Changed
Expand Down Expand Up @@ -54,7 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Update `architect` version to [`v6.3.0`](https://github.com/giantswarm/architect/releases/tag/v6.3.0).
- Updates Go version to 1.17.8.
- Update Go version used in `machine install` command to 1.17.8.
- Update Go version used in `machine install` command to 1.17.8.

## [4.13.0] - 2022-02-18

Expand Down
96 changes: 96 additions & 0 deletions src/commands/package-and-push-oci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
parameters:
app_catalog:
kubasobon marked this conversation as resolved.
Show resolved Hide resolved
type: "string"
default: "oci://giantswarmpublic.azurecr.io/charts/"
description: |
Set this to an OCI registry with a specific subpath, e.g.
`oci://giantswarmpublic.azurecr.io/charts/`. Last slash is mandatory.
app_catalog_test:
type: "string"
default: "oci://giantswarmpublic.azurecr.io/test_charts/"
description: |
Set this to an OCI registry with a specific subpath, e.g.
`oci://giantswarmpublic.azurecr.io/test_charts/`. Last slash is mandatory.
chart:
type: "string"
on_tag:
type: boolean
default: true
description: |
When this is `false`, commits to `master` will be pushed to `app_catalog` instead of `app_catalog_test`.
Set this to `false` for deployments that follow a a master branch for production releases rather than
using tags (the default).
explicit_allow_chart_name_mismatch:
type: boolean
default: false
description: |
If 'explicit_allow_chart_name_mismatch' is set to true, the name of the chart can be anything.
Otherwise the name set in the 'chart' parameter must start with the repository name and optionally continue with '-app'.
Does not have any effect for 'executor: app-build-suite'.
persist_chart_archive:
type: boolean
default: false
description: |
When this is `true`, the packaged chart archive will be persisted to the workspace.
Set this to `true`, if you're planning to execute tests using app-test-suite.
steps:
- when:
condition: << parameters.on_tag >>
steps:
- run:
name: "architect/package-and-push: Determine target app catalog based on presence of tag"
command: |
[ -z ${CIRCLE_TAG} ] && echo -n '<< parameters.app_catalog_test >>' | tee .app_catalog_name || echo -n '<< parameters.app_catalog >>' | tee .app_catalog_name
echo -n ${CIRCLE_TAG} | tee .reference
- unless:
condition: << parameters.on_tag >>
steps:
- run:
name: "architect/package-and-push: Determine target app catalog based on branch name"
command: |
[[ ${CIRCLE_BRANCH} == master ]] && echo -n '<< parameters.app_catalog >>' | tee .app_catalog_name || echo -n '<< parameters.app_catalog_test >>' | tee .app_catalog_name
echo -n ${CIRCLE_SHA1} | tee .reference
- unless:
condition: << parameters.explicit_allow_chart_name_mismatch >>
steps:
- run:
name: Verify chart parameters
command: |
CHART_NAME="<< parameters.chart >>"
[[ ${CHART_NAME%-app} == ${CIRCLE_PROJECT_REPONAME%-app} ]] && exit 0 || echo "chart parameter value should match ${CIRCLE_PROJECT_REPONAME%-app} or ${CIRCLE_PROJECT_REPONAME%-app}-app" ; exit 1
- run:
name: Package the chart archive
command: |
mkdir build && helm package ./helm/<< parameters.chart >> --destination ./build
- when:
condition: << parameters.persist_chart_archive >>
steps:
- persist_to_workspace:
root: build
paths:
- "<< parameters.chart >>*.tgz"
- run:
name: Push chart archive to OCI registy app catalog
kubasobon marked this conversation as resolved.
Show resolved Hide resolved
command: |
readonly app_catalog_name="$(cat .app_catalog_name)"
readonly reference="$(cat .reference)"

ret=1
tries=4
for i in $(seq 1 $tries) ; do
echo "====> Attempt $i: Running: helm push ../build/*.tgz $app_catalog_name"
set +e
helm push ../build/*.tgz $app_catalog_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a stupid question: Where does helm actually come from here? Is it just installed by default? And should we verify that the version is recent enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

architect-orb uses architect's Dockerfile as a base image. We install a bunch of binaries in that Dockerfile, including helm. I've recently updated architect (https://github.com/giantswarm/architect/pull/728/files), and architect-orb is already using the latest release.

ret=$?
set -e

[[ $ret -eq 0 ]] && exit $ret

sleep 5
done

echo "Giving up after $tries failures." >&2
echo "Error pushing changes. See known errors in:" >&2
echo "https://github.com/giantswarm/architect-orb/blob/master/README.md#push-to-app-catalog" >&2

exit $ret