From 2ead9c892b97a0afe0ca6046bd7cfdad050183ff Mon Sep 17 00:00:00 2001 From: "lihanbo.0316" Date: Wed, 5 Jun 2024 14:29:45 +0800 Subject: [PATCH] feat: push images to dockerhub --- .github/workflows/dockerhub-latest.yml | 30 +++++++++++++++++++++++ .github/workflows/dokcerhub-released.yml | 31 ++++++++++++++++++++++++ Makefile | 3 ++- hack/lib/build.sh | 4 +++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dockerhub-latest.yml create mode 100644 .github/workflows/dokcerhub-released.yml diff --git a/.github/workflows/dockerhub-latest.yml b/.github/workflows/dockerhub-latest.yml new file mode 100644 index 00000000..aca4771f --- /dev/null +++ b/.github/workflows/dockerhub-latest.yml @@ -0,0 +1,30 @@ +name: Build and push latest images to DockerHub + +on: + push: + branches: ["main", "ci-test"] + +permissions: + packages: write + +jobs: + publish-images-to-dockerhub: + name: Publish to DockerHub + if: ${{ github.repository == 'kubewharf/kubeadmiral' }} + runs-on: [ubuntu-latest] + steps: + - name: checkout code + uses: actions/checkout@v3 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USER_NAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and publish images + env: + REGISTRY: kubewharf + TAG: latest + OUTPUT_TYPE: registry + run: make images diff --git a/.github/workflows/dokcerhub-released.yml b/.github/workflows/dokcerhub-released.yml new file mode 100644 index 00000000..1a7c2811 --- /dev/null +++ b/.github/workflows/dokcerhub-released.yml @@ -0,0 +1,31 @@ +name: Build and push released images to DockerHub + +on: + release: + types: + - published + +permissions: + packages: write + +jobs: + publish-images-to-dockerhub: + name: Publish to DockerHub + if: ${{ github.repository == 'kubewharf/kubeadmiral' }} + runs-on: [ubuntu-latest] + steps: + - name: checkout code + uses: actions/checkout@v3 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USER_NAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and publish images + env: + REGISTRY: kubewharf + TAG: ${{ github.ref_name }} + OUTPUT_TYPE: registry + run: make images diff --git a/Makefile b/Makefile index 54adfb64..3f6bcd2c 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ DEBUG_TARGET_NAME ?= $(TARGET_NAME)_debug REGISTRY ?= ghcr.io/kubewharf TAG ?= latest REGION ?= +OUTPUT_TYPE ?= ifeq (${REGION}, cn) GOPROXY := https://goproxy.cn,direct @@ -123,7 +124,7 @@ local-up: images: REGISTRY=$(REGISTRY) TAG=$(TAG) ARCHS=$(ARCHS) GOPROXY=$(GOPROXY) REGION=$(REGION) \ DOCKER_BUILD_ARGS="$(DOCKER_BUILD_ARGS)" DOCKERFILE_PATH="$(DOCKERFILE_PATH)" \ - TARGET_NAME="$(TARGET_NAME)" bash hack/make-rules/build-images.sh + TARGET_NAME="$(TARGET_NAME)" OUTPUT_TYPE="$(OUTPUT_TYPE)" bash hack/make-rules/build-images.sh # Clean built binaries .PHONY: clean diff --git a/hack/lib/build.sh b/hack/lib/build.sh index 86a0fba8..bb8cf272 100644 --- a/hack/lib/build.sh +++ b/hack/lib/build.sh @@ -119,4 +119,8 @@ function build::build_images() { --tag ${image_name} \ --file ${dockerfile_path} \ ${REPO_ROOT} + + if [[ "$output_type" == "registry" ]]; then + docker push "${image_name}" + fi }