refactor: project structure

This commit is contained in:
Urko. 2024-04-29 21:29:05 +02:00
parent 2abed91918
commit 727b083e52
7 changed files with 45 additions and 15 deletions

30
Dockerfile Normal file
View File

@ -0,0 +1,30 @@
FROM golang:1.22 as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY internal ./internal
COPY pk ./pk
ARG PORT
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/webhook-ci /app/main.go
FROM alpine:3.15
# Install ca-certificates, ffmpeg (which includes ffprobe), Python, and yt-dlp
RUN apk --no-cache add ca-certificates ffmpeg python3 py3-pip \
&& python3 -m venv /opt/venv \
&& source /opt/venv/bin/activate \
&& pip install --no-cache-dir yt-dlp
ENV PATH="/opt/venv/bin:$PATH"
COPY --from=builder /app/banana-byte /app/banana-byte
COPY --from=builder /app/web /app/web
ENV VIEWS_DIR="/app/web"
EXPOSE $PORT
CMD ["/app/banana-byte"]

View File

@ -4,13 +4,13 @@ import (
"errors" "errors"
"log" "log"
pkgwatcher "gitea.urkob.com/urko/git-webhook-ci/pkg/watcher" "gitea.urkob.com/urko/git-webhook-ci/pkg"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
type watcher struct { type watcher struct {
fswatcher *fsnotify.Watcher fswatcher *fsnotify.Watcher
deploy pkgwatcher.DeployFunc deploy pkg.DeployFunc
} }
type notifier struct{} type notifier struct{}
@ -28,7 +28,7 @@ var (
errErrorsClosedChan = errors.New("errors is closed") errErrorsClosedChan = errors.New("errors is closed")
) )
func NewWatcher(notifier pkgwatcher.NotifyIface, deploy pkgwatcher.DeployFunc) *watcher { func NewWatcher(notifier pkg.NotifyIface, deploy pkg.DeployFunc) *watcher {
wt, err := notifier.NewWatcher() wt, err := notifier.NewWatcher()
if err != nil { if err != nil {
log.Printf("fsnotify.NewWatcher: %s\n", err) log.Printf("fsnotify.NewWatcher: %s\n", err)

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"time" "time"
"gitea.urkob.com/urko/git-webhook-ci/cfg" "gitea.urkob.com/urko/git-webhook-ci/kit/cfg"
pkgwatcher "gitea.urkob.com/urko/git-webhook-ci/pkg/watcher" "gitea.urkob.com/urko/git-webhook-ci/pkg"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -26,8 +26,8 @@ var (
) )
var ( var (
mockDeploy pkgwatcher.DeployFunc mockDeploy pkg.DeployFunc
mockErrorDeploy pkgwatcher.DeployFunc mockErrorDeploy pkg.DeployFunc
errIntentional = errors.New("intentional error") errIntentional = errors.New("intentional error")
binaryPath = "" binaryPath = ""
scriptPath = "" scriptPath = ""

10
main.go
View File

@ -7,14 +7,14 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"gitea.urkob.com/urko/git-webhook-ci/cfg"
"gitea.urkob.com/urko/git-webhook-ci/internal/watcher" "gitea.urkob.com/urko/git-webhook-ci/internal/watcher"
pkgwatcher "gitea.urkob.com/urko/git-webhook-ci/pkg/watcher" "gitea.urkob.com/urko/git-webhook-ci/kit/cfg"
"gitea.urkob.com/urko/git-webhook-ci/pkg"
) )
var ( var (
watcherIface pkgwatcher.WatcherIface watcherIface pkg.WatcherIface
notifierIface pkgwatcher.NotifyIface notifierIface pkg.NotifyIface
) )
func main() { func main() {
@ -27,7 +27,7 @@ func main() {
config := cfg.NewConfig(envFilePath) config := cfg.NewConfig(envFilePath)
notifierIface = watcher.NewNotifier() notifierIface = watcher.NewNotifier()
watcherIface = watcher.NewWatcher(notifierIface, pkgwatcher.Deploy) watcherIface = watcher.NewWatcher(notifierIface, pkg.Deploy)
defer func() { defer func() {
if err := watcherIface.Close(); err != nil { if err := watcherIface.Close(); err != nil {

View File

@ -1,4 +1,4 @@
package watcher package pkg
import ( import (
"fmt" "fmt"

View File

@ -1,9 +1,9 @@
package watcher package pkg
import ( import (
"testing" "testing"
"gitea.urkob.com/urko/git-webhook-ci/cfg" "gitea.urkob.com/urko/git-webhook-ci/kit/cfg"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )