Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
chore: Introduce new CI and pre-release pipeline, level up helm charts (
Browse files Browse the repository at this point in the history
#112)

* chore: Introduce new pre-release and release pipeline

Signed-off-by: Christian Kreuzberger <[email protected]>

* Adapt helm charts and Dockerfile to be compatible with build scripts and skaffold

Signed-off-by: Christian Kreuzberger <[email protected]>

* review comments

Signed-off-by: Christian Kreuzberger <[email protected]>

* Added value for pubsub_topic for distributor

Signed-off-by: Christian Kreuzberger <[email protected]>
  • Loading branch information
christian-kreuzberger-dtx authored Dec 21, 2021
1 parent b65263d commit cc1da80
Show file tree
Hide file tree
Showing 23 changed files with 347 additions and 349 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
README.md
.git
.idea
skaffold.yaml
reviewdog.yml
charts/
deploy/
.github/
installer/
18 changes: 18 additions & 0 deletions .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Unit Tests'
description: 'Run unit tests using go'
inputs:
GO_VERSION:
default: "1.16"
env:
GO111MODULE: "on"
GOPROXY: "https://proxy.golang.org"
runs:
using: "composite"
steps:
- name: Install Go
uses: actions/[email protected]
with:
go-version: ${{ inputs.GO_VERSION }}
- name: Test
shell: bash
run: go test -v ./...
148 changes: 88 additions & 60 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0 # need to checkout "all commits" for certain features to work (e.g., get all changed files)

Expand Down Expand Up @@ -97,93 +97,121 @@ jobs:
############################################################################
# Unit tests #
############################################################################
unit-tests:
test:
name: Unit Tests
needs: prepare_ci_run
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16.2
- name: Checkout Code
- name: Check out repository
uses: actions/checkout@v2

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Test
run: go test -coverprofile=coverage.txt -covermode=atomic -v ./...
working-directory: .
- name: Unit tests
uses: ./.github/actions/unit-tests

############################################################################
# Build Docker Image #
############################################################################
docker_build:
needs: [prepare_ci_run, unit-tests]
needs: [prepare_ci_run]
name: Docker Build
runs-on: ubuntu-20.04
env:
BRANCH: ${{ needs.prepare_ci_run.outputs.BRANCH }}
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATE }}${{ needs.prepare_ci_run.outputs.TIME }}
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- id: docker_login
name: Docker Login
# only run docker login on pushes; also for PRs, but only if this is not a fork
if: (github.event_name == 'push') || (github.event.pull_request.head.repo.full_name == github.repository)
# note: GH does not allow to access secrets for PRs from a forked repositories due to security reasons
# that's fine, but it means we can't push images to dockerhub
uses: docker/login-action@v1
- name: Docker Build
id: docker_build
uses: keptn/gh-automation/.github/actions/[email protected]
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- id: docker_build_service
name: Docker Build Service
uses: keptn/gh-action-build-docker-image@master
with:
VERSION: ${{ env.VERSION }}
IMAGE_NAME: "${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}"
DATETIME: ${{ env.DATETIME }}

- id: docker_build_initcontainer
name: Docker Build InitContainer
uses: keptn/gh-action-build-docker-image@master
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
PUSH: ${{(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)}}

- name: Docker Build Initcontainer
id: docker_build_initcontainer
uses: keptn/gh-automation/.github/actions/[email protected]
with:
VERSION: ${{ env.VERSION }}
IMAGE_NAME: "${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}"
DATETIME: ${{ env.DATETIME }}
FILE: ${{ env.DOCKERFILE_INITCONTAINER }}

- id: create_docker_build_report
name: Create Docker Build Report
run: |
echo "The following Docker Images have been built: " > docker_build_report_final.txt
cat docker_build_report.txt >> docker_build_report_final.txt || echo "* No images have been built or uploaded" >> docker_build_report_final.txt
echo "---"
cat docker_build_report_final.txt
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
DOCKERFILE: ${{ env.DOCKERFILE_INITCONTAINER }}
PUSH: ${{(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)}}

