Skip to content

Commit

Permalink
use goreleaser to release tarball and image, support brew install (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
howieyuen committed Jan 6, 2023
1 parent 5ea6525 commit 7be555e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 107 deletions.
47 changes: 8 additions & 39 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,21 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.18
# <--- Build and Package --->
- name: Pack kusion release packages for multiple platforms
env:
GO111MODULE: on
run: make build-all
# <--- Get version informations --->
- name: Get version
id: get_version
run: |
echo "::set-output name=kusion_version::$(./_build/bundles/kusion-linux/bin/kusion version -s | cut -d ';' -f 1)"
echo "::set-output name=kclvmgo_version::$(./_build/bundles/kusion-linux/bin/kusion version -y | grep kclvmgoVersion | cut -d ':' -f 2 | awk '$1=$1')"
echo "::set-output name=kclplugin_version::$(./_build/bundles/kusion-linux/bin/kusion version -y | grep kclPluginVersion | cut -d ':' -f 2 | awk '$1=$1')"
go generate ./pkg/version > version.txt
echo "kusion_version=$(cat version.txt | grep releaseVersion | cut -d ':' -f 2 | awk '$1=$1')" >> $GITHUB_OUTPUT
echo "kclvmgo_version=$(cat version.txt | grep kclvmgoVersion | cut -d ':' -f 2 | awk '$1=$1')" >> $GITHUB_OUTPUT
echo "kclplugin_version=$(cat version.txt | grep kclPluginVersion | cut -d ':' -f 2 | awk '$1=$1')" >> $GITHUB_OUTPUT
rm version.txt
# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# <--- build and push kusion image to Dockerhub --->
- name: Build and push kusion image to Docker Hub
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: kusionstack/kusion:latest,kusionstack/kusion:${{ steps.get_version.outputs.kusion_version }}
# <--- build and push kusionctl image to Dockerhub --->
- name: Build and push kusionctl image to Docker Hub
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile_kusionctl
push: true
tags: kusionstack/kusionctl:latest,kusionstack/kusionctl:${{ steps.get_version.outputs.kusion_version }}
# <--- Push kusion big packages for multiple platforms to Github Release --->
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
./_build/bundles/*.tgz*
./_build/bundles/*.zip*
append_body: true
body: |
## Docker Images
* `kusionstack/kusion:${{ steps.get_version.outputs.kusion_version }}`
## Dependent version
* [kclvm-go](https://github.com/KusionStack/kclvm-go): `${{ steps.get_version.outputs.kclvmgo_version }}`
* [kcl-plugin](https://github.com/KusionStack/kcl-plugin): `${{ steps.get_version.outputs.kclplugin_version }}`
# <--- End --->
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
Expand All @@ -119,3 +85,6 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.KUSIONSTACK_BOT_TOKEN }}
KUSION_VERSION: ${{ steps.get_version.outputs.kusion_version }}
KCLVM_GO_VERSION: ${{ steps.get_version.outputs.kclvmgo_version }}
KCL_PLUGIN_VERSION: ${{ steps.get_version.outputs.kclplugin_version }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ _python37_home_/
__debug_bin
.vscode/
zz_*

# version
*z_update_version.go
109 changes: 52 additions & 57 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@ before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
- go generate ./pkg/version
builds:
- env:
- id: default
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# 使用 ldflags="-s -w" 去掉符号表和调试信息,以减少发布包的大小
ldflags:
- -s -w
# upx 在部分 Mac 系统中会出现 killed 的报错,二进制无法正常工作,暂时不使用
# hooks:
# post:
# - upx -9 "{{ .Path }}"
# upx 在 windows amd64 上会报错,暂时不用
# ignore:
# - goos: windows
# goarch: arm64
- -s
- -w
ignore:
- goos: linux
goarch: arm64
- goos: windows
goarch: arm64
main: .
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- id: default
builds:
- default
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: desc
use: github
sort: asc
filters:
exclude:
- '^docs:'
Expand All @@ -48,58 +51,50 @@ release:
draft: false
footer: |
## Docker Images
* `KusionStack/kusion:{{ .Tag }}`
* `KusionStack/kusion:{{ .Tag }}-arm64`
## Thanks!
* `kusionstack/kusion:{{ .Env.KUSION_VERSION }}`
## Dependent version
* [kclvm-go](https://github.com/KusionStack/kclvm-go): `{{ .Env.KCLVM_GO_VERSION }}`
* [kcl-plugin](https://github.com/KusionStack/kcl-plugin): `{{ .Env.KCL_PLUGIN_VERSION }}`
dockers:
- image_templates:
- 'KusionStack/{{ .ProjectName }}:{{ .Tag }}'
- 'KusionStack/{{ .ProjectName }}:latest'
# - 'ghcr.io/KusionStack/{{ .ProjectName }}:{{ .Tag }}'
# - 'ghcr.io/KusionStack/{{ .ProjectName }}:latest'
dockerfile: Dockerfile
use: docker
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"
- image_templates:
- 'KusionStack/{{ .ProjectName }}:{{ .Tag }}-arm64'
# - 'ghcr.io/KusionStack/{{ .ProjectName }}:{{ .Tag }}-arm64'
dockerfile: Dockerfile
use: docker
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
goarch: arm64
- use: buildx
goos: linux
goarch: amd64
dockerfile: Dockerfile
image_templates:
- kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64
build_flag_templates:
- "--target=goreleaser"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"

docker_manifests:
- use: docker
name_template: kusionstack/{{ .ProjectName }}:{{ .Tag }}
image_templates:
- kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64
- use: docker
name_template: kusionstack/{{ .ProjectName }}:latest
image_templates:
- kusionstack/{{ .ProjectName }}:{{ .Tag }}-amd64

brews:
- tap:
owner: KusionStack
name: homebrew-tap
# token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"

url_template: "https://github.com/KusionStack/kusion/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
download_strategy: CurlDownloadStrategy

# Git author used to commit to the repository.
# Defaults are shown.
commit_author:
name: GoReleaser Bot
email: goreleaser@carlosbecker.com

folder: HomebrewFormula
homepage: "https://github.com/KusionStack/kusion"
description: "Codify and deliver intentions to Kubernetes and Clouds"
license: "Apache License"
Expand Down
27 changes: 17 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM ubuntu:20.04

COPY _build/bundles/kusion-linux/ /kusion/

RUN chmod +x /kusion/bin/kusion
FROM golang:1.18 AS build
COPY / /src
WORKDIR /src
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build make build-local-linux

FROM ubuntu:20.04 AS base
# Install KCL Dependencies
RUN apt-get update -y && apt-get install python3 python3-pip -y
# unembed kcl stuff
RUN /kusion/bin/kusion

ENV PATH="/kusion/bin:/root/go/bin:${PATH}"
ENV KUSION_PATH="/kusion"
# KCL PATH
ENV PATH="/root/go/bin:${PATH}"
# KUSION_PATH
ENV KUSION_PATH="$HOME/.kusion"
ENV LANG=en_US.utf8

FROM base AS goreleaser
COPY kusion /usr/local/bin/kusion
RUN /usr/local/bin/kusion

FROM base
COPY --from=build /src/_build/bundles/kusion-linux/bin/kusion /usr/local/bin/kusion
RUN /usr/local/bin/kusion
1 change: 0 additions & 1 deletion pkg/version/.gitignore

This file was deleted.

0 comments on commit 7be555e

Please sign in to comment.