Skip to content

Commit

Permalink
Feat: release to docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Oct 5, 2023
1 parent 1b1856f commit ed7dd1e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 10 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: release_docker

on:
push:
tags:
- '*'

jobs:
release_docker:
name: Release Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: synctvorg/synctv

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From alpine:latest as builder

ARG VERSION=v0.0.0

WORKDIR /synctv

COPY ./ ./

RUN apk add --no-cache bash curl gcc git go musl-dev

RUN bash build.sh -P -v ${VERSION} -b build

From alpine:latest

WORKDIR /opt/synctv

ENV SERVER_LISTEN=0.0.0.0

ENV SERVER_PORT=8080

COPY --from=builder /synctv/build/synctv /usr/local/bin/synctv

COPY entrypoint.sh /entrypoint.sh

RUN apk add --no-cache bash ca-certificates su-exec tzdata

RUN chmod +x /entrypoint.sh

ENV PUID=0 PGID=0 UMASK=022

EXPOSE 8080 8080

CMD [ "/entrypoint.sh" ]
49 changes: 43 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ function Help() {
echo "-w set web version (default: latest releases)"
echo "-m set build mode (default: pie)"
echo "-l set ldflags (default: -s -w --extldflags \"-static -fpic -Wl,-z,relro,-z,now\")"
echo "-p set platform (default: linux/amd64,darwin/arm64)"
echo "-p set platform (default: host platform, support: all, linux, darwin, windows)"
echo "-P set trim path (default: disable)"
echo "-b set build result dir (default: build)"
echo "-T set tags (default: jsoniter)"
}

function Init() {
Expand All @@ -31,13 +32,14 @@ function Init() {
fi
BUILD_MODE="pie"
LDFLAGS='-s -w --extldflags "-static -fpic -Wl,-z,relro,-z,now"'
PLATFORM="linux/amd64,darwin/arm64"
PLATFORM=""
TRIM_PATH=""
BUILD_DIR="build"
TAGS="jsoniter"
}

function ParseArgs() {
while getopts "hv:w:m:l:p:Pb:" arg; do
while getopts "hv:w:m:l:p:Pb:T:" arg; do
case $arg in
h)
Help
Expand All @@ -64,6 +66,9 @@ function ParseArgs() {
b)
BUILD_DIR="$OPTARG"
;;
T)
TAGS="$OPTARG"
;;
?)
echo "unkonw argument"
exit 1
Expand Down Expand Up @@ -126,7 +131,11 @@ function InitDep() {
curl -sL "https://github.com/synctv-org/synctv-web/releases/download/${WEB_VERSION}/dist.tar.gz" | tar --strip-components 1 -C "public/dist" -z -x -v -f -
}

ALLOWD_PLATFORM="linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64,windows/arm64"
LINUX_ALLOWED_PLATFORM="linux/386,linux/amd64,linux/arm,linux/arm64,linux/loong64,linux/mips,linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64,linux/ppc64le,linux/riscv64,linux/s390x"
DARWIN_ALLOWED_PLATFORM="darwin/amd64,darwin/arm64"
WINDOWS_ALLOWED_PLATFORM="windows/386,windows/amd64,windows/arm,windows/arm64"

ALLOWED_PLATFORM="$LINUX_ALLOWED_PLATFORM,$DARWIN_ALLOWED_PLATFORM,$WINDOWS_ALLOWED_PLATFORM"

function CheckPlatform() {
platform="$1"
Expand Down Expand Up @@ -159,13 +168,41 @@ function Build() {
EXT=""
fi
if [ "$TRIM_PATH" ]; then
GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)-$GOOS-$GOARCH$EXT" .
GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)-$GOOS-$GOARCH$EXT" .
else
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)-$GOOS-$GOARCH$EXT" .
GOOS=$GOOS GOARCH=$GOARCH go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)-$GOOS-$GOARCH$EXT" .
fi
}

function BuildSingle() {
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"
if [ "$GOOS" == "windows" ]; then
EXT=".exe"
else
EXT=""
fi
echo "build $GOOS/$GOARCH"
if [ "$TRIM_PATH" ]; then
go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)$EXT" .
else
go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$(basename $PWD)$EXT" .
fi
}

function BuildAll() {
if [ ! "$PLATFORM" ]; then
BuildSingle
return
elif [ "$PLATFORM" == "all" ]; then
PLATFORM="$ALLOWD_PLATFORM"
elif [ "$PLATFORM" == "linux" ]; then
PLATFORM="$LINUX_ALLOWED_PLATFORM"
elif [ "$PLATFORM" == "darwin" ]; then
PLATFORM="$DARWIN_ALLOWED_PLATFORM"
elif [ "$PLATFORM" == "windows" ]; then
PLATFORM="$WINDOWS_ALLOWED_PLATFORM"
fi
for platform in $(echo "$PLATFORM" | tr "," "\n"); do
Build "$platform"
done
Expand Down
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

chown -R ${PUID}:${PGID} /opt/synctv/

umask ${UMASK}

exec su-exec ${PUID}:${PGID} synctv server --env-no-prefix --skip-config
5 changes: 4 additions & 1 deletion internal/bootstrap/sysNotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
c chan os.Signal
notifyTaskLock sync.Mutex
notifyTaskQueue = pqueue.NewMaxPriorityQueue[*SysNotifyTask]()
once sync.Once
WaitCbk func()
)

Expand All @@ -34,7 +35,9 @@ func NewSysNotifyTask(name string, task func() error) *SysNotifyTask {
func InitSysNotify() {
c = make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP /*1*/, syscall.SIGINT /*2*/, syscall.SIGQUIT /*3*/, syscall.SIGTERM /*15*/)
WaitCbk = sync.OnceFunc(waitCbk)
WaitCbk = func() {
once.Do(waitCbk)
}
}

func waitCbk() {
Expand Down
9 changes: 6 additions & 3 deletions server/handlers/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ const (

var (
Rooms *rooms
initOnce = sync.OnceFunc(func() {
Rooms = newRooms()
})
once = sync.Once{}
initOnce = func() {
once.Do(func() {
Rooms = newRooms()
})
}
)

var (
Expand Down

0 comments on commit ed7dd1e

Please sign in to comment.