Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
feat: web interface, scan-stats and jellyfin and autoscan targets (#103)
Browse files Browse the repository at this point in the history
* build: new build process

* refactor: use a cgo-less sqlite

* fix(processor): do not process scans when no targets are set

* feat(processor): database migrations

* feat(targets): autoscan

* feat(triggers): manual trigger web interface

* feat(targets): jellyfin

* feat: scan-stats to display remaining scans
  • Loading branch information
l3uddz authored Mar 18, 2021
1 parent 8e28242 commit 8118c89
Show file tree
Hide file tree
Showing 30 changed files with 1,211 additions and 206 deletions.
124 changes: 81 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
# dependencies
- name: goreleaser
run: |
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sudo sh -s -- -b /usr/local/bin
- name: qemu
uses: docker/setup-qemu-action@v1

- name: buildx
uses: docker/setup-buildx-action@v1

# checkout
- name: checkout
uses: actions/checkout@v2
Expand All @@ -21,9 +32,12 @@ jobs:
- name: go
uses: actions/setup-go@v1
with:
go-version: 1.14
- run: go version
- run: go env
go-version: 1.16

- name: go info
run: |
go version
go env
# cache
- name: cache
Expand All @@ -39,24 +53,26 @@ jobs:
run: |
make vendor
# test
- name: tests
run: |
make test
# git status
- name: git status
run: git status

# build
- name: build
if: startsWith(github.ref, 'refs/tags/') == false
run: |
make snapshot
# get tag name
- name: tag_name
if: startsWith(github.ref, 'refs/tags/')
uses: little-core-labs/[email protected]
with:
tagRegex: "v?(.+)"

# publish
- name: publish
if: startsWith(github.ref, 'refs/tags/')
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
make publish
Expand All @@ -74,42 +90,64 @@ jobs:
name: build_darwin
path: dist/*darwin*

# docker login
- name: docker login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
# docker build (latest & tag)
- name: docker - build latest
- name: release tag
if: startsWith(github.ref, 'refs/tags/') == true
uses: docker/build-push-action@v1
uses: little-core-labs/[email protected]
id: releasetag
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: cloudb0x/autoscan
dockerfile: docker/Dockerfile
tags: latest
tag_with_ref: true
tag_with_sha: true
always_pull: true

# docker build (master)
- name: docker - build master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v1
tagRegex: "v?(.+)"

- name: docker - build release
if: startsWith(github.ref, 'refs/tags/') == true
uses: docker/build-push-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: cloudb0x/autoscan
dockerfile: docker/Dockerfile
tags: master
tag_with_sha: true
always_pull: true
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
tags: |
cloudb0x/autoscan:${{ steps.releasetag.outputs.tag }}
cloudb0x/autoscan:latest
# docker build (branch)
- name: docker - build other
if: startsWith(github.ref, 'refs/heads/master') == false
uses: docker/build-push-action@v1
- name: branch name
if: startsWith(github.ref, 'refs/tags/') == false
id: branch-name
uses: tj-actions/[email protected]

- name: docker tag
if: startsWith(github.ref, 'refs/tags/') == false
uses: frabert/replace-string-action@master
id: dockertag
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: cloudb0x/autoscan
dockerfile: docker/Dockerfile
tag_with_ref: true
tag_with_sha: false
always_pull: true
pattern: '[:\.\/]+'
string: "${{ steps.branch-name.outputs.current_branch }}"
replace-with: '-'
flags: 'g'

- name: docker - build branch
if: startsWith(github.ref, 'refs/tags/') == false
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
tags: |
cloudb0x/autoscan:${{ steps.dockertag.outputs.replaced }}
# cleanup
- name: cleanup
run: |
rm -f ${HOME}/.docker/config.json
4 changes: 2 additions & 2 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
if: startsWith(github.event.ref_type, 'branch') == true
runs-on: ubuntu-latest
steps:
- name: Sanitize branch docker tag
- name: docker tag
uses: frabert/replace-string-action@master
id: dockertag
with:
Expand All @@ -16,7 +16,7 @@ jobs:
replace-with: '-'
flags: 'g'

- name: Remove branch docker tag
- name: remove docker tag
shell: bash
env:
username: ${{ secrets.DOCKER_USERNAME }}
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/test.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .golangci.yml

This file was deleted.

33 changes: 8 additions & 25 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,33 @@
# https://goreleaser.com
project_name: autoscan
env:
- GO111MODULE=on
- CGO_ENABLED=1

# Build
builds:
- id: build_darwin
-
env:
- CC=o64-clang
- CXX=o64-clang++
main: ./cmd/autoscan
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
ldflags:
- -s -w
- -X "main.Version={{ .Version }}"
- -X "main.GitCommit={{ .ShortCommit }}"
- -X "main.Timestamp={{ .Timestamp }}"
flags:
- -trimpath

- id: build_linux
main: ./cmd/autoscan
goos:
- linux
goarch:
- amd64
- arm64
- arm
goarm:
- 7
ldflags:
- -linkmode external
- -extldflags -static
- -s -w
- -X "main.Version={{ .Version }}"
- -X "main.GitCommit={{ .ShortCommit }}"
- -X "main.Timestamp={{ .Timestamp }}"
flags:
- -trimpath
- -tags=netgo
- -v

# Archive
archives:
-
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}"
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
format: "binary"

# Checksum
Expand Down
41 changes: 20 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ TARGET := $(shell go env GOOS)_$(shell go env GOARCH)
DIST_PATH := dist
BUILD_PATH := ${DIST_PATH}/${CMD}_${TARGET}
GO_FILES := $(shell find . -path ./vendor -prune -or -type f -name '*.go' -print)
HTML_FILES := $(shell find . -path ./vendor -prune -or -type f -name '*.html' -print)
SQL_FILES := $(shell find . -path ./vendor -prune -or -type f -name '*.sql' -print)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
TIMESTAMP := $(shell date +%s)
VERSION ?= 0.0.0-dev
CGO := 1
CGO := 0

# Deps
.PHONY: check_goreleaser
check_goreleaser:
@command -v goreleaser >/dev/null || (echo "goreleaser is required."; exit 1)

.PHONY: test
test: ## Run tests
go test ./... -cover -v -race ${GO_PACKAGES}

.PHONY: vendor
vendor: ## Vendor files and tidy go.mod
go mod vendor
Expand All @@ -24,7 +34,7 @@ vendor_update: ## Update vendor dependencies
build: vendor ${BUILD_PATH}/${CMD} ## Build application

# Binary
${BUILD_PATH}/${CMD}: ${GO_FILES} go.sum
${BUILD_PATH}/${CMD}: ${GO_FILES} ${HTML_FILES} ${SQL_FILES} go.sum
@echo "Building for ${TARGET}..." && \
mkdir -p ${BUILD_PATH} && \
CGO_ENABLED=${CGO} go build \
Expand All @@ -34,25 +44,14 @@ ${BUILD_PATH}/${CMD}: ${GO_FILES} go.sum
-o ${BUILD_PATH}/${CMD} \
./cmd/autoscan

.PHONY: release
release: check_goreleaser ## Generate a release, but don't publish
goreleaser --skip-validate --skip-publish --rm-dist

.PHONY: publish
publish: ## Generate a release, and publish
docker run --rm --privileged \
-e GITHUB_TOKEN="${TOKEN}" \
-e VERSION="${GIT_TAG_NAME}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/Cloudbox/autoscan \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/Cloudbox/autoscan \
neilotoole/xcgo:latest goreleaser --rm-dist
publish: check_goreleaser ## Generate a release, and publish
goreleaser --rm-dist

.PHONY: snapshot
snapshot: ## Generate a snapshot release
docker run --rm --privileged \
-e VERSION="${VERSION}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/Cloudbox/autoscan \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/Cloudbox/autoscan \
neilotoole/xcgo:latest goreleaser --snapshot --skip-validate --skip-publish --rm-dist
snapshot: check_goreleaser ## Generate a snapshot release
goreleaser --snapshot --skip-publish --rm-dist
Loading

0 comments on commit 8118c89

Please sign in to comment.