Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
xOS committed Sep 3, 2024
1 parent dd1401e commit f94a642
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 74 deletions.
163 changes: 98 additions & 65 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,112 @@ on:
- ".*"

jobs:
release:
build:
strategy:
fail-fast: true
matrix:
goos: [linux, windows]
goarch: [amd64]
include:
- goos: linux
goarch: s390x
- goos: linux
goarch: arm64

name: Build artifacts
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.21
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
outputs:
tag_name: ${{ steps.extract_branch.outputs.tag }}
steps:
- run: git config --global --add safe.directory /__w/xos/serverstatus
- uses: actions/checkout@v4

- name: Fetch IPInfo GeoIP Database
env:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
env:
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
run: |
rm pkg/geoip/geoip.db
wget -O pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${IPINFO_TOKEN}
wget -qO pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${IPINFO_TOKEN}
- name: Extract branch name
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21.x"

- name: Build
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: build --single-target --clean --skip=validate

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dash-${{ env.GOOS }}-${{ env.GOARCH }}
path: |
./dist/*/*
release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets

- name: Archive and compress binaries
run: |
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch
for file in assets/*/*/*; do
if [ -f "$file" ]; then
chmod +x "$file"
zip -jr "$file.zip" "$file"
fi
done
- name: xgo build
uses: crazy-max/ghaction-xgo@v2
- name: Release
uses: ncipollo/release-action@v1
with:
xgo_version: latest
go_version: 1.21.x
dest: dist
pkg: cmd/dashboard
prefix: dash
targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64,windows/amd64,windows/386,windows/arm64 # linux/386,
v: true
x: false
race: false
tags: timetzdata
ldflags: -s -w --extldflags '-static -fpic' -X github.com/xos/serverstatus/service/singleton.Version=${{ steps.extract_branch.outputs.tag }}
buildmode: default

- name: fix dist
artifacts: "assets/*/*/*.zip"
generateReleaseNotes: true


release-docker:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release Docker images
steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets

- name: Fix permissions
run: |
ls -al dist/
mv dist/dash-linux-arm-7 dist/dash-linux-arm
chmod -R +x ./assets/*
mkdir dist
mv ./assets/*/*/* ./dist
- name: Log in to the GHCR
- name: Extract branch name
run: |
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
id: extract_branch

- name: Log into GHCR
uses: docker/login-action@master
with:
registry: ghcr.io
Expand All @@ -75,57 +141,24 @@ jobs:

- name: Set up image name
run: |
GHRC_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/server-dash" | tr '[:upper:]' '[:lower:]')
GHCR_IMAGE_NAME=$(echo "ghcr.io/${{ github.repository_owner }}/server-dash" | tr '[:upper:]' '[:lower:]')
if [ ${{ github.repository_owner }} = "xos" ]
then ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/dns/server-dash")
else ALI_IMAGE_NAME=$(echo "registry.cn-shanghai.aliyuncs.com/${{ github.repository_owner }}/server-dash" | tr '[:upper:]' '[:lower:]')
fi
echo "::set-output name=GHRC_IMAGE_NAME::$GHRC_IMAGE_NAME"
echo "::set-output name=ALI_IMAGE_NAME::$ALI_IMAGE_NAME"
echo "GHCR_IMAGE_NAME=$GHCR_IMAGE_NAME" >> $GITHUB_OUTPUT
echo "ALI_IMAGE_NAME=$ALI_IMAGE_NAME" >> $GITHUB_OUTPUT
id: image-name

- name: Build dasbboard image And Push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/riscv64 # linux/386,
platforms: linux/amd64,linux/arm64,linux/s390x
push: true
tags: |
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHRC_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.GHCR_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:latest
${{ steps.image-name.outputs.ALI_IMAGE_NAME }}:${{ steps.extract_branch.outputs.tag }}
- name: Compress dist files
run: |
for file in dist/*; do
if [ -f "$file" ]; then
zip -r "$file.zip" "$file"
fi
done
- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.zip"
generateReleaseNotes: true

- name: Purge jsdelivr cache
run: |
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/serverstatus@master/script/server-status.sh
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/serverstatus@master/script/server-agent.service
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/serverstatus@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/serverstatus@master/script/config.yaml
LOWER_USERNAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/script/server-status.sh
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/script/server-agent.service
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/script/docker-compose.yaml
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/script/config.yaml
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/bg/background.jpeg
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/favicon.ico
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/logo.png
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/main.css
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/main.js
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/semantic-ui-alerts.min.css
curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/serverstatus@master/resource/static/semantic-ui-alerts.min.js
71 changes: 71 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: 2
before:
hooks:
- go mod tidy -v
builds:
- id: linux_arm64
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
ldflags:
- -s -w
- -X github.com/xos/serverstatus/service/singleton.Version={{.Version}}
- -extldflags "-static -fpic"
flags:
- -trimpath
goos:
- linux
goarch:
- arm64
main: ./cmd/dashboard
binary: dash-{{ .Os }}-{{ .Arch }}
- id: linux_amd64
env:
- CGO_ENABLED=1
- CC=x86_64-linux-gnu-gcc
ldflags:
- -s -w
- -X github.com/xos/serverstatus/service/singleton.Version={{.Version}}
- -extldflags "-static -fpic"
flags:
- -trimpath
goos:
- linux
goarch:
- amd64
main: ./cmd/dashboard
binary: dash-{{ .Os }}-{{ .Arch }}
- id: linux_s390x
env:
- CGO_ENABLED=1
- CC=s390x-linux-gnu-gcc
ldflags:
- -s -w
- -X github.com/xos/serverstatus/service/singleton.Version={{.Version}}
- -extldflags "-static -fpic"
flags:
- -trimpath
goos:
- linux
goarch:
- s390x
main: ./cmd/dashboard
binary: dash-{{ .Os }}-{{ .Arch }}
- id: windows_amd64
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
ldflags:
- -s -w
- -X github.com/xos/serverstatus/service/singleton.Version={{.Version}}
- -extldflags "-static -fpic"
flags:
- -trimpath
goos:
- windows
goarch:
- amd64
main: ./cmd/dashboard
binary: dash-{{ .Os }}-{{ .Arch }}
snapshot:
version_template: "dashboard"
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
FROM ubuntu:focal-20221130
FROM alpine AS certs
RUN apk update && apk add ca-certificates

ENV TZ="Asia/Shanghai"
FROM busybox:stable-musl

ARG TARGETOS
ARG TARGETARCH

COPY --from=certs /etc/ssl/certs /etc/ssl/certs
COPY ./script/entrypoint.sh /entrypoint.sh
RUN chmod +x /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 && \
chmod +x /entrypoint.sh
WORKDIR /dashboard
COPY ./resource ./resource
COPY dist/dash-${TARGETOS}-${TARGETARCH} ./app

VOLUME ["/dashboard/data"]
EXPOSE 80 2222
ARG TZ=Asia/Shanghai
ENV TZ=$TZ
ENTRYPOINT ["/entrypoint.sh"]
1 change: 1 addition & 0 deletions cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"time"
_ "time/tzdata"

"github.com/ory/graceful"
flag "github.com/spf13/pflag"
Expand Down

0 comments on commit f94a642

Please sign in to comment.