generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9951680
commit 6218806
Showing
75 changed files
with
10,232 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
# Ignore build and test binaries. | ||
bin/ | ||
testbin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
name: Build artifacts | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
|
||
concurrency: build-${{ github.ref }} | ||
|
||
env: | ||
HELM_VERSION: v3.11.3 | ||
KIND_VERSION: v0.19.0 | ||
REGISTRY: ghcr.io | ||
CHART_DIRECTORY: chart | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Check that license header boilerplate is correct | ||
uses: sap/cs-actions/check-go-license-boilerplate@main | ||
with: | ||
boilerplate-path: hack/boilerplate.go.txt | ||
|
||
- name: Check that license headers are correct | ||
uses: sap/cs-actions/check-go-license-headers@main | ||
with: | ||
boilerplate-path: hack/boilerplate.go.txt | ||
|
||
- name: Check that generated artifacts are up-to-date | ||
run: | | ||
make generate | ||
echo "Running 'git status' ..." | ||
if [ -z "$(git status --porcelain)" ]; then | ||
echo "Generated artifacts are up-to-date." | ||
else | ||
>&2 echo "Generated artifacts are not up-to-date; probably 'make generate' was not run before committing." | ||
exit 1 | ||
fi | ||
- name: Check that manifests are up-to-date | ||
run: | | ||
make manifests | ||
echo "Running 'git status' ..." | ||
if [ -z "$(git status --porcelain)" ]; then | ||
echo "Manifests are up-to-date." | ||
else | ||
>&2 echo "Manifests are not up-to-date; probably 'make manifests' was not run before committing." | ||
exit 1 | ||
fi | ||
- name: Run tests | ||
run: | | ||
make envtest | ||
KUBEBUILDER_ASSETS=$(pwd)/bin/k8s/current E2E_ENABLED=${{ github.event_name == 'push' }} go test -count 1 ./... | ||
build-docker: | ||
name: Build Docker image | ||
runs-on: ubuntu-22.04 | ||
needs: test | ||
permissions: | ||
contents: read | ||
outputs: | ||
image-archive: image.tar | ||
image-repository: ${{ steps.prepare-repository-name.outputs.repository }} | ||
image-tag: ${{ steps.extract-metadata.outputs.version }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Prepare repository name | ||
id: prepare-repository-name | ||
run: | | ||
repository=$REGISTRY/${{ github.repository }} | ||
echo "repository=${repository,,}" >> $GITHUB_OUTPUT | ||
- name: Prepare custom labels for Docker | ||
id: extract-custom-labels | ||
run: | | ||
echo "labels<<EOF" >> $GITHUB_OUTPUT | ||
for c in pkg/operator/data/charts/*/Chart.yaml; do | ||
name=$(yq .name $c) | ||
version=$(yq .version $c) | ||
app_version=$(yq .appVersion $c) | ||
echo "com.sap.cs.image.content.charts.$name.version=$version" >> $GITHUB_OUTPUT | ||
if [ ! -z "$app_version" ]; then | ||
echo "com.sap.cs.image.content.charts.$name.app-version=$app_version" >> $GITHUB_OUTPUT | ||
fi | ||
done | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: extract-metadata | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ steps.prepare-repository-name.outputs.repository }} | ||
labels: ${{ steps.extract-custom-labels.outputs.labels }} | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
context: . | ||
cache-from: | | ||
type=gha,scope=sha-${{ github.sha }} | ||
type=gha,scope=${{ github.ref_name }} | ||
type=gha,scope=${{ github.base_ref || 'main' }} | ||
type=gha,scope=main | ||
cache-to: | | ||
type=gha,scope=sha-${{ github.sha }},mode=max | ||
type=gha,scope=${{ github.ref_name }},mode=max | ||
outputs: | | ||
type=oci,dest=${{ runner.temp }}/image.tar | ||
tags: ${{ steps.extract-metadata.outputs.tags }} | ||
labels: ${{ steps.extract-metadata.outputs.labels }} | ||
|
||
- name: Upload Docker image archive | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: image.tar | ||
path: ${{ runner.temp }}/image.tar | ||
|
||
test-helm: | ||
name: Run Helm chart tests | ||
runs-on: ubuntu-22.04 | ||
needs: build-docker | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: azure/setup-helm@v3 | ||
with: | ||
version: ${{ env.HELM_VERSION }} | ||
|
||
- name: Lint Helm chart | ||
run: | | ||
helm lint $CHART_DIRECTORY | ||
- name: Create Kind cluster | ||
uses: helm/kind-action@v1 | ||
with: | ||
version: ${{ env.KIND_VERSION }} | ||
cluster_name: kind | ||
|
||
- name: Show Kubernetes version | ||
run: | | ||
kubectl version | ||
- name: Download Docker image archive | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{ needs.build-docker.outputs.image-archive }} | ||
path: ${{ runner.temp }} | ||
|
||
- name: Load Docker image archive into Kind cluster | ||
run: | | ||
kind load image-archive ${{ runner.temp }}/${{ needs.build-docker.outputs.image-archive }} | ||
- name: Install Helm chart and deploy sample component | ||
run: | | ||
release_name=$(yq .name $CHART_DIRECTORY/Chart.yaml) | ||
kubectl create ns cop-system | ||
helm -n cop-system upgrade -i $release_name --wait --timeout 5m \ | ||
--set image.repository=${{ needs.build-docker.outputs.image-repository }} \ | ||
--set image.tag=${{ needs.build-docker.outputs.image-tag }} \ | ||
$CHART_DIRECTORY | ||
kubectl create ns component-system | ||
kubectl -n component-system apply -f examples/sample.yaml | ||
kubectl -n component-system wait -f examples/sample.yaml --for condition=Ready --timeout 120s | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
name: Publish artifacts | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
concurrency: release-${{ github.event.release.tag_name }} | ||
|
||
env: | ||
REGCTL_VERSION: v0.4.8 | ||
REGISTRY: ghcr.io | ||
CHART_DIRECTORY: chart | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
validate: | ||
name: Run validations | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Validate chart version/appVersion | ||
run: | | ||
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml) | ||
app_version=$(yq .appVersion $CHART_DIRECTORY/Chart.yaml) | ||
if [ "v$chart_version" != "${{ github.event.release.tag_name }}" ]; then | ||
>&2 echo "Version in $CHART_DIRECTORY/Chart.yaml ($chart_version) does not match release version (${{ github.event.release.tag_name }})." | ||
exit 1 | ||
fi | ||
if [ "$app_version" != "${{ github.event.release.tag_name }}" ]; then | ||
>&2 echo "AppVersion in $CHART_DIRECTORY/Chart.yaml ($app_version) does not match release version (${{ github.event.release.tag_name }})." | ||
exit 1 | ||
fi | ||
publish-docker: | ||
name: Publish Docker image | ||
runs-on: ubuntu-22.04 | ||
needs: validate | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
|
||
- name: Prepare repository name | ||
id: prepare-repository-name | ||
run: | | ||
repository=$REGISTRY/${{ github.repository }} | ||
echo "repository=${repository,,}" >> $GITHUB_OUTPUT | ||
- name: Prepare custom labels for Docker | ||
id: extract-custom-labels | ||
run: | | ||
echo "labels<<EOF" >> $GITHUB_OUTPUT | ||
for c in pkg/operator/data/charts/*/Chart.yaml; do | ||
name=$(yq .name $c) | ||
version=$(yq .version $c) | ||
app_version=$(yq .appVersion $c) | ||
echo "com.sap.cs.image.content.charts.$name.version=$version" >> $GITHUB_OUTPUT | ||
if [ ! -z "$app_version" ]; then | ||
echo "com.sap.cs.image.content.charts.$name.app-version=$app_version" >> $GITHUB_OUTPUT | ||
fi | ||
done | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: extract-metadata | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ steps.prepare-repository-name.outputs.repository }} | ||
labels: ${{ steps.extract-custom-labels.outputs.labels }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
context: . | ||
cache-from: | | ||
type=gha,scope=sha-${{ github.sha }} | ||
type=gha,scope=${{ github.ref_name }} | ||
type=gha,scope=${{ github.base_ref || 'main' }} | ||
type=gha,scope=main | ||
cache-to: | | ||
type=gha,scope=sha-${{ github.sha }},mode=max | ||
type=gha,scope=${{ github.ref_name }},mode=max | ||
push: true | ||
tags: ${{ steps.extract-metadata.outputs.tags }} | ||
labels: ${{ steps.extract-metadata.outputs.labels }} | ||
|
||
publish-crds: | ||
name: Publish CRD image | ||
runs-on: ubuntu-22.04 | ||
needs: validate | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup regctl | ||
uses: regclient/actions/regctl-installer@main | ||
with: | ||
release: ${{ env.REGCTL_VERSION }} | ||
install-dir: ${{ runner.temp }}/bin | ||
|
||
- name: Log in to the registry | ||
# regctl-login action is currently broken ... | ||
# uses: regclient/actions/regctl-login@main | ||
# with: | ||
# registry: ${{ env.REGISTRY }} | ||
# username: ${{ github.actor }} | ||
# password: ${{ github.token }} | ||
run: | | ||
regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }} | ||
- name: Build and push artifact | ||
run: | | ||
cd crds | ||
repository=$REGISTRY/${{ github.repository }}/crds | ||
tar cvz * | regctl artifact put -m application/gzip ${repository,,}:${{ github.event.release.tag_name }} | ||
Oops, something went wrong.