Skip to content

Commit

Permalink
Merge pull request #12 from shiguredo/feature/refactoring
Browse files Browse the repository at this point in the history
Feature/refactoring
  • Loading branch information
Hexa authored Oct 19, 2023
2 parents 9904859 + 4a18a58 commit 93c10e9
Show file tree
Hide file tree
Showing 25 changed files with 470 additions and 363 deletions.
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)
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

0 comments on commit 93c10e9

Please sign in to comment.