-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from stoneshi-yunify/main
add build workflows and support multi-arch build
- Loading branch information
Showing
3 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,63 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "Image Tag" | ||
default: "latest" | ||
push: | ||
branches: | ||
- 'main' | ||
- 'release-*' | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
buildx: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Prepare | ||
id: prepare | ||
run: | | ||
VERSION=latest | ||
if [[ $GITHUB_REF == refs/tags/* ]]; then | ||
VERSION=${GITHUB_REF#refs/tags/} | ||
fi | ||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
VERSION=${{ github.event.inputs.tag }} | ||
fi | ||
echo ::set-output name=version::${VERSION} | ||
- name: Docker meta for kubesphere | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: docker.io/kubesphere/storageclass-accessor | ||
tags: ${{ steps.prepare.outputs.version }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login to DockerHub | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: docker.io | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Build and push Docker images | ||
uses: docker/build-push-action@v2.4.0 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
tags: ${{ steps.meta.outputs.tags }} | ||
push: true | ||
load: false | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64 |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
GIT_COMMIT=$(shell git rev-parse HEAD | head -c 7) | ||
IMG ?= kubesphere/storageclass-accessor:${GIT_COMMIT} | ||
IMGLATEST ?= kubesphere/storageclass-accessor:latest | ||
REPO ?= kubesphere | ||
TAG ?= latest | ||
|
||
.PHONY: build | ||
build: | ||
go mod tidy && go mod verify && go build -o bin/manager main.go | ||
build-local: ; $(info $(M)...Begin to build storageclass-accessor binary.) @ ## Build storageclass-accessor. | ||
CGO_ENABLED=0 go build -ldflags \ | ||
"-X 'main.goVersion=$(shell go version|sed 's/go version //g')' \ | ||
-X 'main.gitHash=$(shell git describe --dirty --always --tags)' \ | ||
-X 'main.buildTime=$(shell TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" \ | ||
-o bin/manager main.go | ||
|
||
.PHONY: docker-build | ||
docker-build: #test ## Build docker image with the manager. | ||
docker build -t ${IMG} . | ||
build-image: ; $(info $(M)...Begin to build storageclass-accessor image.) @ ## Build storageclass-accessor image. | ||
docker build -f Dockerfile -t ${REPO}/storageclass-accessor:${TAG} . | ||
docker push ${REPO}/storageclass-accessor:${TAG} | ||
|
||
.PHONY: docker-push | ||
docker-push: ## Push docker image with the manager. | ||
docker push ${IMG} | ||
docker tag ${IMG} ${IMGLATEST} | ||
docker push ${IMGLATEST} | ||
build-cross-image: ; $(info $(M)...Begin to build storageclass-accessor image.) @ ## Build storageclass-accessor image. | ||
docker buildx build -f Dockerfile -t ${REPO}/storageclass-accessor:${TAG} --push --platform linux/amd64,linux/arm64 . |