diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 7d22090..7cb048c 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -9,9 +9,6 @@ on: jobs: release: runs-on: ubuntu-latest - container: - image: azenkain/go-node:latest - steps: - uses: actions/checkout@v4 @@ -20,19 +17,13 @@ jobs: mkdir -p assets/resources printf "%s" "${{ secrets.ENV_FILE }}" > assets/resources/.env - - name: Download Go dependencies - run: go mod download - - - name: Build for linux (embed env) - run: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o build/history-api ./cmd/history-api - - name: Stop and remove old containers run: | - docker compose down --remove-orphans || true + docker compose down || true - - name: Clean up only this project images + - name: Remove unused Docker resources run: | - docker image prune -f + docker system prune -a --volumes -f - name: Build and restart containers run: | diff --git a/Dockerfile b/Dockerfile index 20ce1ab..e9fd58a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,17 @@ +FROM golang:1.26.1-alpine AS builder + +RUN apk add --no-cache git + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \ + go build -trimpath -ldflags="-s -w" -o history-api ./cmd/history-api + FROM alpine:latest RUN apk --no-cache add ca-certificates tzdata @@ -5,9 +19,11 @@ ENV TZ=Asia/Ho_Chi_Minh WORKDIR /app -COPY build/history-api . +COPY --from=builder /app/history-api . COPY data ./data +RUN chmod +x ./history-api + EXPOSE 3344 CMD ["./history-api"] \ No newline at end of file