Compare commits

..

7 Commits

Author SHA1 Message Date
Yuxing Deng
18027bbaeb fix: the usage is not compatible with old version 2024-11-25 09:31:06 +08:00
Yuxing Deng
99c03af96e fix: wrong branch name 2024-10-21 21:49:53 +08:00
Yuxing Deng
618cd9abfb fix: add release-v branch to push workflow 2024-10-21 21:48:13 +08:00
Yuxing Deng
9c5a29c9cc fix: CROSS push 2024-10-21 21:45:47 +08:00
Yuxing Deng
2c0afb3776 fix: aliyun-metadata should have registry name for image 2024-10-21 21:45:47 +08:00
Yuxing Deng
ca5f23170f feat: use goreleaser to build binaries 2024-10-21 16:36:57 +08:00
Yuxing Deng
24a7324f92 feat: bump ui version 2024-10-08 11:05:54 +08:00
10 changed files with 165 additions and 125 deletions

View File

@@ -16,6 +16,4 @@ jobs:
- name: Commitsar check - name: Commitsar check
uses: aevea/commitsar@v0.20.2 uses: aevea/commitsar@v0.20.2
- name: Build to test - name: Build to test
env:
SKIP_COMPRESS: "true"
run: make ci run: make ci

View File

@@ -4,8 +4,12 @@ on:
push: push:
branches: branches:
- main - main
- "release/v*"
tags: tags:
- 'v*.*.*' # Matches any tag that starts with 'v' and follows semantic versioning - "v*.*.*" # Matches any tag that starts with 'v' and follows semantic versioning
env:
ALIYUN_REGISTRY: ${{ vars.ALIYUN_REGISTRY || '' }}
jobs: jobs:
build-and-deploy: build-and-deploy:
@@ -15,67 +19,73 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: CI
env:
SKIP_PACKAGE: "true"
run: make ci
- name: Prepare for packaging image
run: cp dist/* package/
# aliyun image to test the docker build is ok
- name: Login to Aliyun ACR - name: Login to Aliyun ACR
if: ${{ vars.ALIYUN_REGISTRY != '' }}
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: registry.cn-shenzhen.aliyuncs.com registry: ${{ env.ALIYUN_REGISTRY }}
username: ${{ secrets.ACR_USERNAME }} username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_TOKEN }} password: ${{ secrets.ACR_TOKEN }}
if: ${{ vars.ALIYUN == 'true' }} - name: Aliyun image docker meta
if: ${{ vars.ALIYUN_REGISTRY != '' }}
id: aliyun-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.ALIYUN_REGISTRY }}/${{ vars.REPO || 'cnrancher' }}/${{ vars.IMAGE || 'kube-explorer' }}
tags: |
type=ref,event=tag
type=ref,event=branch,suffix=-head
- name: Build to Aliyun
if: ${{ vars.ALIYUN_REGISTRY != '' }}
uses: docker/build-push-action@v6
with:
labels: ${{ steps.aliyun-meta.outputs.labels }}
tags: "${{ steps.aliyun-meta.outputs.tags }}"
context: package
push: true
# docker hub multi-arch image
- name: Login to Dockerhub - name: Login to Dockerhub
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: CI - name: Docker meta
if: startsWith(github.ref, 'refs/heads/') id: meta
env: uses: docker/metadata-action@v5
CROSS: push with:
run: make github_ci images: ${{ vars.REPO || 'cnrancher' }}/${{ vars.IMAGE || 'kube-explorer' }}
tags: |
- name: CI type=ref,event=tag
if: startsWith(github.ref, 'refs/tags/') type=ref,event=branch,suffix=-head
env: - name: Set up QEMU
CROSS: tag
run: |
make github_ci
make release-note
- name: Prepare for packaging image
run: cp dist/* package/
- name: Set docker iamge name
id: image-name
env:
REPO_OVERRIDE: ${{ vars.REPO || 'cnrancher' }}
IMAGE_OVERRIDE: ${{ vars.IMAGE || 'kube-explorer' }}
run: |
tag_name=latest;
if [[ ${GITHUB_REF} == refs/tags/* ]]; then tag_name=${GITHUB_REF#refs/tags/}; fi;
echo "image_name=${REPO_OVERRIDE}/${IMAGE_OVERRIDE}:${tag_name}" >> $GITHUB_OUTPUT;
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
- - name: Set up Docker Buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Build to Dockerhub - name: Build to Dockerhub
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
platforms: linux/amd64,linux/arm64/v8 platforms: linux/amd64,linux/arm64/v8
tags: "${{ steps.image-name.outputs.image_name }}" labels: ${{ steps.meta.outputs.labels }}
tags: "${{ steps.meta.outputs.tags }}"
context: package context: package
push: true push: true
- name: Build to Aliyun
uses: docker/build-push-action@v6 - name: Make release note
with: if: startsWith(github.ref, 'refs/tags/')
tags: registry.cn-shenzhen.aliyuncs.com/${{ steps.image-name.outputs.image_name }} run: |
context: package make release-note
push: true
if: ${{ vars.ALIYUN == 'true' }}
- name: Release - name: Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
with: with:
files: dist/kube-explorer-* files: dist/kube-explorer-*
body_path: dist/release-note body_path: dist/release-note
draft: true draft: true

4
.gitignore vendored
View File

@@ -23,3 +23,7 @@
/.vscode /.vscode
/vendor /vendor
/internal/ui/ui/ /internal/ui/ui/
**/Dockerfile.dapper*
!**/Dockerfile.dapper
dist/

