Skip to content

Commit 0b25cef

Browse files
committed
add CI
1 parent e866788 commit 0b25cef

23 files changed

Lines changed: 1353 additions & 468 deletions
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Build container
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- '[0-9]+.[1-9][0-9]*.x'
8+
pull_request:
9+
branches:
10+
- 'main'
11+
- '[0-9]+.[1-9][0-9]*.x'
12+
paths-ignore:
13+
- "**.md"
14+
workflow_dispatch:
15+
16+
env:
17+
GO_VERSION: "~1.20"
18+
IMAGE_NAME: "valid8or-plugin-aws"
19+
defaults:
20+
run:
21+
shell: bash
22+
23+
jobs:
24+
prepare_ci_run:
25+
name: Prepare CI Run
26+
runs-on: ubuntu-22.04
27+
outputs:
28+
GIT_SHA: ${{ steps.extract_branch.outputs.GIT_SHA }}
29+
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
30+
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
31+
DATETIME: ${{ steps.get_datetime.outputs.DATETIME }}
32+
BUILD_TIME: ${{ steps.get_datetime.outputs.BUILD_TIME }}
33+
NON_FORKED_AND_NON_ROBOT_RUN: ${{ steps.get_run_type.outputs.NON_FORKED_AND_NON_ROBOT_RUN }}
34+
35+
steps:
36+
- name: Check out code
37+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
38+
39+
- name: Extract branch name
40+
id: extract_branch
41+
uses: keptn/gh-action-extract-branch-name@main
42+
43+
- name: Get current date and time
44+
id: get_datetime
45+
run: |
46+
DATETIME=$(date +'%Y%m%d%H%M')
47+
BUILD_TIME=$(date -u "+%F_%T")
48+
echo "DATETIME=$DATETIME" >> "$GITHUB_OUTPUT"
49+
echo "BUILD_TIME=$BUILD_TIME" >> "$GITHUB_OUTPUT"
50+
51+
- name: Get workflow run type
52+
id: get_run_type
53+
run: |
54+
NON_FORKED_AND_NON_ROBOT_RUN=${{ ( github.actor != 'renovate[bot]' && github.actor != 'dependabot[bot]' ) && ( github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository ) }}
55+
echo "github.actor != 'renovate[bot]' = ${{ github.actor != 'renovate[bot]' }}"
56+
echo "github.actor != 'dependabot[bot]' = ${{ github.actor != 'dependabot[bot]' }}"
57+
echo "github.event_name == 'push' = ${{ github.event_name == 'push' }}"
58+
echo "github.event.pull_request.head.repo.full_name == github.repository = ${{ github.event.pull_request.head.repo.full_name == github.repository }}"
59+
echo "NON_FORKED_AND_NON_ROBOT_RUN = $NON_FORKED_AND_NON_ROBOT_RUN"
60+
echo "NON_FORKED_AND_NON_ROBOT_RUN=$NON_FORKED_AND_NON_ROBOT_RUN" >> "$GITHUB_OUTPUT"
61+
62+
build_image:
63+
name: Build Container Image
64+
needs: prepare_ci_run
65+
runs-on: ubuntu-22.04
66+
env:
67+
BRANCH: ${{ needs.prepare_ci_run.outputs.BRANCH }}
68+
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
69+
BUILD_TIME: ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
70+
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
71+
RELEASE_REGISTRY: "localhost:5000/valid8or-plugin-aws"
72+
steps:
73+
- name: Check out code
74+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
75+
76+
- name: Set up Docker Buildx
77+
id: buildx
78+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2
79+
80+
- name: Build Docker Image
81+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
82+
with:
83+
context: .
84+
platforms: linux/amd64
85+
file: ./Dockerfile
86+
target: production
87+
tags: |
88+
${{ env.RELEASE_REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }}
89+
build-args: |
90+
GIT_HASH=${{ env.GIT_SHA }}
91+
RELEASE_VERSION=dev-${{ env.DATETIME }}
92+
BUILD_TIME=${{ env.BUILD_TIME }}
93+
builder: ${{ steps.buildx.outputs.name }}
94+
push: false
95+
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
96+
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
97+
outputs: type=docker,dest=/tmp/${{ env.IMAGE_NAME }}-image.tar
98+
99+
- name: Upload image as artifact
100+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
101+
with:
102+
name: ${{ env.IMAGE_NAME }}-image.tar
103+
path: /tmp/${{ env.IMAGE_NAME }}-image.tar
104+
105+
upload_images:
106+
name: Upload images to quay registry
107+
needs: [ prepare_ci_run, build_image ]
108+
if: github.event_name == 'push' && needs.prepare_ci_run.outputs.NON_FORKED_AND_NON_ROBOT_RUN == 'true' # only run on push to main/maintenance branches
109+
runs-on: ubuntu-22.04
110+
env:
111+
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
112+
BUILD_TIME: ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
113+
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
114+
permissions:
115+
packages: write # Needed for pushing images to the registry
116+
contents: read # Needed for checking out the repository
117+
steps:
118+
- name: Check out code
119+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
120+
121+
- name: Login to GitHub Container Registry
122+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
123+
with:
124+
registry: "quay.io"
125+
username: tgillson
126+
password: ${{ secrets.QUAY_TOKEN }}
127+
128+
- name: Set up Docker Buildx
129+
id: buildx
130+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2
131+
132+
- name: Build Docker Image
133+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
134+
with:
135+
context: .
136+
file: ./Dockerfile
137+
platforms: linux/amd64,linux/arm64
138+
target: production
139+
tags: |
140+
quay.io/spectrocloud-labs/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }}
141+
build-args: |
142+
GIT_HASH=${{ env.GIT_SHA }}
143+
RELEASE_VERSION=dev-${{ env.DATETIME }}
144+
BUILD_TIME=${{ env.BUILD_TIME }}
145+
builder: ${{ steps.buildx.outputs.name }}
146+
push: true
147+
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
148+
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}