- id: report_docker_build_to_pr
# Comment the docker build report to the PR
# This only works for PRs coming from inside of the repo, not from forks
name: Report Docker Build to PR
if: (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.repository)
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: docker_build_report_final.txt
recreate: true
recreate: true
header: test
message: |
The following Docker Images have been built:
* ${{ fromJSON(steps.docker_build.outputs.BUILD_METADATA)['image.name'] }}
* ${{ fromJSON(steps.docker_build_initcontainer.outputs.BUILD_METADATA)['image.name'] }}
helm_chart_build:
needs: [prepare_ci_run, docker_build]
name: Build Helm Charts
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
steps:
- name: Checkout Code
uses: actions/[email protected]

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Build Helm Charts
id: build_helm_charts
run: ./gh-actions-scripts/build_helm_chart.sh "${VERSION}" "${VERSION}.${DATETIME}" "${IMAGE}"

- name: Upload Helm Chart as an artifact
id: upload_helm_chart
uses: actions/upload-artifact@v2
with:
name: helm-charts
path: installer/*.tgz

linter_build:
needs: [prepare_ci_run]
name: Build Linter
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Run make
run: make build-lint

- name: Upload Linter binaries as an artifact
id: upload_helm_chart
uses: actions/upload-artifact@v2
with:
name: linter
path: bin/job-lint-*
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Package helm
uses: WyriHaximus/github-action-helm3@v2
with:
exec: helm package helm
exec: helm package chart

- name: Upload Linux
uses: actions/[email protected]
Expand Down
109 changes: 109 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Create Pre-Release
on:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Unit tests
uses: ./.github/actions/unit-tests

pre-release:
needs: test
name: Pre-Release
uses: keptn/gh-automation/.github/workflows/[email protected]

docker_build:
needs: [pre-release]
name: Docker Build
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.pre-release.outputs.RELEASE_TAG }}
steps:
- name: Checkout Code
uses: actions/[email protected]

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Docker Build
id: docker_build_service
uses: keptn/gh-automation/.github/actions/[email protected]
with:
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}

- name: Docker Build Initcontainer
id: docker_build_initcontainer
uses: ./.github/actions/docker-build
with:
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
DOCKERFILE: ${{ env.DOCKERFILE_INITCONTAINER }}

helm_chart_build:
needs: [pre-release, docker_build]
name: Build Helm Charts
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.pre-release.outputs.RELEASE_TAG }}
steps:
- name: Checkout Code
uses: actions/[email protected]

- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v3
with:
env-file: .ci_env

- name: Build Helm Charts
id: build_helm_charts
run: ./gh-actions-scripts/build_helm_chart.sh "${VERSION}" "${VERSION}" "${IMAGE}"

- name: Upload Helm Chart as release asset
env:
RELEASE_TAG: ${{ needs.pre-release.outputs.RELEASE_TAG }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "$RELEASE_TAG" installer/*.tgz
linter_build:
needs: [pre-release]
name: Build Linter
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.pre-release.outputs.RELEASE_TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Run make
run: make build-lint

- name: Rename binaries
run: |
mv ./bin/job-lint-linux-amd64 job-lint-linux-amd64-$VERSION
mv ./bin/job-lint-windows-amd64 job-lint-windows-amd64-$VERSION.exe
mv ./bin/job-lint-darwin-amd64 job-lint-darwin-amd64-$VERSION
- name: Upload release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "$VERSION" bin/job-lint-*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ main
.idea/*
# but allow .idea shared run configurations
!.idea/runConfigurations/

# ignore installer folder (packaged helm chart)
installer/
15 changes: 0 additions & 15 deletions .idea/runConfigurations/Develop_on_Kubernetes.xml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/runConfigurations/Run_on_Kubernetes.xml

This file was deleted.

Loading

0 comments on commit cc1da80

Please sign in to comment.