diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index caef7e9..cf943a8 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -15,6 +15,35 @@ jobs: steps: - uses: actions/checkout@master + - name: Extract branch name + run: | + export BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) + echo "##[set-output name=branch;]$BRANCH_NAME" + if [ $BRANCH_NAME = "main" ] || [ $BRANCH_NAME = "master" ] + then echo "##[set-output name=tag;]latest" + else echo "##[set-output name=tag;]$BRANCH_NAME" + fi + id: extract_branch + + - name: xgo build + uses: crazy-max/ghaction-xgo@v2 + with: + xgo_version: latest + go_version: 1.18 + dest: dist + pkg: cmd/dashboard + prefix: dashboard + targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64 # linux/386, + v: true + x: false + race: false + ldflags: -s -w + buildmode: default + + - name: fix dist + run: | + cp dist/dashboard-linux-arm-7 dist/dashboard-linux-arm + - name: Log in to the GHCR uses: docker/login-action@master with: @@ -51,8 +80,8 @@ jobs: with: context: . file: ./Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x + platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386, push: true tags: | - ${{ steps.image-name.outputs.GHRC_IMAGE_NAME }} - ${{ steps.image-name.outputs.ALI_IMAGE_NAME }} + ${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }} + ${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }} diff --git a/Dockerfile b/Dockerfile index 7e3b63b..8a9fc5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,22 @@ -FROM golang:alpine AS binarybuilder -RUN apk --no-cache --no-progress add \ - gcc git musl-dev -WORKDIR /dashboard -COPY . . -RUN cd cmd/dashboard && go build -o app -ldflags="-s -w" +FROM ubuntu:focal -FROM alpine:latest ENV TZ="Asia/Shanghai" + +ARG TARGETOS +ARG TARGETARCH + COPY ./script/entrypoint.sh /entrypoint.sh -RUN apk --no-cache --no-progress add \ - ca-certificates \ - tzdata && \ - cp "/usr/share/zoneinfo/$TZ" /etc/localtime && \ - echo "$TZ" > /etc/timezone && \ + +RUN export DEBIAN_FRONTEND="noninteractive" && \ + apt update && apt install -y ca-certificates tzdata && \ + update-ca-certificates && \ + ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \ + dpkg-reconfigure tzdata && \ chmod +x /entrypoint.sh + WORKDIR /dashboard COPY ./resource ./resource -COPY --from=binarybuilder /dashboard/cmd/dashboard/app ./app +COPY dist/dashboard-${TARGETOS}-${TARGETARCH} ./app VOLUME ["/dashboard/data"] EXPOSE 80 5555 diff --git a/script/entrypoint.sh b/script/entrypoint.sh index dc39b74..c20950f 100644 --- a/script/entrypoint.sh +++ b/script/entrypoint.sh @@ -1,3 +1,3 @@ #!/bin/sh -echo -e "nameserver 127.0.0.11\nnameserver 8.8.8.8\nnameserver 223.5.5.5\n" > /etc/resolv.conf +echo -e "nameserver 127.0.0.11\nnameserver 8.8.4.4\nnameserver 223.5.5.5\n" > /etc/resolv.conf /dashboard/app \ No newline at end of file