75
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,75 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
dist: bin
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- id: prod
env:
- CGO_ENABLED=0
targets:
- "darwin_amd64"
- "darwin_arm64"
- "linux_amd64"
- "linux_arm64"
- "linux_arm"
- "windows_amd64"
flags:
- -tags=embed
binary: '{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}'
ldflags: |
{{ if ne .Os "darwin" }}
-extldflags -static -s
{{ else }}
-s -w
{{ end }}
-X github.com/cnrancher/kube-explorer/internal/version.Version={{ .Env.VERSION }}
-X github.com/cnrancher/kube-explorer/internal/version.GitCommit={{ .Env.COMMIT }}
-X github.com/cnrancher/kube-explorer/internal/config.APIUIVersion={{ .Env.CATTLE_API_UI_VERSION }}
no_unique_dist_dir: true
- id: dev
env:
- CGO_ENABLED=0
targets:
- "linux_amd64"
- "linux_arm64"
flags:
- -tags=embed
binary: '{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}'
ldflags: |
{{ if ne .Os "darwin" }}
-extldflags -static -s
{{ else }}
-s -w
{{ end }}
-X github.com/cnrancher/kube-explorer/internal/version.Version={{ .Env.VERSION }}
-X github.com/cnrancher/kube-explorer/internal/version.GitCommit={{ .Env.COMMIT }}
-X github.com/cnrancher/kube-explorer/internal/config.APIUIVersion={{ .Env.CATTLE_API_UI_VERSION }}
no_unique_dist_dir: true
upx:
- compress: "5"
ids:
- prod
enabled: true
goos:
- linux
- windows
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

View File

