migration ci from drone to gh actions

fixed up build issues

include ci feedback

remove copy to dist/artifacts
This commit is contained in:
Gaurav Mehta 2024-04-22 13:39:48 +10:00
parent 5e03d6d864
commit 0628775de7
9 changed files with 120 additions and 77 deletions

View File

@ -1,73 +0,0 @@
---
kind: pipeline
name: harvester-vm-import-controller
platform:
os: linux
arch: amd64
steps:
- name: fetch
image: alpine/git
commands:
- git fetch --tags
when:
instance:
- drone-publish.rancher.io
ref:
- refs/head/master
- refs/tags/*
event:
- tag
- name: build
image: rancher/dapper:v0.6.0
commands:
- dapper ci
volumes:
- name: docker
path: /var/run/docker.sock
- name: docker-publish-master
image: plugins/docker
settings:
build_args:
- VERSION=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}-head
dockerfile: package/Dockerfile
password:
from_secret: docker_password
repo: "rancher/harvester-vm-import-controller"
tag: ${DRONE_BRANCH}-head
username:
from_secret: docker_username
when:
branch: main
event:
- push
- name: docker-publish
image: plugins/docker
settings:
build_args:
- "VERSION=${DRONE_TAG}"
custom_dns: 1.1.1.1
dockerfile: package/Dockerfile
password:
from_secret: docker_password
repo: "rancher/harvester-vm-import-controller"
tag: "${DRONE_TAG}"
username:
from_secret: docker_username
when:
instance:
- drone-publish.rancher.io
ref:
- refs/head/main
- refs/tags/*
event:
- tag
volumes:
- name: docker
host:
path: /var/run/docker.sock

15
.github/workflows/master.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Master Build and Publish
on:
push:
branches:
- main
- release/v*
jobs:
build-master:
uses: ./.github/workflows/template-build.yml
with:
release-tag-name: ${{ github.ref_name }}-head
push: true
secrets: inherit

12
.github/workflows/pull-request.yml vendored Normal file
View File

@ -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

14
.github/workflows/tag.yml vendored Normal file
View File

@ -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

55
.github/workflows/template-build.yml vendored Normal file
View File

@ -0,0 +1,55 @@
on:
workflow_call:
inputs:
release-tag-name:
required: true
type: string
push:
required: true
type: boolean
env:
imageName: "rancher/harvester-vm-import-controller"
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
uses: docker/build-push-action@v5
with:
provenance: false
context: .
platforms: linux/amd64,linux/arm64
file: package/Dockerfile
push: ${{ inputs.push }}
tags: ${{env.imageName}}:${{ inputs.release-tag-name }}

View File

@ -16,6 +16,11 @@ RUN export K8S_VERSION=1.24.2 && \
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 CROSS
ENV DAPPER_SOURCE /go/src/github.com/harvester/vm-import-controller
ENV DAPPER_OUTPUT ./bin

View File

@ -1,7 +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 qemu-tools
ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi
ENV ARCH=${TARGETPLATFORM#linux/}
COPY package/qemu-wrapper.sh /usr/bin/qemu-wrapper.sh
COPY bin/vm-import-controller /usr/bin/vm-import-controller
COPY bin/vm-import-controller-${ARCH} /usr/bin/vm-import-controller
USER 1000
CMD ["vm-import-controller"]

View File

@ -2,5 +2,6 @@
set -e
cd $(dirname $0)/..
CGO_ENABLED=0 go build -o bin/vm-import-controller .
mkdir -p bin
mkdir -p bin
GOARCH=amd64 CGO_ENABLED=0 go build -o bin/vm-import-controller-amd64 .
GOARCH=arm64 CGO_ENABLED=0 go build -o bin/vm-import-controller-arm64 .

View File

@ -7,5 +7,7 @@ cd $(dirname $0)/..
IMAGE=${REPO}/harvester-vm-import-controller:${TAG}
DOCKERFILE=package/Dockerfile
docker build -f ${DOCKERFILE} -t ${IMAGE} .
buildx build --load \
-f ${DOCKERFILE} -t ${IMAGE} .
echo Built ${IMAGE}