Skip to content
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

ci: move from drone ci to github actions #30

Merged
merged 2 commits into from
Apr 25, 2024
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
157 changes: 0 additions & 157 deletions .drone.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Main Build and Publish

on:
push:
branches:
- main

jobs:
build-main:
uses: ./.github/workflows/template-build.yml
with:
release-tag-name: ${{ github.ref_name }}-head
push: true
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Pull Request Build

on:
pull_request:

jobs:
build-pr:
uses: ./.github/workflows/template-build.yml
with:
release-tag-name: pull-${{ github.event.number }}
push: false
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master
Expand All @@ -23,6 +23,6 @@ jobs:
severity: 'CRITICAL'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
14 changes: 14 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Tag Build and Publish

on:
push:
tags:
- v**

jobs:
build-tag:
uses: ./.github/workflows/template-build.yml
with:
release-tag-name: ${{ github.ref_name }}
push: true
secrets: inherit
79 changes: 79 additions & 0 deletions .github/workflows/template-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
on:
workflow_call:
inputs:
release-tag-name:
required: true
type: string
push:
required: true
type: boolean

env:
repo: "rancher"
controllerImageName: "harvester-vm-dhcp-controller"
agentImageName: "harvester-vm-dhcp-agent"
webhookImageName: "harvester-vm-dhcp-webhook"

jobs:
dapper-build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run dapper
run: make ci

- name: Read some Secrets
uses: rancher-eio/read-vault-secrets@main
if: ${{ inputs.push == true }}
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD

- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ inputs.push == true }}
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}

- name: Docker Build (Controller)
uses: docker/build-push-action@v5
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
file: package/Dockerfile
push: ${{ inputs.push }}
tags: ${{ env.repo }}/${{ env.controllerImageName }}:${{ inputs.release-tag-name }}

- name: Docker Build (Agent)
uses: docker/build-push-action@v5
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
file: package/Dockerfile.agent
push: ${{ inputs.push }}
tags: ${{ env.repo }}/${{ env.agentImageName }}:${{ inputs.release-tag-name }}

- name: Docker Build (Webhook)
uses: docker/build-push-action@v5
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
file: package/Dockerfile.webhook
push: ${{ inputs.push }}
tags: ${{ env.repo }}/${{ env.webhookImageName }}:${{ inputs.release-tag-name }}
9 changes: 6 additions & 3 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ ENV ARCH $DAPPER_HOST_ARCH

RUN zypper -n install tar gzip bash git docker less file curl wget

RUN if [ "${ARCH}" = "amd64" ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.55.2; \
fi
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1

# The docker version in dapper is too old to have buildx. Install it manually.
RUN curl -sSfL https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} -o buildx-v0.13.1.linux-${ARCH} && \
chmod +x buildx-v0.13.1.linux-${ARCH} && \
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx

## install controller-gen
RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0
Expand Down
13 changes: 12 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-base:15.5

RUN zypper -n rm container-suseconnect && \
zypper -n in curl dhcp-tools jq

COPY bin/vm-dhcp-controller /usr/bin/vm-dhcp-controller
ARG TARGETPLATFORM

RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH=${TARGETPLATFORM#linux/}

COPY bin/vm-dhcp-controller-${ARCH} /usr/bin/vm-dhcp-controller

ENTRYPOINT [ "vm-dhcp-controller" ]
13 changes: 12 additions & 1 deletion package/Dockerfile.agent
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-base:15.5

RUN zypper -n rm container-suseconnect && \
zypper -n in curl dhcp-tools jq

COPY bin/vm-dhcp-agent /usr/bin/vm-dhcp-agent
ARG TARGETPLATFORM

RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH=${TARGETPLATFORM#linux/}

COPY bin/vm-dhcp-agent-${ARCH} /usr/bin/vm-dhcp-agent

ENTRYPOINT [ "vm-dhcp-agent" ]
13 changes: 12 additions & 1 deletion package/Dockerfile.webhook
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-base:15.5

RUN zypper -n rm container-suseconnect && \
zypper -n in curl

COPY bin/vm-dhcp-webhook /usr/bin/vm-dhcp-webhook
ARG TARGETPLATFORM

RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH=${TARGETPLATFORM#linux/}

COPY bin/vm-dhcp-webhook-${ARCH} /usr/bin/vm-dhcp-webhook

ENTRYPOINT [ "vm-dhcp-webhook" ]
8 changes: 5 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mkdir -p bin
LINKFLAGS="-X main.AppVersion=$VERSION
-X main.GitCommit=$COMMIT"

CGO_ENABLED=0 GOARCH="$ARCH" go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-controller ./cmd/controller
CGO_ENABLED=0 GOARCH="$ARCH" go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-agent ./cmd/agent
CGO_ENABLED=0 GOARCH="$ARCH" go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-webhook ./cmd/webhook
for arch in "amd64" "arm64"; do
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-controller-"$arch" ./cmd/controller
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-agent-"$arch" ./cmd/agent
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "-s -w $LINKFLAGS" -o bin/vm-dhcp-webhook-"$arch" ./cmd/webhook
done
2 changes: 0 additions & 2 deletions scripts/default
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ cd $(dirname $0)

./build
./package
./package-agent
./package-webhook
Loading
Loading