diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5c37fc1..093a358 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -140,77 +140,77 @@ checksum: name_template: "{{ .ProjectName }}_checksums.txt" algorithm: sha256 -dockers: - - use: buildx - ids: - - syncer - goos: linux - goarch: amd64 - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/syncer:{{ .Tag }}-amd64 - dockerfile: docker/syncer/Dockerfile.release - build_flag_templates: - - --pull - - --platform=linux/amd64 - - --label=io.sealos.image.created={{.Date}} - - --label=io.sealos.image.title=syncer - - --label=io.sealos.image.revision={{.ShortCommit}} - - --label=io.sealos.image.version={{.Tag }} - - --label=io.sealos.image.auth={{ .Env.USERNAME }} - - use: buildx - ids: - - syncer - goos: linux - goarch: arm64 - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/syncer:{{ .Tag }}-arm64 - dockerfile: docker/syncer/Dockerfile.release - build_flag_templates: - - --pull - - --platform=linux/arm64 - - --label=io.sealos.image.created={{.Date}} - - --label=io.sealos.image.title=lvscare - - --label=io.sealos.image.revision={{.ShortCommit}} - - --label=io.sealos.image.version={{.Tag }} - - --label=io.sealos.image.auth={{ .Env.USERNAME }} - - use: buildx - ids: - - sealos - goos: linux - goarch: amd64 - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-amd64 - dockerfile: docker/sealos/Dockerfile.release - build_flag_templates: - - --pull - - --platform=linux/amd64 - - --label=io.sealos.image.created={{.Date}} - - --label=io.sealos.image.title=sealos - - --label=io.sealos.image.revision={{.ShortCommit}} - - --label=io.sealos.image.version={{.Tag }} - - --label=io.sealos.image.auth={{ .Env.USERNAME }} - - use: buildx - ids: - - sealos - goos: linux - goarch: arm64 - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-arm64 - dockerfile: docker/sealos/Dockerfile.release - build_flag_templates: - - --pull - - --platform=linux/arm64 - - --label=io.sealos.image.created={{.Date}} - - --label=io.sealos.image.title=sealos - - --label=io.sealos.image.revision={{.ShortCommit}} - - --label=io.sealos.image.version={{.Tag }} - - --label=io.sealos.image.auth={{ .Env.USERNAME }} -docker_manifests: - - name_template: ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }} - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }}-amd64 - - ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }}-arm64 - - name_template: ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }} - image_templates: - - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-amd64 - - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-arm64 +# dockers: +# - use: buildx +# ids: +# - syncer +# goos: linux +# goarch: amd64 +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/syncer:{{ .Tag }}-amd64 +# dockerfile: docker/syncer/Dockerfile.release +# build_flag_templates: +# - --pull +# - --platform=linux/amd64 +# - --label=io.sealos.image.created={{.Date}} +# - --label=io.sealos.image.title=syncer +# - --label=io.sealos.image.revision={{.ShortCommit}} +# - --label=io.sealos.image.version={{.Tag }} +# - --label=io.sealos.image.auth={{ .Env.USERNAME }} +# - use: buildx +# ids: +# - syncer +# goos: linux +# goarch: arm64 +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/syncer:{{ .Tag }}-arm64 +# dockerfile: docker/syncer/Dockerfile.release +# build_flag_templates: +# - --pull +# - --platform=linux/arm64 +# - --label=io.sealos.image.created={{.Date}} +# - --label=io.sealos.image.title=lvscare +# - --label=io.sealos.image.revision={{.ShortCommit}} +# - --label=io.sealos.image.version={{.Tag }} +# - --label=io.sealos.image.auth={{ .Env.USERNAME }} +# - use: buildx +# ids: +# - sealos +# goos: linux +# goarch: amd64 +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-amd64 +# dockerfile: docker/sealos/Dockerfile.release +# build_flag_templates: +# - --pull +# - --platform=linux/amd64 +# - --label=io.sealos.image.created={{.Date}} +# - --label=io.sealos.image.title=sealos +# - --label=io.sealos.image.revision={{.ShortCommit}} +# - --label=io.sealos.image.version={{.Tag }} +# - --label=io.sealos.image.auth={{ .Env.USERNAME }} +# - use: buildx +# ids: +# - sealos +# goos: linux +# goarch: arm64 +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-arm64 +# dockerfile: docker/sealos/Dockerfile.release +# build_flag_templates: +# - --pull +# - --platform=linux/arm64 +# - --label=io.sealos.image.created={{.Date}} +# - --label=io.sealos.image.title=sealos +# - --label=io.sealos.image.revision={{.ShortCommit}} +# - --label=io.sealos.image.version={{.Tag }} +# - --label=io.sealos.image.auth={{ .Env.USERNAME }} +# docker_manifests: +# - name_template: ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }} +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }}-amd64 +# - ghcr.io/{{ .Env.USERNAME }}/lvscare:{{ .Tag }}-arm64 +# - name_template: ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }} +# image_templates: +# - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-amd64 +# - ghcr.io/{{ .Env.USERNAME }}/sealos:{{ .Tag }}-arm64 diff --git a/deploy/Dockerfile.exporter b/deploy/Dockerfile.exporter index 8bf9335..d2f8f00 100644 --- a/deploy/Dockerfile.exporter +++ b/deploy/Dockerfile.exporter @@ -1,15 +1,24 @@ -FROM golang:1.20-alpine -# docker build -t exporter:1.0 -f ./Dockerfile.exporter . +# 构建阶段1:构建二进制文件 +FROM golang:1.20 as builder + +# 设置工作目录 WORKDIR /app -COPY . . +# 复制项目文件到容器中 +COPY cmd/exporter/main.go go.mod go.sum /app/ -RUN apk update && apk add make +# 构建二进制文件 +RUN CGO_ENABLED=0 GOOS=linux go build -o exporter main.go -RUN make exporter +# 构建阶段2:生成最终镜像 FROM alpine:latest -COPY --from=0 /app/_output/bin/platforms/linux/amd64/exporter /app/exporter +# 设置工作目录 +WORKDIR /app + +# 从构建阶段1中复制二进制文件到容器中 +COPY --from=builder /app/exporter /app/exporter -ENTRYPOINT ["/app/exporter"] +# 运行二进制文件 +CMD ["/app/exporter --help"] diff --git a/deploy/Dockerfile.syncer b/deploy/Dockerfile.syncer index 456f5c7..dec8e49 100644 --- a/deploy/Dockerfile.syncer +++ b/deploy/Dockerfile.syncer @@ -1,15 +1,25 @@ FROM golang:1.20-alpine # docker build -t syncer:1.0 -f ./Dockerfile.syncer . -WORKDIR /app +# 构建阶段1:构建二进制文件 +FROM golang:1.20 as builder -COPY . . +# 设置工作目录 +WORKDIR /app -RUN apk update && apk add make +# 复制项目文件到容器中 +COPY cmd/exporter/main.go go.mod go.sum /app/ -RUN make syncer +# 构建二进制文件 +RUN CGO_ENABLED=0 GOOS=linux go build -o exporter main.go +# 构建阶段2:生成最终镜像 FROM alpine:latest -COPY --from=0 /app/_output/bin/platforms/linux/amd64/syncer /app/syncer +# 设置工作目录 +WORKDIR /app + +# 从构建阶段1中复制二进制文件到容器中 +COPY --from=builder /app/syncer /app/syncer -ENTRYPOINT ["/app/syncer"] +# 运行二进制文件 +CMD ["/app/syncer --help"]