Skip to content

Commit 33294e7

Browse files
committed
feat: docker & ci build
1 parent 969cdc6 commit 33294e7

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed

.github/workflows/ci.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths-ignore:
7+
- 'docs/**'
8+
- 'assets/**'
9+
- '**/*.gitignore'
10+
- '**/*.md'
11+
pull_request:
12+
branches: [ "main" ]
13+
paths-ignore:
14+
- 'docs/**'
15+
- 'assets/**'
16+
- '**/*.gitignore'
17+
- '**/*.md'
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: '0'
27+
- name: Set up Go
28+
uses: actions/setup-go@v3
29+
with:
30+
cache: false
31+
go-version-file: go.mod
32+
33+
- name: Verify gofmt
34+
run: |
35+
go fmt ./... && git add cmd internal models pkg &&
36+
git diff --cached --exit-code || (echo 'Please run "make fmt" to verify gofmt' && exit 1);
37+
- name: Verify govet
38+
run: |
39+
go vet ./... && git add cmd internal models pkg &&
40+
git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
41+
42+
- name: Build
43+
run: CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o aoa .

.github/workflows/release.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
default: 'latest'
8+
required: true
9+
description: 'Docker image tag'
10+
push:
11+
tags:
12+
- 'v*'
13+
14+
jobs:
15+
build-image:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v2
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
23+
- name: Login to Docker Hub
24+
uses: docker/login-action@v2
25+
with:
26+
username: ${{ secrets.DOCKERHUB_USERNAME }}
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
28+
29+
- name: Login to the GPR
30+
uses: docker/login-action@v2
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.repository_owner }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Parse Tag Name
37+
run: |
38+
if [ x${{ github.event.inputs.tag }} == x"" ]; then
39+
echo "TAG_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
40+
else
41+
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Build and push
45+
uses: docker/build-push-action@v4
46+
env:
47+
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 # https://github.com/orgs/community/discussions/45969
48+
with:
49+
platforms: linux/amd64,linux/arm64
50+
push: true
51+
pull: true
52+
labels: |
53+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
54+
org.opencontainers.image.licenses=Apache-2.0
55+
tags: |
56+
${{ github.repository }}:${{ env.TAG_NAME }}
57+
ghcr.io/${{ github.repository }}:${{ env.TAG_NAME }}
58+
cache-from: type=gha # https://docs.docker.com/build/cache/backends/gha/
59+
cache-to: type=gha,mode=max
60+
61+
goreleaser:
62+
permissions: write-all
63+
runs-on: ubuntu-latest
64+
if: ${{ github.event.inputs.tag == '' }}
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v3
68+
with:
69+
fetch-depth: 0
70+
- name: Fetch all tags
71+
run: git fetch --force --tags
72+
- name: Set up Go
73+
uses: actions/setup-go@v4
74+
with:
75+
cache: false
76+
go-version-file: go.mod
77+
- name: Run GoReleaser
78+
uses: goreleaser/goreleaser-action@v4
79+
with:
80+
distribution: goreleaser
81+
version: latest
82+
args: release --clean
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Make sure to check the documentation at https://goreleaser.com
2+
env:
3+
- GIT_URL=https://github.com/soulteary/amazing-openai-api
4+
before:
5+
hooks:
6+
- go mod tidy
7+
builds:
8+
- id: amazing-openai-api
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- windows
14+
- darwin
15+
goarch:
16+
- amd64
17+
main: ./
18+
binary: aoa
19+
flags:
20+
- -trimpath
21+
ldflags:
22+
- -s -w
23+
- -X github.com/soulteary/amazing-openai-api/internal/version.Version={{ .Version }}
24+
- -X github.com/soulteary/amazing-openai-api/internal/version.BuildDate={{ .Date }}
25+
- -X github.com/soulteary/amazing-openai-api/internal/version.GitCommit={{ .Commit }}
26+
27+
archives:
28+
- format: tar.gz
29+
# this name template makes the OS and Arch compatible with the results of uname.
30+
name_template: >-
31+
{{ .ProjectName }}_
32+
{{- .Version }}_
33+
{{- .Os }}_
34+
{{- if eq .Arch "amd64" }}x86_64
35+
{{- else if eq .Arch "386" }}i386
36+
{{- else }}{{ .Arch }}{{ end }}
37+
{{- if .Arm }}v{{ .Arm }}{{ end }}
38+
# use zip for windows archives
39+
format_overrides:
40+
- goos: windows
41+
format: zip
42+
checksum:
43+
name_template: 'checksums.txt'
44+
snapshot:
45+
name_template: "{{ incpatch .Version }}-next"
46+
47+
# https://goreleaser.com/customization/changelog/
48+
changelog:
49+
sort: asc
50+
use: github
51+
filters:
52+
exclude:
53+
- '^build:'
54+
- '^ci:'
55+
# - '^docs:'
56+
- '^test:'
57+
- '^chore:'
58+
- '^feat(deps):'
59+
- 'merge conflict'
60+
- Merge pull request
61+
- Merge remote-tracking branch
62+
- Merge branch
63+
- go mod tidy
64+
- '^Update'
65+
groups:
66+
- title: Dependency updates
67+
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
68+
order: 300
69+
- title: 'New Features'
70+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
71+
order: 100
72+
- title: 'Security updates'
73+
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
74+
order: 150
75+
- title: 'Bug fixes'
76+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
77+
order: 200
78+
- title: 'Documentation updates'
79+
regexp: '^.*?doc(\([[:word:]]+\))??!?:.+$'
80+
order: 400
81+
# - title: 'Build process updates'
82+
# regexp: '^.*?build(\([[:word:]]+\))??!?:.+$'
83+
# order: 400
84+
- title: Other work
85+
order: 9999
86+
release:
87+
footer: |
88+
**Full Changelog**: https://github.com/soulteary/amazing-openai-api/compare/{{ .PreviousTag }}...{{ .Tag }}

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM golang:1.21.0-alpine AS builder
2+
RUN apk update && apk upgrade \
3+
&& apk add --no-cache ca-certificates tzdata \
4+
&& update-ca-certificates 2>/dev/null || true
5+
RUN apk add --no-cache make git gcc g++ libc-dev
6+
ENV GO111MODULE=on
7+
ENV CGO_ENABLED=0
8+
ENV GOOS=linux
9+
WORKDIR /build
10+
ADD go.mod go.sum ./
11+
RUN go mod download
12+
COPY . .
13+
RUN go build -trimpath -ldflags "-s -w" -o aoa .
14+
15+
FROM alpine:3.18.0
16+
RUN apk update && apk upgrade \
17+
&& apk add --no-cache ca-certificates tzdata \
18+
&& update-ca-certificates 2>/dev/null || true
19+
WORKDIR /app
20+
EXPOSE 8080
21+
COPY --from=builder /build/aoa .
22+
ENTRYPOINT ["/app/aoa"]

0 commit comments

Comments
 (0)