-
Notifications
You must be signed in to change notification settings - Fork 21
Migrate from Drone to GH Actions #23
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
Merged
andreas-kupries
merged 4 commits into
rancher:master
from
andreas-kupries:ak-44988-sure-7963-gh-actions
May 3, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b4c920
feat: draft gh action flows for test builds, and publication.
andreas-kupries 69d114a
Added release flow tested in PR #25. Only change is in trigger condit…
andreas-kupries 301d159
address comments - use multi-dim matrix, easier access to os, arch parts
andreas-kupries dd3c282
address comments
andreas-kupries File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,106 @@ | ||
name: CI Build and Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
IMAGE: rancher/kube-api-auth | ||
|
||
permissions: | ||
contents: read | ||
security-events: write # upload Trivy Sarif results | ||
|
||
jobs: | ||
linter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get Sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: false | ||
|
||
- name: Validate the sources | ||
run: | | ||
./scripts/validate | ||
# Except for linting. That is done through the proper GH action | ||
|
||
- name: Lint sources | ||
uses: golangci/golangci-lint-action@v4 | ||
|
||
- name: Test | ||
run: ./scripts/test | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- linter | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- linux | ||
arch: | ||
- amd64 | ||
- arm64 | ||
steps: | ||
- name: Prepare Matrix Instance | ||
run: | | ||
echo "GOOS=${{ matrix.os }}" | ||
echo "GOOS=${{ matrix.os }}" >> $GITHUB_ENV | ||
echo "GOARCH=${{ matrix.arch }}" | ||
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV | ||
echo "ARCH=${{ matrix.arch }}" | ||
echo "ARCH=${{ matrix.arch }}" >> $GITHUB_ENV | ||
|
||
- name: Get Sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Determine Tag | ||
id: get-TAG | ||
run: | | ||
export TAG=$(git describe --always) | ||
echo "TAG=$TAG" | ||
echo "TAG=$TAG" >> "$GITHUB_ENV" | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: false | ||
|
||
- name: Build | ||
run: | | ||
./scripts/build | ||
echo Stage binary for packaging step | ||
cp -rv ./bin/* ./package/ | ||
|
||
- name: Package up into container image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: package | ||
push: false | ||
tags: ${{ env.IMAGE }}:${{ env.TAG }}-${{ env.ARCH }} | ||
file: package/Dockerfile | ||
|
||
- name: Scan for security vulnerabilities using Trivy | ||
uses: aquasecurity/[email protected] | ||
with: | ||
image-ref: ${{ env.IMAGE }}:${{ env.TAG }}-${{ env.ARCH }} | ||
ignore-unfixed: true | ||
vuln-type: 'os,library' | ||
severity: 'CRITICAL,HIGH' | ||
format: 'sarif' | ||
output: 'trivy-results.sarif' | ||
|
||
- name: Upload Trivy scan results to GitHub Security tab | ||
uses: github/codeql-action/upload-sarif@v3 | ||
if: always() | ||
with: | ||
sarif_file: 'trivy-results.sarif' |
This file contains hidden or 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,150 @@ | ||
name: CI Build And Publish Release | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
IMAGE: rancher/kube-api-auth | ||
|
||
jobs: | ||
push: | ||
permissions: | ||
contents: read | ||
id-token: write # this is important, it's how we authenticate with Vault | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- linux | ||
arch: | ||
- amd64 | ||
- arm64 | ||
steps: | ||
- name: Prepare Matrix Instance | ||
run: | | ||
echo "PLATFORM_PAIR=${{ matrix.os }}-${{ matrix.arch }}" | ||
echo "PLATFORM_PAIR=${{ matrix.os }}-${{ matrix.arch }}" >> $GITHUB_ENV | ||
echo "GOOS=${{ matrix.os }}" | ||
echo "GOOS=${{ matrix.os }}" >> $GITHUB_ENV | ||
echo "GOARCH=${{ matrix.arch }}" | ||
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV | ||
echo "ARCH=${{ matrix.arch }}" | ||
echo "ARCH=${{ matrix.arch }}" >> $GITHUB_ENV | ||
|
||
- name: Retrieve Docker Hub Credentials From Vault | ||
uses: rancher-eio/read-vault-secrets@main | ||
with: | ||
secrets: | | ||
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKERHUB_USERNAME ; | ||
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKERHUB_PASSWORD | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ env.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Get Sources | ||
uses: actions/checkout@v4 | ||
|
||
- name: Docker Meta Data Setup | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: false | ||
|
||
- name: Build and stage | ||
run: | | ||
./scripts/build | ||
# Stage binary for packaging step | ||
cp -r ./bin/* ./package/ | ||
|
||
- name: Build image and push by digest | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: package | ||
file: package/Dockerfile | ||
platforms: ${{ matrix.os }}/${{ matrix.arch }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true | ||
|
||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
|
||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests-${{ env.PLATFORM_PAIR }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
merge: | ||
permissions: | ||
contents: read | ||
id-token: write # this is important, it's how we authenticate with Vault | ||
runs-on: ubuntu-latest | ||
needs: | ||
- push | ||
steps: | ||
- name: Retrieve Docker Hub Credentials From Vault | ||
uses: rancher-eio/read-vault-secrets@main | ||
with: | ||
secrets: | | ||
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKERHUB_USERNAME ; | ||
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKERHUB_PASSWORD | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ env.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-* | ||
merge-multiple: true | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE }} | ||
|
||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create \ | ||
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ env.IMAGE }}@sha256:%s ' *) | ||
|
||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.