@@ -1,3 +1,4 @@
FROM goreleaser/goreleaser:v2.3.2 as goreleaser
FROM aevea/release-notary:0.9.2 as tools FROM aevea/release-notary:0.9.2 as tools
FROM registry.suse.com/bci/golang:1.22 FROM registry.suse.com/bci/golang:1.22
@@ -8,8 +9,7 @@ ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
ENV https_proxy=${PROXY} \ ENV https_proxy=${PROXY} \
http_proxy=${PROXY} http_proxy=${PROXY}
RUN zypper -n install ca-certificates git-core wget curl unzip tar vim less file xz RUN zypper -n install ca-certificates git-core wget curl unzip tar vim less file xz cosign docker
RUN zypper install -y -f docker
ENV UPX_VERSION 4.2.1 ENV UPX_VERSION 4.2.1
RUN curl -sL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-${ARCH}_linux.tar.xz | tar xvJf - --strip-components=1 -C /tmp && \ RUN curl -sL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-${ARCH}_linux.tar.xz | tar xvJf - --strip-components=1 -C /tmp && \
@@ -18,11 +18,12 @@ RUN curl -sL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${
RUN if [ "${ARCH}" == "amd64" ]; then \ RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2; \ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2; \
fi fi
COPY --from=goreleaser /usr/bin/goreleaser /usr/bin/goreleaser
COPY --from=tools /app/release-notary /usr/local/bin/ COPY --from=tools /app/release-notary /usr/local/bin/
ENV CATTLE_DASHBOARD_UI_VERSION="v2.8.0-kube-explorer-ui-rc3" ENV CATTLE_DASHBOARD_UI_VERSION="v2.8.5-kube-explorer-ui-rc1"
ENV CATTLE_API_UI_VERSION="1.1.11" ENV CATTLE_API_UI_VERSION="1.1.11"
ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS GOPROXY SKIP_COMPRESS GITHUB_REPOSITORY GITHUB_TOKEN ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS GOPROXY GITHUB_TOKEN GITHUB_REF GITHUB_REF_NAME BUILD_TARGET SKIP_PACKAGE
ENV DAPPER_SOURCE /go/src/github.com/cnrancher/kube-explorer ENV DAPPER_SOURCE /go/src/github.com/cnrancher/kube-explorer
ENV DAPPER_OUTPUT ./bin ./dist ENV DAPPER_OUTPUT ./bin ./dist
ENV DAPPER_DOCKER_SOCKET true ENV DAPPER_DOCKER_SOCKET true

View File

@@ -4,5 +4,4 @@ ARG TARGETOS
ENV ARCH=${TARGETARCH:-"amd64"} OS=${TARGETOS:-"linux"} ENV ARCH=${TARGETARCH:-"amd64"} OS=${TARGETOS:-"linux"}
RUN zypper install -y catatonit RUN zypper install -y catatonit
COPY kube-explorer-${OS}-${ARCH} /usr/bin/kube-explorer COPY kube-explorer-${OS}-${ARCH} /usr/bin/kube-explorer
ENTRYPOINT [ "/usr/bin/catatonit", "--" ] ENTRYPOINT [ "/usr/bin/catatonit", "--", "kube-explorer" ]
CMD [ "kube-explorer" ]

View File

@@ -6,77 +6,33 @@ cd "$(dirname $0)/.."
rm -rf ./bin/* ./dist/* rm -rf ./bin/* ./dist/*
OS_ARCH_ARG_LINUX="amd64 arm arm64" BUILD_TARGET="${BUILD_TARGET:-dev}"
OS_ARCH_ARG_DARWIN="amd64 arm64" CROSS=${CROSS:-}
OS_ARCH_ARG_WINDOWS="amd64"
LD_INJECT_VALUES="-X github.com/cnrancher/kube-explorer/internal/version.Version=$VERSION if [[ ${GITHUB_REF} == refs/tags/* ]]; then
-X github.com/cnrancher/kube-explorer/internal/version.GitCommit=$COMMIT CROSS=tag
-X github.com/cnrancher/kube-explorer/internal/config.APIUIVersion=$CATTLE_API_UI_VERSION" elif [ -n "${GITHUB_REF}" ]; then
CROSS=push
fi
[ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s" case "$CROSS" in
case "$CROSS" in
"push")
for ARCH in ${OS_ARCH_ARG_LINUX}; do
OUTPUT_BIN="bin/kube-explorer-linux-$ARCH"
echo "Building binary for linux/$ARCH..."
GOARCH=$ARCH GOOS=linux CGO_ENABLED=0 go build -tags embed \
-ldflags \
"$LD_INJECT_VALUES $LINKFLAGS" \
-o ${OUTPUT_BIN}
done
;;
"tag") "tag")
for ARCH in ${OS_ARCH_ARG_LINUX}; do BUILD_TARGET="prod"
OUTPUT_BIN="bin/kube-explorer-linux-$ARCH" ;;
echo "Building binary for linux/$ARCH..." "push")
GOARCH=$ARCH GOOS=linux CGO_ENABLED=0 go build -tags embed \ ;;
-ldflags \
"$LD_INJECT_VALUES $LINKFLAGS" \
-o ${OUTPUT_BIN}
done
for ARCH in ${OS_ARCH_ARG_DARWIN}; do
OUTPUT_BIN="bin/kube-explorer-darwin-$ARCH"
echo "Building binary for darwin/$ARCH..."
GOARCH=$ARCH GOOS=darwin CGO_ENABLED=0 go build -tags embed \
-ldflags \
"$LD_INJECT_VALUES" \
-o ${OUTPUT_BIN}
done
for ARCH in ${OS_ARCH_ARG_WINDOWS}; do
OUTPUT_BIN="bin/kube-explorer-windows-$ARCH.exe"
echo "Building binary for windows/$ARCH..."
GOARCH=$ARCH GOOS=windows CGO_ENABLED=0 go build -tags embed \
-ldflags \
"$LD_INJECT_VALUES" \
-o ${OUTPUT_BIN}
done
;;
*) *)
# only build one for current platform BUILD_ARG="${BUILD_ARG} --single-target"
CGO_ENABLED=0 go build -tags embed \ ;;
-ldflags \
"$LD_INJECT_VALUES $LINKFLAGS" \
-o "bin/kube-explorer-$(uname | tr '[:upper:]' '[:lower:]')-${ARCH}"
;;
esac esac
BUILD_ARG="${BUILD_ARG:-} --skip validate --id ${BUILD_TARGET}"
mkdir -p "./bin" mkdir -p "./bin"
# upx is handled by goreleaser
VERSION=${VERSION} COMMIT=${COMMIT} goreleaser build $BUILD_ARG
mkdir -p "./dist" mkdir -p "./dist"
for f in ./bin/*; do cp -r bin/kube-explorer-* dist/
filename=$(basename "$f")
if [[ $filename != *darwin* && -z "$SKIP_COMPRESS" ]]; then
if upx -o "./dist/$filename" "$f"; then
echo "UPX done for $filename!"
else
echo "UPX failed for $filename, copying original file."
cp "$f" "./dist/$filename"
fi
else
cp "$f" "./dist/$filename"
fi
done

View File

@@ -6,4 +6,6 @@ cd $(dirname $0)
./download ./download
./validate ./validate
./build ./build
./package if [ -z "${SKIP_PACKAGE}" ]; then
./package
fi

View File

@@ -1,9 +0,0 @@
#!/bin/bash
set -e
cd $(dirname $0)
./download
./validate
./build

View File

@@ -1,11 +1,15 @@
#!/bin/bash #!/bin/bash
if [[ ${GITHUB_REF} == refs/tags/* ]]; then
GIT_TAG=${GIT_TAG:-${GITHUB_REF_NAME}}
fi
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
DIRTY="-dirty" DIRTY="-dirty"
fi fi
COMMIT=$(git rev-parse --short HEAD) COMMIT=$(git rev-parse --short HEAD)
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} GIT_TAG=${GIT_TAG:-$(git tag -l --contains HEAD | head -n 1)}
if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then
VERSION=$GIT_TAG VERSION=$GIT_TAG