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

Move CI to github action #42

Merged
merged 1 commit into from
Jun 6, 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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./.dapper
./.cache
174 changes: 0 additions & 174 deletions .drone.yml

This file was deleted.

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

on:
push:
branches:
- master

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

env:
repo: "rancher"
controllerImageName: "harvester-cloud-provider"

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/harvester/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/harvester/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.tag }}
13 changes: 13 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pull Request Build

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build-for-dev:
uses: ./.github/workflows/factory.yml
with:
tag: pr-${{ github.event.number }}
push: false
secrets: inherit
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Build and Publish

on:
push:
tags:
- v**

jobs:
build-for-release:
uses: ./.github/workflows/factory.yml
with:
tag: ${{ github.ref_name }}
push: true
secrets: inherit
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/.dapper
/.idea
/bin
/dist
/.nocalhost
7 changes: 6 additions & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ RUN zypper -n rm container-suseconnect && \
## install golangci-lint
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

ENV DAPPER_ENV REPO TAG DRONE_TAG
ENV DAPPER_SOURCE /go/src/github.com/harvester/harvester-cloud-provider/
ENV DAPPER_OUTPUT ./bin ./dist
ENV DAPPER_OUTPUT ./bin
ENV DAPPER_DOCKER_SOCKET true
ENV HOME ${DAPPER_SOURCE}
WORKDIR ${DAPPER_SOURCE}
Expand Down
16 changes: 15 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# syntax=docker/dockerfile:1.7.0

FROM registry.suse.com/bci/bci-minimal:15.5
COPY bin/harvester-cloud-provider /usr/bin/

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/harvester-cloud-provider-${ARCH} /usr/bin/harvester-cloud-provider


CMD ["harvester-cloud-provider"]
5 changes: 4 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ cd $(dirname $0)/..

mkdir -p bin
[ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s"
CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/harvester-cloud-provider

for arch in "amd64" "arm64"; do
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/harvester-cloud-provider-"$arch"
done
2 changes: 1 addition & 1 deletion scripts/entry
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

mkdir -p bin dist
mkdir -p bin
if [ -e ./scripts/$1 ]; then
./scripts/"$@"
else
Expand Down
5 changes: 1 addition & 4 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ if echo $TAG | grep -q dirty; then
TAG=dev
fi

mkdir -p dist/artifacts
cp bin/harvester-cloud-provider dist/artifacts/harvester-cloud-provider${SUFFIX}

IMAGE=${REPO}/harvester-cloud-provider:${TAG}
DOCKERFILE=package/Dockerfile
if [ -e ${DOCKERFILE}.${ARCH} ]; then
DOCKERFILE=${DOCKERFILE}.${ARCH}
fi

docker build -f ${DOCKERFILE} -t ${IMAGE} .
buildx build --load -f ${DOCKERFILE} -t ${IMAGE} .
echo Built ${IMAGE}
Loading