Skip to content

Commit

Permalink
chore: add docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
biuld committed Oct 20, 2024
1 parent a56b9fa commit d44032e
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 16 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Docker

on:
push:
branches:
- main # 当 `main` 分支有 push 时触发
tags:
- 'v*.*.*' # 当有新的 tag 时触发

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3.5.0
with:
cosign-release: 'v2.2.4'

# 设置 Buildx 以支持多架构构建
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# 登录 GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# 提取 Docker 镜像的元数据(标签、名称等)
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=sha
type=ref,event=tag
# 构建并推送多架构 Docker 镜像
- name: Build and push Docker image
uses: docker/build-push-action@v6.9.0
id: build-and-push
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# 使用 cosign 签名发布的 Docker 镜像
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
images=""
for tag in $(echo $TAGS | tr ',' '\n'); do
images+="ghcr.io/${{ github.repository }}:$tag@${DIGEST} "
done
cosign sign --yes ${images}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'

services:
weibo-album-dl:
image: weibo-album-dl:latest
container_name: weibo-album-dl
restart: unless-stopped
volumes:
- ./dl:/dl # 可选:挂载本地目录到容器中
environment:
WB_DL_ARGS: "-s /dl"
39 changes: 23 additions & 16 deletions src/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,34 @@ def run(p: String) =
)
log.info("finished term")

def logHelp(args: Seq[String]) = log.info(s"""
unsupported args: ${args.mkString(" ")}!
try these blow:
-w `path` to walk through uids inside `path`
-s `path` to walk through uids inside `path` periodically (once a day)
-u `uid` to download all images of `uid`
""")

@main
def main(args: String*): Unit =
args match
case "-w" :: dir :: _ => run(dir)
case "-s" :: dir :: _ =>
case _ if args.size == 0 =>
val argsStr = System.getenv("WB_DL_ARGS")
argsStr match
case _ if argsStr != null && argsStr.length() != 0 =>
val argsFromEnv = argsStr.split(" ")
wrappedMain(argsFromEnv*)
case _ => logHelp(Seq("empty char"))
case _ => wrappedMain(args*)

def wrappedMain(args: String*): Unit =
args match
case Seq("-w", dir) => run(dir)
case Seq("-s", dir) =>
scheduler.scheduleWithFixedDelay(() => run(dir), 0, 1, TimeUnit.DAYS)
case "-u" :: uid :: dir :: _ =>
case Seq("-u", uid, dir) =>
val p = util.path(dir)
if !os.exists(p) then throw FileNotFoundException(s"$p does not exists")
val cookies = sinaVisitorSystem
getAlbum(uid, p, cookies)
case _ =>
val argsStr = System.getenv("WB_DL_ARGS")

if argsStr != null && argsStr.length() != 0 then
val args = argsStr.split(" ").toSeq
main(args*)
else log.info(s"""
unsupported args ${args.mkString(" ")}!
try these blow:
-w `path` to walk through uids inside `path`
-s `path` to walk through uids inside `path` periodically (once a day)
-u `uid` to download all images of `uid`
""")
case _ => logHelp(args)
16 changes: 16 additions & 0 deletions weibo-album-dl.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Container]
ContainerName=weibo-album-dl
Environment="WB_DL_ARGS=-s /dl"
Image=weibo-album-dl:latest
Volume=/mnt/sda1/code/dl:/dl
WorkingDir=/app

[Service]
Restart=always

[Unit]
Description=weibo-album-dl
After=network.target

[Install]
WantedBy=multi-user.target

0 comments on commit d44032e

Please sign in to comment.