docker
This commit is contained in:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
.env
|
||||||
|
.git/
|
||||||
|
docker-compose.yml
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
tmp/
|
||||||
|
.air.toml
|
||||||
|
aparserserver/
|
||||||
|
.vscode
|
25
Dockerfile
Normal file
25
Dockerfile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
FROM registry.home.4it.me/golang:1.21 as builder
|
||||||
|
|
||||||
|
LABEL maintainer="dilap54 <dilap54@mail.ru>"
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN make build
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
WORKDIR /app/
|
||||||
|
|
||||||
|
COPY migrations ./migrations
|
||||||
|
COPY ./categories.json ./
|
||||||
|
COPY --from=builder /app/cli ./
|
||||||
|
|
||||||
|
ENTRYPOINT [ "./cli" ]
|
10
Makefile
Normal file
10
Makefile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
docker build . -t registry.home.4it.me/dilap54/platiparser
|
||||||
|
|
||||||
|
docker-push:
|
||||||
|
docker push registry.home.4it.me/dilap54/platiparser
|
||||||
|
|
||||||
|
build:
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o cli ./cmd/cli/
|
@ -11,40 +11,45 @@ import (
|
|||||||
|
|
||||||
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
||||||
"gitea.home.4it.me/dilap54/platiparser/plati"
|
"gitea.home.4it.me/dilap54/platiparser/plati"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
godotenv.Load(".env")
|
commands = append(commands, platiCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
var platiCommand = &cli.Command{
|
||||||
categories := openCategories("./categories.json").Content
|
Name: "plati",
|
||||||
categories = filterBySubstring("Gift", categories)
|
Action: func(c *cli.Context) error {
|
||||||
|
categories := openCategories("./categories.json").Content
|
||||||
|
categories = filterBySubstring("Gift", categories)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
db := gorm.GetDB()
|
db := gorm.GetDB()
|
||||||
platiCli := plati.New()
|
platiCli := plati.New()
|
||||||
|
|
||||||
// printNames(categories)
|
// printNames(categories)
|
||||||
|
|
||||||
for i, c := range categories {
|
for i, c := range categories {
|
||||||
log.Printf("fetching goods [%d/%d] for %s\n", i, len(categories), c.FlatName)
|
log.Printf("fetching goods [%d/%d] for %s\n", i, len(categories), c.FlatName)
|
||||||
goods, err := platiCli.GetBlockGoodsCategory(ctx, c.ID, c.ParentID, "cntSellDESC", 1, 100, "RUR", "ru-RU")
|
goods, err := platiCli.GetBlockGoodsCategory(ctx, c.ID, c.ParentID, "cntSellDESC", 1, 100, "RUR", "ru-RU")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return fmt.Errorf("getblockgoodscategory: %w", err)
|
||||||
|
}
|
||||||
|
if len(goods) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
gormGoods := convertGoodsToGorm(c, goods)
|
||||||
|
if err := db.Create(gormGoods).Error; err != nil {
|
||||||
|
return fmt.Errorf("db Create: %w", err)
|
||||||
|
}
|
||||||
|
json.NewEncoder(os.Stdout).Encode(goods)
|
||||||
}
|
}
|
||||||
if len(goods) == 0 {
|
|
||||||
continue
|
return nil
|
||||||
}
|
},
|
||||||
gormGoods := convertGoodsToGorm(c, goods)
|
|
||||||
if err := db.Create(gormGoods).Error; err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
json.NewEncoder(os.Stdout).Encode(goods)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertGoodsToGorm(cat *plati.Category, goods []*plati.Good) []*gorm.Good {
|
func convertGoodsToGorm(cat *plati.Category, goods []*plati.Good) []*gorm.Good {
|
Reference in New Issue
Block a user