.github/workflows/release.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '[0-9]+.[0-9]+.x'
8+
workflow_dispatch:
9+
10+
env:
11+
# Default minimum version of Go to support.
12+
DEFAULT_GO_VERSION: 1.19
13+
REGISTRY: ghcr.io
14+
GITHUB_PAGES_BRANCH: gh_pages
15+
16+
defaults:
17+
run:
18+
shell: bash
19+
20+
jobs:
21+
release-please:
22+
permissions:
23+
contents: write # for google-github-actions/release-please-action to create release commit
24+
pull-requests: write # for google-github-actions/release-please-action to create release PR
25+
runs-on: ubuntu-latest
26+
outputs:
27+
releases_created: ${{ steps.release.outputs.releases_created }}
28+
tag_name: ${{ steps.release.outputs.tag_name }}
29+
# Release-please creates a PR that tracks all changes
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
33+
34+
- uses: google-github-actions/release-please-action@ca6063f4ed81b55db15b8c42d1b6f7925866342d # v3
35+
id: release
36+
with:
37+
command: manifest
38+
token: ${{secrets.GITHUB_TOKEN}}
39+
default-branch: main
40+
41+
release-charts:
42+
needs: release-please
43+
permissions:
44+
contents: write
45+
runs-on: ubuntu-latest
46+
if: needs.release-please.outputs.releases_created == 'true'
47+
steps:
48+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
49+
- name: Publish Helm chart
50+
uses: stefanprodan/helm-gh-pages@master
51+
with:
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
charts_dir: chart
54+
charts_url: https://charts.spectrocloud-labs.io
55+
owner: spectrocloud-labs
56+
repository: charts
57+
branch: main
58+
commit_username: spectrocloud-labs-bot
59+
commit_email: bot@noreply.spectrocloud-labs.io
60+
61+
build-container:
62+
if: needs.release-please.outputs.releases_created == 'true'
63+
needs:
64+
- release-please
65+
runs-on: ubuntu-22.04
66+
permissions:
67+
contents: write
68+
packages: write
69+
id-token: write
70+
env:
71+
IMAGE_TAG: ghcr.io/spectrocloud-labs/valid8or-plugin-aws:${{ needs.release-please.outputs.tag_name }}
72+
IMAGE_NAME: valid8or-plugin-aws
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
76+
with:
77+
submodules: recursive
78+
79+
- name: Set up Docker Buildx
80+
id: buildx
81+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2
82+
83+
- name: Login to GitHub Container Registry
84+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
85+
with:
86+
registry: "quay.io"
87+
username: tgillson
88+
password: ${{ secrets.QUAY_TOKEN }}
89+
90+
- name: Build Docker Image
91+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
92+
with:
93+
context: .
94+
file: ./Dockerfile
95+
platforms: linux/amd64,linux/arm64
96+
target: production
97+
tags: |
98+
${{ env.IMAGE_TAG }}
99+
builder: ${{ steps.buildx.outputs.name }}
100+
push: true
101+
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_TAG }}
102+
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_TAG }}
103+
104+
- name: Generate SBOM
105+
uses: anchore/sbom-action@78fc58e266e87a38d4194b2137a3d4e9bcaf7ca1 # v0.14.3
106+
with:
107+
image: ${{ env.IMAGE_TAG }}
108+
artifact-name: sbom-${{ env.IMAGE_NAME }}
109+
output-file: ./sbom-${{ env.IMAGE_NAME }}.spdx.json
110+
111+
- name: Attach SBOM to release
112+
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
113+
with:
114+
tag_name: ${{ needs.release-please.outputs.tag_name }}
115+
files: ./sbom-${{ env.IMAGE_NAME }}.spdx.json

.github/workflows/test.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Run tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
env:
10+
GO_VERSION: "~1.20"
11+
12+
jobs:
13+
test-unit:
14+
name: Run Unit Tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4
21+
with:
22+
go-version: ${{ env.GO_VERSION }}
23+
24+
- name: Test
25+
run: go test -v ./...
26+
27+
test-chart:
28+
name: Run Helm Chart Tests
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Set up Helm
36+
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3
37+
with:
38+
version: v3.11.2
39+
40+
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4
41+
with:
42+
python-version: '3.9'
43+
check-latest: true
44+
45+
- name: Set up chart-testing
46+
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0
47+
48+
- name: Run chart-testing (list-changed)
49+
id: list-changed
50+
run: |
51+
changed=$(ct list-changed --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }})
52+
echo $changed
53+
echo "Hallo"
54+
if [[ -n "$changed" ]]; then
55+
echo "changed=true" >> "$GITHUB_OUTPUT"
56+
fi
57+
58+
- name: Run chart-testing (lint)
59+
if: steps.list-changed.outputs.changed == 'true'
60+
run: ct lint --validate-maintainers=false --check-version-increment=false --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }}
61+
62+
- name: Create kind cluster
63+
if: steps.list-changed.outputs.changed == 'true'
64+
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
65+
66+
- name: Run chart-testing (install)
67+
if: steps.list-changed.outputs.changed == 'true'
68+
run: ct install --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }}

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{".":"0.0.1"}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.20 as builder
2+
FROM golang:1.20 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -28,7 +28,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
2828

2929
# Use distroless as minimal base image to package the manager binary
3030
# Refer to https://github.com/GoogleContainerTools/distroless for more details
31-
FROM gcr.io/distroless/static:nonroot
31+
FROM gcr.io/distroless/static:nonroot AS production
3232
WORKDIR /
3333
COPY --from=builder /workspace/manager .
3434
USER 65532:65532

0 commit comments

Comments
 (0)