wip
This commit is contained in:
parent
f2ef06ca81
commit
73a654bfaa
9 changed files with 57 additions and 26 deletions
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
|||
.git
|
||||
app.db
|
||||
uploads
|
|
@ -1,15 +1,15 @@
|
|||
# Первый этап: сборка приложения
|
||||
FROM golang:latest AS builder
|
||||
|
||||
WORKDIR /rest-app
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go build -o alt-storage
|
||||
RUN go build -o aides-repo-api ./cmd/aides-repo-api/main.go
|
||||
|
||||
# Второй этап: создание финального образа
|
||||
FROM registry.altlinux.org/alt/alt:sisyphus
|
||||
|
||||
COPY --from=builder /rest-app/alt-storage /bin/main
|
||||
ENTRYPOINT ["/bin/main"]
|
||||
COPY --from=builder /app/aides-repo-api /bin/aides-repo-api
|
||||
ENTRYPOINT ["/bin/aides-repo-api"]
|
5
go.mod
5
go.mod
|
@ -10,9 +10,14 @@ require (
|
|||
|
||||
require (
|
||||
github.com/ajg/form v1.5.1 // indirect
|
||||
github.com/go-co-op/gocron/v2 v2.13.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/jonboulle/clockwork v0.4.0 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.24 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
gorm.io/driver/sqlite v1.5.7 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
|
|
10
go.sum
10
go.sum
|
@ -6,12 +6,22 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
|||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||
github.com/go-co-op/gocron/v2 v2.13.0 h1:iGU/RoZvf4GF5hIZUkDSFvvajk9K3W4YgocarBol/ME=
|
||||
github.com/go-co-op/gocron/v2 v2.13.0/go.mod h1:ZF70ZwEqz0OO4RBXE1sNxnANy/zvwLcattWEFsqpKig=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
|
||||
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
|
||||
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
type TaskUploadResponse struct {
|
||||
TaskID string `json:"taskID"`
|
||||
Repo string `json:"repo"`
|
||||
StatusText string `json:"status"`
|
||||
}
|
||||
|
||||
|
@ -39,15 +38,6 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
repo := r.FormValue("repo")
|
||||
if repo == "" {
|
||||
render.Render(w, r, &errors.ErrResponse{
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
StatusText: "Missing required repo field",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
files := r.MultipartForm.File["files"]
|
||||
for _, fileHeader := range files {
|
||||
if fileHeader.Size > (1024 << 20) { // Limit each file size to 10MB
|
||||
|
@ -61,7 +51,6 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = c.taskService.Upload(&taskservice.TaskUploadInput{
|
||||
TaskID: taskID,
|
||||
Repo: repo,
|
||||
Files: files,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -76,7 +65,6 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response := TaskUploadResponse{
|
||||
TaskID: taskID,
|
||||
Repo: repo,
|
||||
StatusText: "Success!",
|
||||
}
|
||||
|
||||
|
|
|
@ -101,8 +101,6 @@ func (s *Service) ForceUpdate() {
|
|||
}
|
||||
|
||||
for _, el := range tasks {
|
||||
fmt.Println(el.Files)
|
||||
|
||||
taskPath := path.Join(
|
||||
s.app.Config.UploadDir, "tasks", strconv.FormatUint(uint64(el.ID), 10),
|
||||
)
|
||||
|
@ -131,4 +129,26 @@ func (s *Service) ForceUpdate() {
|
|||
Update(
|
||||
"current_task_id", gorm.Expr("last_task_id"),
|
||||
)
|
||||
|
||||
os.MkdirAll(path.Join(s.app.Config.UploadDir, "repo"), os.ModePerm)
|
||||
|
||||
aPath := path.Join(s.app.Config.UploadDir, "future_repo", "Sisyphus")
|
||||
bPath := path.Join(s.app.Config.UploadDir, "repo", "Sisyphus")
|
||||
cPath := path.Join(s.app.Config.UploadDir, "repo", ".Sisyphus")
|
||||
|
||||
if _, err := os.Stat(bPath); err == nil {
|
||||
fmt.Printf("Moving %s to %s\n", bPath, cPath)
|
||||
if err := os.Rename(bPath, cPath); err != nil {
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
|
||||
}
|
||||
|
||||
if err := os.Rename(aPath, bPath); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(cPath); err != nil {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
package taskservice
|
||||
|
||||
import "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
import (
|
||||
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/models"
|
||||
)
|
||||
|
||||
func (s *Service) Create(repo string) (*models.Task, error) {
|
||||
taskRepo := models.GitRepo{
|
||||
Name: repo,
|
||||
}
|
||||
s.app.Db.FirstOrCreate(&taskRepo)
|
||||
s.app.Db.Debug().
|
||||
Where(&taskRepo).
|
||||
FirstOrCreate(&taskRepo)
|
||||
|
||||
altRepo := models.ALTRepo{
|
||||
Name: "Sisyphus",
|
||||
}
|
||||
s.app.Db.FirstOrCreate(&altRepo)
|
||||
s.app.Db.
|
||||
Where(&altRepo).
|
||||
FirstOrCreate(&altRepo)
|
||||
|
||||
task := models.Task{
|
||||
RepoID: taskRepo.ID,
|
||||
|
|
|
@ -26,11 +26,11 @@ func (s *Service) onTaskComplete(task *models.Task) error {
|
|||
|
||||
grart := models.GitRepoAltRepoTask{
|
||||
ALTRepoID: 1,
|
||||
Repo: task.Repo,
|
||||
RepoID: task.RepoID,
|
||||
}
|
||||
s.app.Db.Debug().Where(
|
||||
&grart,
|
||||
).FirstOrCreate(&grart)
|
||||
s.app.Db.Debug().
|
||||
Where(&grart).
|
||||
FirstOrCreate(&grart)
|
||||
|
||||
grart.LastTaskID = task.ID
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
type TaskUploadInput struct {
|
||||
TaskID string
|
||||
Repo string
|
||||
|
||||
Files []*multipart.FileHeader
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue