Skip to content

Commit

Permalink
adding github files and allow injecting image
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Mar 11, 2024
1 parent c761502 commit 59b3915
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
24 changes: 24 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Description

<!-- Fill-in description here -->

## Dependencies

<!-- List here any related PRs with links, that need to be pulled also for testing -->
n/a

## Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

* [ ] Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix _(in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes)._
* [ ] Does this PR require product documentation?
* [ ] If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
* [ ] Does this PR require a product release notes entry?
* [ ] If so, fill in "Release Note Text" in the JIRA.
* [ ] Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
* [ ] If so, make sure it is described in the JIRA ticket.
* QE requirements (check 1 from the list):
* [ ] Standard QE validation, with pre-merge tests unless stated otherwise.
* [ ] Regression tests only (e.g. refactoring with no user-facing change).
* [ ] No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).
8 changes: 8 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
categories:
- title: Breaking changes 🛠
labels:
- breaking-change
- title: Non-breaking changes
labels:
- "*"
15 changes: 15 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: greetings

on: [issues]

jobs:
greeting:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Congratulations for contributing your first netobserv-cli issue'
34 changes: 34 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: pull request checks

on:
pull_request:
branches: ['*']

jobs:
build-test:
name: Build, lint, test
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']

steps:
- name: install make
run: sudo apt-get install make
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
- name: run build
run: make build && git diff --exit-code
- name: run unit tests
run: make test
- name: Report coverage
uses: codecov/[email protected]
with:
files: ./cover.out
flags: unittests
fail_ci_if_error: false
args: --timeout 3m0s
66 changes: 66 additions & 0 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build and push to quay.io
on:
push:
branches: [ main, release-*, workflow-test ]

env:
WF_REGISTRY_USER: netobserv+github_ci
WF_ORG: netobserv
WF_MULTIARCH_TARGETS: amd64 arm64 ppc64le s390x
WF_VERSION: ${{ github.ref_name }}

jobs:
push-image:
name: push image
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- name: install make
run: sudo apt-get install make
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.WF_REGISTRY_USER }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: get short sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: build and push manifest with images
run: |
MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} make images
MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.short_sha }} OCI_BUILD_OPTS="--label quay.expires-after=2w" make images
if [[ "main" == "$WF_VERSION" ]]; then
MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=latest make images
fi
codecov:
name: Codecov upload
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- name: install make
run: sudo apt-get install make
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
- name: Test
run: make test
- name: Report coverage
uses: codecov/[email protected]
with:
files: ./cover.out
flags: unittests
fail_ci_if_error: false
60 changes: 60 additions & 0 deletions .github/workflows/push_image_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and push PR image to quay.io
on:
pull_request_target:
types: [labeled]

env:
WF_REGISTRY_USER: netobserv+github_ci
WF_REGISTRY: quay.io/netobserv
WF_IMAGE: network-observability-cli
WF_ORG: netobserv

jobs:
push-pr-image:
if: ${{ github.event.label.name == 'ok-to-test' }}
name: push PR image
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- name: install make
run: sudo apt-get install make
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
with:
ref: "refs/pull/${{ github.event.number }}/merge"
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.WF_REGISTRY_USER }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: get short sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: build and push manifest with images
run: OCI_BUILD_OPTS="--label quay.expires-after=2w" IMAGE_ORG=${{ env.WF_ORG }} IMAGE=${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }} make images
- uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `New image:
${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }}
It will expire after two weeks.
To deploy this build, update the CLI images in the corresponding YAML files under res folder.
Then run:
\`\`\`bash
USER=netobserv VERSION=${{ env.short_sha }} make oc-commands
\`\`\`
`
})
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: release to quay.io
on:
push:
tags: [v*]

env:
WF_REGISTRY_USER: netobserv+github_ci
WF_ORG: netobserv
WF_MULTIARCH_TARGETS: amd64 arm64 ppc64le s390x

jobs:
push-image:
name: push image
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- name: checkout
uses: actions/checkout@v3
- name: validate tag
run: |
tag=`git describe --exact-match --tags 2> /dev/null`
if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "$tag is a valid release tag"
set -e
echo "tag=$tag" >> $GITHUB_ENV
else
echo "$tag is NOT a valid release tag"
exit 1
fi
- name: install make
run: sudo apt-get install make
- name: set up go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.WF_REGISTRY_USER }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: build and push manifest with images
run: MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.tag }} make images
15 changes: 15 additions & 0 deletions .github/workflows/rm-ok-to-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Remove ok-to-test
on:
pull_request_target:
types: [synchronize,reopened]

jobs:
rm-ok-to-test:
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test')
runs-on: ubuntu-latest
name: Remove ok-to-test
steps:
- uses: actions-ecosystem/action-remove-labels@v1
with:
labels: ok-to-test
fail_on_error: true
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ prereqs: ## Test if prerequisites are met, and installing missing dependencies
##@ Develop

.PHONY: compile
compile:
compile: ## Compile project
@echo "### Compiling project"
GOARCH=${GOARCH} go build -ldflags "-X main.version=${VERSION} -X 'main.buildVersion=${BUILD_VERSION}' -X 'main.buildDate=${BUILD_DATE}'" -mod vendor -a -o $(OUTPUT)

.PHONY: build
build: fmt lint compile ## Build project (fmt + lint + compile)

.PHONY: test
test: ## Unit test
@echo "### TODO, unit tests not yet implemented"

.PHONY: fmt
fmt: ## Run go fmt against code.
@echo "### Formatting code"
Expand All @@ -100,7 +107,7 @@ clean:
.PHONY: oc-commands
oc-commands: ## Generate oc plugins and add them to /usr/bin/
@echo "### Generating oc-commands"
./scripts/inject.sh $(DIST_DIR)
./scripts/inject.sh $(DIST_DIR) $(IMAGE)
sudo cp -a ./build/. /usr/bin/

##@ Images
Expand Down
7 changes: 7 additions & 0 deletions scripts/inject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ sed -i -e '/flowAgentYAMLContent/{r ./res/flow-capture.yml' -e 'd}' ./tmp/functi
sed -i -e '/packetAgentYAMLContent/{r ./res/packet-capture.yml' -e 'd}' ./tmp/functions.sh
sed -i -e '/collectorServiceYAMLContent/{r ./res/collector-service.yml' -e 'd}' ./tmp/functions.sh

if [ -z "$2" ]; then
echo "image not provided, keeping current ones"
else
echo "updating CLI images to $2"
sed -i "/ image:/c\ image: $2" ./tmp/functions.sh
fi

# inject updated functions to oc commands
sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-flows
sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-packets
Expand Down

0 comments on commit 59b3915

Please sign in to comment.