Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactoring #12

Merged
merged 30 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e0d9f7f
s3 は特別扱いする
voluntas May 8, 2023
32e9751
リファクタリング
voluntas May 9, 2023
76cc5f1
不要なコメント削除
voluntas May 9, 2023
1351d17
workflow 整理
voluntas May 9, 2023
fcaf523
script/ に移動
voluntas May 9, 2023
16ccbe8
renovate 更新
voluntas May 9, 2023
bcc2278
Merge branch 'develop' into feature/refactoring
voluntas Jun 9, 2023
b39f6a0
lumberjack を本家にする
voluntas Jun 9, 2023
bdc1c74
ライブラリアップデート
voluntas Aug 1, 2023
6af3775
Merge branch 'develop' into feature/refactoring
voluntas Aug 1, 2023
a983720
go.sum アップデート
voluntas Aug 1, 2023
76de8f0
Merge branch 'feature/refactoring' of github.com:shiguredo/sora-archi…
voluntas Aug 1, 2023
b53c4ca
go 1.21 に上げる
voluntas Aug 17, 2023
4c40f0a
go.sum 更新
voluntas Aug 17, 2023
bcbb5df
ライブラリアップデート
voluntas Aug 29, 2023
e50c38e
ログ周りを整備
voluntas Aug 31, 2023
04303a4
2023.1.5
voluntas Aug 31, 2023
9e8420d
config.ini
voluntas Aug 31, 2023
1f251be
VERSION ファイルを導入して Makefile を整理する
voluntas Sep 8, 2023
15af3d3
Merge branch 'develop' into feature/refactoring
voluntas Oct 11, 2023
cabecfc
rate limit のプロトタイプを追加
voluntas Oct 12, 2023
8411f6e
nil Context をやめる
Hexa Oct 12, 2023
880e326
UploaderManager に limiter を持たせる
Hexa Oct 12, 2023
957fc33
Revert "UploaderManager に limiter を持たせる"
Hexa Oct 13, 2023
a93c9ee
説明を追記する
Hexa Oct 13, 2023
43ba089
アップロード速度の制限を追加する
Hexa Oct 17, 2023
31c9e54
go.mod アップデート
voluntas Oct 17, 2023
9382f92
config に upload_file_rate_limit_mbps を追加する
Hexa Oct 18, 2023
10d1b6d
改行を取り除く
Hexa Oct 19, 2023
4a18a58
Merge branch 'develop' into feature/refactoring
Hexa Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
":timezone(Asia/Tokyo)",
":combinePatchMinorReleases",
":prHourlyLimitNone",
":prConcurrentLimit10",
"group:recommended",
"group:allNonMajor",
"schedule:weekly"
],
"dependencyDashboard": false,
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"platformAutomerge": true,
"automerge": true
}
]
}
30 changes: 30 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci
on:
push:
branches-ignore:
- "master"
tags-ignore:
- "*"

jobs:
build:
name: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: setup go
uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
cache: true
cache-dependency-path: ./go.sum
- run: go version
- run: go fmt .
- uses: dominikh/staticcheck-action@v1
with:
version: "2023.1.5"
install-go: false
- name: Test
run: make test
- name: Build
run: make
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: release

on:
push:
tags:
- "*"

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
cache: false

- run: go install github.com/tcnksm/ghr@latest

