From da97585d0ce7a72c37fd456151b4b31d93fcac38 Mon Sep 17 00:00:00 2001 From: Praveen Yadav Date: Sun, 17 Mar 2024 10:38:21 +0530 Subject: [PATCH] chore: add github action to release binaries on tags Signed-off-by: Praveen Yadav --- .github/workflows/main.yaml | 4 +- .github/workflows/release.yml | 58 +++++++++++++++++++ .gitignore | 2 + .goreleaser.yaml | 104 ++++++++++++++++++++++++++++++++++ Makefile | 4 ++ gateway/Dockerfile.dev | 23 ++++++++ gateway/Makefile | 2 +- 7 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml create mode 100644 gateway/Dockerfile.dev diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index ff4169c..797aa4e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: "1.21.6" + go-version: "1.22.0" - name: Login to DockerHub uses: docker/login-action@v3 with: @@ -28,4 +28,4 @@ jobs: with: push: true file: "./docker/Dockerfile.gateway.dev" - tags: missingstudio/ai:dev \ No newline at end of file + tags: missingstudio/gateway:dev \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..14ce25f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: release + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + +jobs: + dev: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22.0" + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Publish dev image + id: docker_dev_build + uses: docker/build-push-action@v2 + with: + push: true + file: "./docker/Dockerfile.gateway.dev" + tags: missingstudio/gateway:dev + releaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22.0" + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 89e2123..1109e1c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ Chart.lock **/*.tgz go.work.sum + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..dfb591c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,104 @@ +project_name: gateway + +before: + hooks: + - make test + +release: + prerelease: auto + +builds: + - id: gateway + goos: [linux, darwin, windows] + goarch: [amd64, arm64] + binary: gateway + dir: ./gateway + main: ./ + ldflags: + - -s -w -X github.com/missinstudio/ai/gateway/config.Version={{.Tag}} + - -X github.com/missinstudio/ai/gateway/config.BuildCommit={{.FullCommit}} + - -X github.com/missinstudio/ai/gateway/config.BuildDate={{.Date}} + env: + - CGO_ENABLED=0 + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +checksum: + name_template: "{{ .ProjectName }}_v{{ .Version }}_checksums.txt" + +snapshot: + name_template: "{{ .Tag }}-next" + + +dockers: + - goos: linux + goarch: amd64 + ids: + - gateway + dockerfile: Dockerfile + image_templates: + - "docker.io/missingstudio/{{.ProjectName}}:latest" + - "docker.io/missingstudio/{{.ProjectName}}:{{ .Tag }}" + - "docker.io/missingstudio/{{.ProjectName}}:{{ .Tag }}-amd64" + - goos: linux + goarch: arm64 + ids: + - gateway + dockerfile: Dockerfile + image_templates: + - "docker.io/missingstudio/{{.ProjectName}}:{{ .Tag }}-arm64" + + +nfpms: + - maintainer: Missing studio + description: A robust cloud-native AI Gateway + homepage: https://github.com/missingstudio/gateway + license: Apache 2.0 + formats: + - deb + - rpm + +scoops: + - homepage: https://github.com/missingstudio/gateway + description: A robust cloud-native AI Gateway + license: Apache 2.0 + repository: + owner: raystack + name: scoop-bucket + +brews: + - name: gateway + homepage: https://github.com/missingstudio/gateway + description: A robust cloud-native AI Gateway + repository: + owner: missingstudio + name: homebrew-tap + license: Apache 2.0 + folder: Formula + dependencies: + - name: git + install: |- + bin.install "gateway" + commit_author: + name: Missing studio + email: support@missing.studio diff --git a/Makefile b/Makefile index d971be9..94def0c 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,10 @@ help: ## Show this help build: build-gateway ## Build missing studio project .PHONY: build +test: + sh -c "cd ./gateway && make test" +.PHONY: test + build-gateway: sh -c "cd ./gateway && make all" .PHONY: build-gateway diff --git a/gateway/Dockerfile.dev b/gateway/Dockerfile.dev new file mode 100644 index 0000000..a787717 --- /dev/null +++ b/gateway/Dockerfile.dev @@ -0,0 +1,23 @@ +FROM golang:1.22-alpine3.18 as builder + +RUN apk add make + +WORKDIR /go/src/app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make build + +FROM alpine:3.18 +COPY --from=builder /go/src/app/frontier /usr/bin/ +RUN apk update +RUN apk add ca-certificates + +# glibc compatibility library, since go binaries +# don't work well with musl libc that alpine uses +RUN apk add libc6-compat + +ENTRYPOINT ["frontier", "server"] \ No newline at end of file diff --git a/gateway/Makefile b/gateway/Makefile index 0c38111..2a47670 100644 --- a/gateway/Makefile +++ b/gateway/Makefile @@ -26,7 +26,7 @@ clean: ## Clean AI Gateway server .PHONY: clean test: ## Run tests - @go test -race $(shell go list ./... | grep -v /ui | grep -v /vendor/ | grep -v /test/) -coverprofile=coverage.out -count 2 -timeout 150s + @go test -race $(shell go list ./... | grep -v /vendor/ | grep -v /test/) -coverprofile=coverage.out -count 2 -timeout 150s install-tools: install-go-tools .PHONY: install-tools