Skip to content

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .github/workflows/ci.yml
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'
150 changes: 150 additions & 0 deletions .github/workflows/release.yml
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 }}
Loading