From 46d373d45bdf9aad572494231f9ae5b7c59ed59d Mon Sep 17 00:00:00 2001 From: mcoo <2435932516@qq.com> Date: Sat, 25 Jun 2022 13:06:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BA=A4=E5=8F=89=E7=BC=96=E8=AF=91=E5=8A=A0=E5=BF=AB=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/goreleaser.yml | 11 +++++++- Dockerfile | 48 ++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 2fce519..7d827be 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -35,10 +35,19 @@ jobs: with: go-version: 1.16 - - name: Tests & build + name: Tests run: | go mod tidy go test -v ./... + - + name: Build + if: success() && startsWith(github.ref, 'refs/tags/') + run: | + GOOS=linux GOARCH=amd64 go build -o opqbot-manager-amd64 -ldflags="-s -w" . + GOOS=linux GOARCH=arm go build -o opqbot-manager-arm -ldflags="-s -w" . + GOOS=linux GOARCH=arm64 go build -o opqbot-manager-arm64 -ldflags="-s -w" . + GOOS=linux GOARCH=386 go build -o opqbot-manager-386 -ldflags="-s -w" . + ls - name: Set up QEMU if: success() && startsWith(github.ref, 'refs/tags/') diff --git a/Dockerfile b/Dockerfile index 7d485a7..9d35b47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,54 @@ -FROM golang:alpine AS build -WORKDIR $GOPATH/src +#FROM golang:alpine AS build +#WORKDIR $GOPATH/src +FROM alpine:latest AS build +WORKDIR /apps +ARG TARGETPLATFORM +ARG BUILDPLATFORM COPY . . -RUN go mod tidy\ - && go build -o opqbot-manager -ldflags="-s -w" . \ - && apk add upx \ +RUN ls -lh && echo $TARGETPLATFORM \ + && [[ "$TARGETPLATFORM" == "linux/amd64" ]] \ + && mv /apps/opqbot-manager-amd64 /apps/opqbot-manager || echo "not amd64" \ + && [[ "$TARGETPLATFORM" == "linux/arm64" ]] \ + && mv /apps/opqbot-manager-arm64 /apps/opqbot-manager || echo "not arm64" \ + && [[ "$TARGETPLATFORM" == "linux/arm/v7" ]] \ + && mv /apps/opqbot-manager-arm /apps/opqbot-manager || echo "not arm" \ + && [[ "$TARGETPLATFORM" == "linux/386" ]] \ + && mv /apps/opqbot-manager-386 /apps/opqbot-manager || echo "not 386" + + + +# if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; \ +# then \ +# mv ./opqbot-manager-amd64 ./opqbot-manager; \ +# fi \ +# && if ["$TARGETPLATFORM" = "linux/arm64"]; \ +# then \ +# mv ./opqbot-manager-arm64 ./opqbot-manager; \ +# fi \ +# && if ["$TARGETPLATFORM" = "linux/arm/v7"]; \ +# then \ +# mv ./opqbot-manager-arm ./opqbot-manager; \ +# fi \ +# && if ["$TARGETPLATFORM" = "linux/386"]; \ +# then \ +# mv ./opqbot-manager-386 ./opqbot-manager; \ +# fi + +RUN apk add upx \ && upx opqbot-manager \ || echo "UPX Install Failed!" +# RUN go mod tidy\ +# && go build -o opqbot-manager -ldflags="-s -w" . \ +# && apk add upx \ +# && upx opqbot-manager \ +# || echo "UPX Install Failed!" FROM alpine:latest LABEL MAINTAINER enjoy ENV VERSION 1.0 # create a new dir WORKDIR /apps -COPY --from=build /go/src/opqbot-manager /apps/opqbot-manager +COPY --from=build /apps/opqbot-manager /apps/opqbot-manager COPY config.yaml.example /apps/config.yaml.example