Skip to content

Commit

Permalink
build: set up GitHub actions for building and deploying API
Browse files Browse the repository at this point in the history
- Add new file `.github/workflows/api.yml`
- Set up environment variables for `GO_VERSION` and `TZ`
- Trigger the workflow on push to any branch
- Define a job named "buildapi" with a timeout of 20 minutes running on Ubuntu
- Checkout the code and set up QEMU and Docker Buildx
- Set up Go with version `1.22` and check for the latest version
- Install `task` dependency
- Build API using `swag` task
- Build and push docs API using Docker
- Modify file `Taskfile.yml`: Remove `swag` dependency from `codegpt` task
- Run formatting tasks: `gomod`, `gencopyright`, `gofmt`, `golint`

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Apr 1, 2024
1 parent efb5e72 commit b8fe799
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: api

env:
# Common versions
GO_VERSION: '1.22'
TZ: Asia/Shanghai

on:
push:
branches:
- '*'

jobs:
buildapi:
name: "api"
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- name: install task
run: |
echo "install task"
go install github.com/go-task/task/v3/cmd/task@latest
- name: build api
run: |
task swag
- name: Build and push docs api
uses: docker/build-push-action@v5
with:
push: true
tags: ttl.sh/easysoft/zentaoapi
context: docs
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ tasks:
codegpt:
desc: generate code commit message
deps:
- swag
- fmt
cmds:
- git add .
- codegpt commit --diff_unified 5 --exclude_list docs

fmt:
cmds:
- task: swag
- task: gomod
- task: gencopyright
- task: gofmt
Expand Down
31 changes: 31 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM golang:alpine as builder

ENV WORKDIR /go/src/github.com/easysoft/go-zentao/docs

WORKDIR $WORKDIR

COPY go.mod go.mod

COPY go.sum go.sum

RUN go mod download

COPY docs.go docs.go

COPY main.go main.go

RUN go build -o docsapi && cp docsapi /usr/bin/docsapi

FROM alpine

COPY --from=builder /usr/bin/docsapi /root/docsapi

COPY swagger.json /root/swagger.json

COPY swagger.yaml /root/swagger.yaml

WORKDIR /root

EXPOSE 8080

CMD /root/docsapi
1 change: 1 addition & 0 deletions docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
func main() {
app := fiber.New()
app.Use(swagger.New(swagger.Config{
Title: "Zentao API documentation",
Path: "swagger",
BasePath: "/",
FilePath: "./swagger.json",
Expand Down

0 comments on commit b8fe799

Please sign in to comment.