From deb5b95d8ff4cc0f670020eddcd741095428d77d Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 10:27:14 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=F0=9F=91=B7=20building=20docker=20iamges?= =?UTF-8?q?=20with=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 From 181893eab7e532896ff136171989a3f4ba9d4a10 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 10:35:59 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=92=9A=20fix=20DOCKER=5FUSERNAME:?= =?UTF-8?q?=20unbound=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index afb4100..0338ca0 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -31,6 +31,8 @@ jobs: docker run --mount type=bind,source="$(pwd)",target=/project \ --platform linux/amd64 \ -e GORELEASER_KEY=$GORELEASER_KEY \ + -e DOCKER_USERNAME=$DOCKER_USERNAME \ + -e DOCKER_PASSWORD=$DOCKER_PASSWORD \ -v /var/run/docker.sock:/var/run/docker.sock \ oryd/xgoreleaser:latest --skip-publish --snapshot --rm-dist -f .goreleaser.dashboard.yml From 8b78cae228903e05ada70c1364f635524ac2d67c Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 10:52:21 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=92=9A=20override=20entrypoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 0338ca0..ae6cf16 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -30,10 +30,8 @@ jobs: 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 \ - -e DOCKER_USERNAME=$DOCKER_USERNAME \ - -e DOCKER_PASSWORD=$DOCKER_PASSWORD \ -v /var/run/docker.sock:/var/run/docker.sock \ + --entrypoint goreleaser \ oryd/xgoreleaser:latest --skip-publish --snapshot --rm-dist -f .goreleaser.dashboard.yml - name: move dist From 3ceb286f2c920062a013500f5e5bf764a327de17 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 11:21:54 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=F0=9F=92=9A=20use=20xgo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 24 ++++++++++++++++-------- .goreleaser.dashboard.yml | 25 ------------------------- 2 files changed, 16 insertions(+), 33 deletions(-) delete mode 100644 .goreleaser.dashboard.yml diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index ae6cf16..3795e5e 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -25,17 +25,25 @@ jobs: 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 \ - -v /var/run/docker.sock:/var/run/docker.sock \ - --entrypoint goreleaser \ - oryd/xgoreleaser:latest --skip-publish --snapshot --rm-dist -f .goreleaser.dashboard.yml + - name: Build + uses: crazy-max/ghaction-xgo@v2 + with: + xgo_version: latest + go_version: 1.18 + dest: build + pkg: cmd/dashboard + prefix: dashboard + targets: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x + v: true + x: false + race: false + ldflags: -s -w + buildmode: default - name: move dist run: | + ls -al dist + tree dist 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 diff --git a/.goreleaser.dashboard.yml b/.goreleaser.dashboard.yml deleted file mode 100644 index 52ed7b4..0000000 --- a/.goreleaser.dashboard.yml +++ /dev/null @@ -1,25 +0,0 @@ -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 From 468257ebd3550a56e86a8d7af627eec55c91f34a Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 11:50:25 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=F0=9F=91=B7=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 3795e5e..0777b4a 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -25,12 +25,13 @@ jobs: fi id: extract_branch - - name: Build + - name: xgo build uses: crazy-max/ghaction-xgo@v2 with: xgo_version: latest go_version: 1.18 - dest: build + arm_version: 7 + dest: dist pkg: cmd/dashboard prefix: dashboard targets: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x @@ -42,14 +43,13 @@ jobs: - name: move dist run: | - ls -al dist - tree dist 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 + mv dist/dashboard-linux-arm-7 target/linux/arm/v7/dashboard + mv dist/dashboard-linux-arm64 target/linux/arm64/dashboard + mv dist/dashboard-linux-386 target/linux/386/dashboard + mv dist/dashboard-linux-amd64 target/linux/amd64/dashboard + mv dist/dashboard-linux-s390x target/linux/s390x/dashboard - name: Log in to the GHCR uses: docker/login-action@master From a9e49afdfc0dabd5e72d4caa89c5d36392f562a9 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 12:13:21 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=F0=9F=92=9A=20fix=20arm/v7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 0777b4a..fb61ba3 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -30,11 +30,10 @@ jobs: with: xgo_version: latest go_version: 1.18 - arm_version: 7 dest: dist pkg: cmd/dashboard prefix: dashboard - targets: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x + targets: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/s390x v: true x: false race: false From 66d3e83e995076222464891480c27783b83da581 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 13:14:07 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=F0=9F=92=9A=20arm-7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index fb61ba3..2659c25 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -33,7 +33,7 @@ jobs: dest: dist pkg: cmd/dashboard prefix: dashboard - targets: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/s390x + targets: linux/amd64,linux/arm64,linux/arm-7,linux/386,linux/s390x v: true x: false race: false From 9419b02cd3b7093c408c5d0ec54cd80cb96ee18e Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 13:38:44 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=F0=9F=92=9A=20fix=20dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 14 ++++---------- Dockerfile | 18 ++++++++++-------- script/entrypoint.sh | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 2659c25..e8ee1bb 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -33,22 +33,16 @@ jobs: dest: dist pkg: cmd/dashboard prefix: dashboard - targets: linux/amd64,linux/arm64,linux/arm-7,linux/386,linux/s390x + targets: linux/amd64,linux/arm64,linux/arm-7,linux/386,linux/s390x,linux/riscv64 v: true x: false race: false ldflags: -s -w buildmode: default - - name: move dist + - name: fix dist run: | - mkdir -p target/linux/{arm,arm64,386,amd64,s390x} - mkdir target/linux/arm/v7/ - mv dist/dashboard-linux-arm-7 target/linux/arm/v7/dashboard - mv dist/dashboard-linux-arm64 target/linux/arm64/dashboard - mv dist/dashboard-linux-386 target/linux/386/dashboard - mv dist/dashboard-linux-amd64 target/linux/amd64/dashboard - mv dist/dashboard-linux-s390x target/linux/s390x/dashboard + cp dist/dashboard-linux-arm-7 dist/dashboard-linux-arm - name: Log in to the GHCR uses: docker/login-action@master @@ -86,7 +80,7 @@ jobs: with: context: . file: ./Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x + platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x,linux/riscv64 push: true tags: | ${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }} diff --git a/Dockerfile b/Dockerfile index 82effa1..f942930 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,22 @@ -FROM ubuntu:latest +ARG TARGETARCH +ARG TARGETOS + +FROM $TARGETARCH/ubuntu:20.04 -ARG TARGETPLATFORM ENV TZ="Asia/Shanghai" COPY ./script/entrypoint.sh /entrypoint.sh -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 && +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 target/$TARGETPLATFORM/dashboard ./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 From 8f5adc53e02369dd60b6f4e36399b2d2f2c5ee25 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 13:54:19 +0800 Subject: [PATCH 09/11] test --- Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f942930..fe5adfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,4 @@ -ARG TARGETARCH -ARG TARGETOS - -FROM $TARGETARCH/ubuntu:20.04 +FROM ${TARGETARCH}/ubuntu:20.04 ENV TZ="Asia/Shanghai" @@ -16,7 +13,7 @@ RUN export DEBIAN_FRONTEND="noninteractive" && \ WORKDIR /dashboard COPY ./resource ./resource -COPY dist/dashboard-$TARGETOS-$TARGETARCH ./app +COPY dist/dashboard-${TARGETOS}-${TARGETARCH} ./app VOLUME ["/dashboard/data"] EXPOSE 80 5555 From 532b0aaca1899e48d833250b71a09e924f855772 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 14:09:01 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=F0=9F=92=9A=20remove=20i386?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 4 ++-- Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index e8ee1bb..cf943a8 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -33,7 +33,7 @@ jobs: dest: dist pkg: cmd/dashboard prefix: dashboard - targets: linux/amd64,linux/arm64,linux/arm-7,linux/386,linux/s390x,linux/riscv64 + targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64 # linux/386, v: true x: false race: false @@ -80,7 +80,7 @@ jobs: with: context: . file: ./Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm,linux/386,linux/s390x,linux/riscv64 + platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386, push: true tags: | ${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }} diff --git a/Dockerfile b/Dockerfile index fe5adfb..b05ab64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ${TARGETARCH}/ubuntu:20.04 +FROM ubuntu:focal ENV TZ="Asia/Shanghai" From befc0608a80b5487e93ade9bf8d237919d203d10 Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 7 Jul 2022 14:45:03 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=F0=9F=92=9A=20add=20arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index b05ab64..8a9fc5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,9 @@ FROM ubuntu:focal ENV TZ="Asia/Shanghai" +ARG TARGETOS +ARG TARGETARCH + COPY ./script/entrypoint.sh /entrypoint.sh RUN export DEBIAN_FRONTEND="noninteractive" && \