Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build

on:
push:
tags:
- 'v*.*.*'

jobs:
build-and-push:
name: Build And Push
runs-on: ubuntu-latest
needs: []
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
CURRENT_VERSION=${GITHUB_REF#refs/tags/}
echo "Triggered by tag: $CURRENT_VERSION"
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
else
echo "Triggered by branch push, calculating new version..."
LATEST_TAG=$(git tag -l "v*.*.*" | sort -V | tail -n1)

if [ -z "$LATEST_TAG" ]; then
# If no tag, start from v1.0.0
NEW_VERSION="v1.0.0"
else
echo "Latest tag: $LATEST_TAG"
VERSION_PART=$(echo $LATEST_TAG | sed 's/v//')
MAJOR=$(echo $VERSION_PART | cut -d. -f1)
MINOR=$(echo $VERSION_PART | cut -d. -f2)
PATCH=$(echo $VERSION_PART | cut -d. -f3)

PATCH=$((PATCH + 1))
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
fi

echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
fi

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push to Docker Hub
uses: docker/build-push-action@v3
with:
context: .
target: runtime
platforms: linux/amd64
push: true
tags: ${{ secrets.DOCKERHUB_REPOSITORY }}/taskd:${{ steps.version.outputs.version }},${{ secrets.DOCKERHUB_REPOSITORY }}/taskd:latest
21 changes: 7 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@ COPY . .

RUN go env -w CGO_ENABLED=0 && \
go env -w GO111MODULE=on && \
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,direct
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy,direct

#
#go env -w GOPROXY=http://mirrors.sangfor.org/nexus/repository/go-proxy-group
#
RUN go mod tidy
RUN go build -ldflags="-s -w" -o taskd *.go
RUN chmod 755 taskd

RUN go mod tidy && go build -o taskd *.go
FROM alpine:3.21 AS runtime

FROM centos:7.6.1810
#时区设置
ENV env prod
ENV TZ Asia/Shanghai
WORKDIR /
# RUN curl -O http://10.72.1.16:30574/tools/kubectl
# RUN chmod 777 kubectl
# RUN mv kubectl /usr/bin/
# RUN curl -O http://10.72.1.16:30574/tools/jq
# RUN chmod 777 jq
# RUN mv jq /usr/bin/
COPY --from=builder /app/taskd /usr/local/bin
RUN chmod 755 /usr/local/bin/taskd

COPY --from=builder /app/taskd /usr/local/bin/taskd
ENTRYPOINT ["/usr/local/bin/taskd"]

11 changes: 3 additions & 8 deletions controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ type ResponseData struct {
Code string `json:"code"`
Message string `json:"message"`
Success bool `json:"success"`
Data any `json:"data"`
Data any `json:"data,omitempty"`
}

/**
* Normal API response
*/
func respOK(c *gin.Context, data any) {
utils.Debugf("request: %+v, response: %+v", c.Request.RequestURI, data)
c.JSON(http.StatusOK, ResponseData{
Code: "0",
Message: "OK",
Success: true,
Data: data,
})
c.JSON(http.StatusOK, data)
}

/**
Expand All @@ -43,7 +38,7 @@ func respOK(c *gin.Context, data any) {
func respError(c *gin.Context, code int, err error) {
utils.Errorf("request: %+v, error: %s", c.Request.RequestURI, err.Error())
if httpErr, ok := err.(*utils.HttpError); ok {
c.JSON(code, ResponseData{
c.JSON(httpErr.Code(), ResponseData{
Code: strconv.Itoa(httpErr.Code()),
Message: httpErr.Error(),
Success: false,
Expand Down
1 change: 1 addition & 0 deletions dao/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
*/
type TaskObjRec struct {
UUID string `json:"uuid,omitempty"` // Task UUID
Parent string `json:"parent,omitempty"` // The batch specified by this ID
Namespace string `json:"namespace,omitempty"` // Namespace
Name string `json:"name,omitempty"` // Task name
Project string `json:"project,omitempty"` // Project name
Expand Down
Loading
Loading