- name: Build
run: |
GOOS=linux GOARCH=amd64 go build -o dist/sora-archive-uploader_linux_amd64 cmd/sora-archive-uploader/main.go
GOOS=darwin GOARCH=amd64 go build -o dist/sora-archive-uploader_darwin_amd64 cmd/sora-archive-uploader/main.go
GOOS=darwin GOARCH=arm64 go build -o dist/sora-archive-uploader_darwin_arm64 cmd/sora-archive-uploader/main.go
gzip dist/*

- name: Release
run: |
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${{ github.repository_owner }}" -r "sora-archive-uploader" --replace "${GITHUB_REF##*/}" dist/
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bin/*
config.toml
*.jsonl
config.ini
*.jsonl
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 変更履歴

- CHANGE
- 下位互換のない変更
- UPDATE
- 下位互換がある変更
- ADD
- 下位互換がある追加
- FIX
- バグ修正

## develop
21 changes: 4 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
VERSION := 2022.1.0
REVISION := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := "-X main.version=$(VERSION) -X main.revision=$(REVISION) -X main.buildDate=$(BUILD_DATE)"
LDFLAGS_PROD := "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)"
.PHONY: all test

export GO1111MODULE=on
export CWD=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

.PHONY: all sora-archive-uploader-dev sora-archive-uploader-prod
all: sora-archive-uploader-dev

sora-archive-uploader-dev: cmd/sora-archive-uploader/main.go
go build -race -ldflags $(LDFLAGS) -o bin/$@ $<

sora-archive-uploader-prod: cmd/sora-archive-uploader/main.go
go build -ldflags $(LDFLAGS_PROD) -o bin/$@ $<
all:
go build -o bin/sora-archive-uploader cmd/sora-archive-uploader/main.go

test:
go test -v
go test -race -v ./s3
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Sora Archive Uploader

<!-- [![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/shiguredo/sora-archive-uploader.svg)](https://github.com/shiguredo/sora-archive-uploader) -->

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

<!-- [![Actions Status](https://github.com/shiguredo/sora-archive-uploader/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/shiguredo/sora_exporter/actions/workflows/ci.yml) -->

## About Shiguredo's open source software
Expand Down Expand Up @@ -46,17 +48,17 @@ Sora Cloud では出力されたファイルをオブジェクトストレージ

## まずは使ってみる

config.toml に必要な情報を設定してください。
config.ini に必要な情報を設定してください。

```console
$ cp config.example.com config.toml
$ cp config_example.ini config.ini
```

make でビルドして実行します。

```console
$ make
$ ./bin/sora-archive-uploader-dev -C config.toml
$ ./bin/sora-archive-uploader-dev -C config.ini
```

## Discord
Expand All @@ -71,7 +73,7 @@ https://discord.gg/shiguredo

- オープンソースでの公開が前提
- 可能であれば企業名の公開
- 公開が難しい場合は `企業名非公開` と書かせていただきます
- 公開が難しい場合は `企業名非公開` と書かせていただきます

### 機能

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.1.0
28 changes: 8 additions & 20 deletions cmd/sora-archive-uploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,23 @@ import (
"flag"
"fmt"
"log"
"os"

archive "github.com/shiguredo/sora-archive-uploader"
)

var (
version string
revision string
buildDate string

versionText = `sora-archive-uploader build info.
version: %s
revision: %s
build date: %s
`
)

func main() {
configFilePath := flag.String("C", "config.toml", "Config file path")
var v bool
flag.BoolVar(&v, "version", false, "Show version")
// /bin/sora-archive-uploader -V
showVersion := flag.Bool("V", false, "バージョン")

// /bin/sora-archive-uploader -C ./config.ini
configFilePath := flag.String("C", "./config.ini", "Config file path")
flag.Parse()

if v {
fmt.Printf(versionText, version, revision, buildDate)
os.Exit(0)
if *showVersion {
fmt.Printf("Sora Archive Uploader version %s\n", archive.Version)
Hexa marked this conversation as resolved.
Show resolved Hide resolved
return
}

log.Printf("sora-archive-uploader version:%s revision:%s build_date:%s", version, revision, buildDate)
log.Printf("config file path: %s", *configFilePath)
archive.Run(configFilePath)
}
95 changes: 59 additions & 36 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,79 @@
package archive

import (
"github.com/BurntSushi/toml"
_ "embed"

"gopkg.in/ini.v1"
)

//go:embed VERSION
var Version string

const (
DefaultLogDir = "."
DefaultLogName = "sora-archive-uploader.jsonl"

// megabytes
DefaultLogRotateMaxSize = 200
DefaultLogRotateMaxBackups = 7
// days
DefaultLogRotateMaxAge = 30
)

type Config struct {
Debug bool `toml:"debug"`
Debug bool `ini:"debug"`

LogDir string `toml:"log_dir"`
LogName string `toml:"log_name"`
LogStdOut bool `toml:"log_std_out"`
LogRotateMaxSize int `toml:"log_rotate_max_size"`
LogRotateMaxBackups int `toml:"log_rotate_max_backups"`
LogRotateMaxAge int `toml:"log_rotate_max_age"`
LogRotateCompress bool `toml:"log_rotate_compress"`
LogDir string `ini:"log_dir"`
LogName string `ini:"log_name"`
LogStdout bool `ini:"log_stdout"`

ObjectStorageEndpoint string `toml:"object_storage_endpoint"`
ObjectStorageBucketName string `toml:"object_storage_bucket_name"`
ObjectStorageAccessKeyID string `toml:"object_storage_access_key_id"`
ObjectStorageSecretAccessKey string `toml:"object_storage_secret_access_key"`
LogRotateMaxSize int `ini:"log_rotate_max_size"`
LogRotateMaxBackups int `ini:"log_rotate_max_backups"`
LogRotateMaxAge int `ini:"log_rotate_max_age"`
LogRotateCompress bool `ini:"log_rotate_compress"`

SoraArchiveDirFullPath string `toml:"archive_dir_full_path"`
SoraEvacuateDirFullPath string `toml:"evacuate_dir_full_path"`
ObjectStorageEndpoint string `ini:"object_storage_endpoint"`
ObjectStorageBucketName string `ini:"object_storage_bucket_name"`
ObjectStorageAccessKeyID string `ini:"object_storage_access_key_id"`
ObjectStorageSecretAccessKey string `ini:"object_storage_secret_access_key"`

UploadWorkers int `toml:"upload_workers"`
SoraArchiveDirFullPath string `ini:"archive_dir_full_path"`
SoraEvacuateDirFullPath string `ini:"evacuate_dir_full_path"`

UploadedFileCacheSize int `toml:"uploaded_file_cache_size"`
UploadWorkers int `ini:"upload_workers"`

WebhookEndpointURL string `toml:"webhook_endpoint_url"`
WebhookEndpointHealthCheckURL string `toml:"webhook_endpoint_health_check_url"`
// 1 ファイルあたりのアップロードレート制限
UploadFileRateLimitMbps int `ini:"upload_file_rate_limit_mbps"`

WebhookTypeHeaderName string `toml:"webhook_type_header_name"`
WebhookTypeArchiveUploaded string `toml:"webhook_type_archive_uploaded"`
WebhookTypeSplitArchiveUploaded string `toml:"webhook_type_split_archive_uploaded"`
WebhookTypeSplitArchiveEndUploaded string `toml:"webhook_type_split_archive_end_uploaded"`
WebhookTypeReportUploaded string `toml:"webhook_type_report_uploaded"`
UploadedFileCacheSize int `ini:"uploaded_file_cache_size"`

WebhookBasicAuthUsername string `toml:"webhook_basic_auth_username"`
WebhookBasicAuthPassword string `toml:"webhook_basic_auth_password"`
WebhookEndpointURL string `ini:"webhook_endpoint_url"`
WebhookEndpointHealthCheckURL string `ini:"webhook_endpoint_health_check_url"`

WebhookRequestTimeoutS int32 `toml:"webhook_request_timeout_s"`
WebhookTypeHeaderName string `ini:"webhook_type_header_name"`
WebhookTypeArchiveUploaded string `ini:"webhook_type_archive_uploaded"`
WebhookTypeSplitArchiveUploaded string `ini:"webhook_type_split_archive_uploaded"`
WebhookTypeSplitArchiveEndUploaded string `ini:"webhook_type_split_archive_end_uploaded"`
WebhookTypeReportUploaded string `ini:"webhook_type_report_uploaded"`

WebhookTlsVerifyCacertPath string `toml:"webhook_tls_verify_cacert_path"`
WebhookTlsFullchainPath string `toml:"webhook_tls_fullchain_path"`
WebhookTlsPrivkeyPath string `toml:"webhook_tls_privkey_path"`
WebhookBasicAuthUsername string `ini:"webhook_basic_auth_username"`
WebhookBasicAuthPassword string `ini:"webhook_basic_auth_password"`

WebhookRequestTimeoutS int32 `ini:"webhook_request_timeout_s"`

WebhookTLSVerifyCacertPath string `ini:"webhook_tls_verify_cacert_path"`
WebhookTLSFullchainPath string `ini:"webhook_tls_fullchain_path"`
WebhookTLSPrivkeyPath string `ini:"webhook_tls_privkey_path"`
}

func initConfig(data []byte, config interface{}) error {
if err := toml.Unmarshal(data, config); err != nil {
return err
func newConfig(configFilePath string) (*Config, error) {
config := new(Config)
iniConfig, err := ini.InsensitiveLoad(configFilePath)
if err != nil {
return nil, err
}

// TODO: 初期値
return nil
if err := iniConfig.StrictMapTo(config); err != nil {
return nil, err
}
return config, nil
}
Loading