diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b55e971 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index ecdb244..4cedfca 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -4,13 +4,13 @@ import ( "errors" "log" - pkgwatcher "gitea.urkob.com/urko/git-webhook-ci/pkg/watcher" + "gitea.urkob.com/urko/git-webhook-ci/pkg" "github.com/fsnotify/fsnotify" ) type watcher struct { fswatcher *fsnotify.Watcher - deploy pkgwatcher.DeployFunc + deploy pkg.DeployFunc } type notifier struct{} @@ -28,7 +28,7 @@ var ( 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() if err != nil { log.Printf("fsnotify.NewWatcher: %s\n", err) diff --git a/internal/watcher/watcher_test.go b/internal/watcher/watcher_test.go index f3b2bbd..825d954 100644 --- a/internal/watcher/watcher_test.go +++ b/internal/watcher/watcher_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "gitea.urkob.com/urko/git-webhook-ci/cfg" - 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" "github.com/fsnotify/fsnotify" "github.com/stretchr/testify/require" ) @@ -26,8 +26,8 @@ var ( ) var ( - mockDeploy pkgwatcher.DeployFunc - mockErrorDeploy pkgwatcher.DeployFunc + mockDeploy pkg.DeployFunc + mockErrorDeploy pkg.DeployFunc errIntentional = errors.New("intentional error") binaryPath = "" scriptPath = "" diff --git a/cfg/config.go b/kit/cfg/config.go similarity index 100% rename from cfg/config.go rename to kit/cfg/config.go diff --git a/main.go b/main.go index 3bb62b7..e1a22f5 100644 --- a/main.go +++ b/main.go @@ -7,14 +7,14 @@ import ( "os/signal" "syscall" - "gitea.urkob.com/urko/git-webhook-ci/cfg" "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 ( - watcherIface pkgwatcher.WatcherIface - notifierIface pkgwatcher.NotifyIface + watcherIface pkg.WatcherIface + notifierIface pkg.NotifyIface ) func main() { @@ -27,7 +27,7 @@ func main() { config := cfg.NewConfig(envFilePath) notifierIface = watcher.NewNotifier() - watcherIface = watcher.NewWatcher(notifierIface, pkgwatcher.Deploy) + watcherIface = watcher.NewWatcher(notifierIface, pkg.Deploy) defer func() { if err := watcherIface.Close(); err != nil { diff --git a/pkg/watcher/watcher.go b/pkg/watcher.go similarity index 97% rename from pkg/watcher/watcher.go rename to pkg/watcher.go index 64f4698..26e8d79 100644 --- a/pkg/watcher/watcher.go +++ b/pkg/watcher.go @@ -1,4 +1,4 @@ -package watcher +package pkg import ( "fmt" diff --git a/pkg/watcher/watcher_test.go b/pkg/watcher_test.go similarity index 89% rename from pkg/watcher/watcher_test.go rename to pkg/watcher_test.go index 238aa18..a695b19 100644 --- a/pkg/watcher/watcher_test.go +++ b/pkg/watcher_test.go @@ -1,9 +1,9 @@ -package watcher +package pkg import ( "testing" - "gitea.urkob.com/urko/git-webhook-ci/cfg" + "gitea.urkob.com/urko/git-webhook-ci/kit/cfg" "github.com/stretchr/testify/require" )