From deb5b95d8ff4cc0f670020eddcd741095428d77d Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 10:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20building=20docker=20iamges=20wit?= =?UTF-8?q?h=20new=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 32 ++++++++++++++++++++++++++++++-- .goreleaser.dashboard.yml | 25 +++++++++++++++++++++++++ Dockerfile | 24 +++++++++++------------- 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 .goreleaser.dashboard.yml diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index caef7e9..afb4100 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -15,6 +15,34 @@ 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: xgoreleaser build + run: | + docker pull --platform linux/amd64 oryd/xgoreleaser:latest + docker run --mount type=bind,source="$(pwd)",target=/project \ + --platform linux/amd64 \ + -e GORELEASER_KEY=$GORELEASER_KEY \ + -v /var/run/docker.sock:/var/run/docker.sock \ + oryd/xgoreleaser:latest --skip-publish --snapshot --rm-dist -f .goreleaser.dashboard.yml + + - name: move dist + run: | + mkdir -p target/linux/{arm,arm64,386,amd64,s390x} + mkdir target/linux/arm/v7/ + mv dist/universal_linux_arm_7/dashboard target/linux/arm/v7/dashboard + mv dist/universal_linux_arm64/dashboard target/linux/arm64/dashboard + mv dist/universal_linux_amd64_v1/dashboard target/linux/amd64/dashboard + mv dist/universal_linux_s390x/dashboard target/linux/s390x/dashboard + - name: Log in to the GHCR uses: docker/login-action@master with: @@ -54,5 +82,5 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x 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/.goreleaser.dashboard.yml b/.goreleaser.dashboard.yml new file mode 100644 index 0000000..52ed7b4 --- /dev/null +++ b/.goreleaser.dashboard.yml @@ -0,0 +1,25 @@ +before: + hooks: + - go mod tidy -v +builds: + - id: universal + env: + - CGO_ENABLED=1 + flags: + - -tags + - sqlite + ldflags: + - -s -w + goos: + - linux + goarch: + - arm + - arm64 + - amd64 + - s390x + goarm: + - 7 + gomips: + - softfloat + main: ./cmd/dashboard + binary: dashboard diff --git a/Dockerfile b/Dockerfile index 7e3b63b..82effa1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,20 @@ -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:latest -FROM alpine:latest +ARG TARGETPLATFORM ENV TZ="Asia/Shanghai" + 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 target/$TARGETPLATFORM/dashboard ./app VOLUME ["/dashboard/data"] EXPOSE 80 5555