diff --git a/.gitea/workflows/go.yaml b/.gitea/workflows/go.yaml index 4fe00d3..85173ab 100644 --- a/.gitea/workflows/go.yaml +++ b/.gitea/workflows/go.yaml @@ -1,24 +1,43 @@ name: Go build -on: [push] +on: + push: + branches: [ master ] jobs: build: name: Build and test runs-on: ubuntu-latest - - container: - image: golang:latest - env: - GO111MODULE: on - GOPROXY: https://goproxy.cn,direct - ports: - - 8080 steps: + - name: Checkout - uses: actions/checkout@v4 - - name: Build - - run: go build -v + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Build project + run: | + go build -v ./... - name: Test with the Go CLI - run: go test \ No newline at end of file + run: go test + + docker: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: | + docker build -t your-image-name:latest -f ./Dockerfile . + + - name: Run Docker container + run: | + docker run -d -p 8080:8080 your-image-name:latest \ No newline at end of file diff --git a/Dokerfile.yaml b/Dokerfile.yaml new file mode 100644 index 0000000..255f378 --- /dev/null +++ b/Dokerfile.yaml @@ -0,0 +1,26 @@ +# 使用官方的 Go 运行时作为基础镜像 +FROM golang:1.18-alpine AS builder + +# 设置工作目录 +WORKDIR /app + +# 将当前目录下的所有文件复制到工作目录中 +COPY . . + +# 构建可执行文件 +RUN CGO_ENABLED=0 GOOS=linux go build -v -o app . + +# 使用一个更小的基础镜像来减小最终镜像的大小 +FROM alpine:latest + +# 设置工作目录 +WORKDIR /root/ + +# 从构建阶段复制可执行文件 +COPY --from=builder /app/app . + +# 暴露端口 +EXPOSE 8080 + +# 运行可执行文件 +CMD ["./app"] \ No newline at end of file