Implement Scraper Dockerfile and Refactor CI Configuration
- Added a new Dockerfile for the scraper application located at cmd/scraper/Dockerfile to streamline the build process. - Updated the CI configuration in .drone.yml to correctly build the scraper application with the new Dockerfile. - Refactored the main application entry point to utilize a new bootstrap package for configuration, logging, and MongoDB initialization. - Enhanced the scraper's configuration management by defining a dedicated Config struct for better organization and maintainability.
This commit is contained in:
+12
-12
@@ -19,7 +19,7 @@ steps:
|
|||||||
- echo "APP Version tags $APP_VERSION"
|
- echo "APP Version tags $APP_VERSION"
|
||||||
- echo -n "$APP_VERSION" >> .tags
|
- echo -n "$APP_VERSION" >> .tags
|
||||||
|
|
||||||
- name: buid web
|
- name: build web
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
build_args:
|
build_args:
|
||||||
@@ -31,17 +31,17 @@ steps:
|
|||||||
repo: artifactory.ravanertebat.ir/tm/web
|
repo: artifactory.ravanertebat.ir/tm/web
|
||||||
registry: artifactory.ravanertebat.ir
|
registry: artifactory.ravanertebat.ir
|
||||||
|
|
||||||
# - name: buid scraper
|
- name: build scraper
|
||||||
# image: plugins/docker
|
image: plugins/docker
|
||||||
# settings:
|
settings:
|
||||||
# build_args:
|
build_args:
|
||||||
# - BUILD_APP=scraper
|
- BUILD_APP=scraper
|
||||||
# username: cicd
|
username: cicd
|
||||||
# password:
|
password:
|
||||||
# from_secret: REGISTRY_PASSWORD
|
from_secret: REGISTRY_PASSWORD
|
||||||
# dockerfile: Dockerfile-drone
|
dockerfile: ./cmd/scraper/Dockerfile
|
||||||
# repo: artifactory.ravanertebat.ir/tm/scraper
|
repo: artifactory.ravanertebat.ir/tm/scraper
|
||||||
# registry: artifactory.ravanertebat.ir
|
registry: artifactory.ravanertebat.ir
|
||||||
|
|
||||||
node:
|
node:
|
||||||
tag: aecde-docker-runner
|
tag: aecde-docker-runner
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
ARG GO_VERSION=1.23
|
||||||
|
ARG BASH_VERSION=5.0
|
||||||
|
|
||||||
|
FROM golang:${GO_VERSION} AS go-builder
|
||||||
|
|
||||||
|
WORKDIR /go/src/company/tm_back
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o scraper-build ./cmd/scraper/main.go
|
||||||
|
|
||||||
|
FROM bash:${BASH_VERSION}
|
||||||
|
RUN apk --no-cache add busybox-suid curl rsync tzdata tcpdump tree ca-certificates s-nail \
|
||||||
|
&& ln -s /usr/bin/mail /usr/bin/s-nail \
|
||||||
|
&& mkdir -p /go/bin/media /go/bin/log /go/bin/config
|
||||||
|
WORKDIR /go/bin
|
||||||
|
|
||||||
|
COPY --from=go-builder /go/src/company/tm_back/scraper-build .
|
||||||
|
|
||||||
|
EXPOSE 8090
|
||||||
|
|
||||||
|
ENTRYPOINT /go/bin/scraper-build
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -15,17 +15,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Init Application Configuration
|
// Init Application Configuration
|
||||||
func initConfig() *Config {
|
func InitConfig() (*Config, error) {
|
||||||
conf, err := config.LoadConfig(".", &Config{})
|
conf, err := config.LoadConfig(".", &Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Failed to load config: %v", err))
|
return nil, fmt.Errorf("failed to load config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Logger Service
|
// Init Logger Service
|
||||||
func initLogger(conf config.LoggingConfig) logger.Logger {
|
func InitLogger(conf config.LoggingConfig) logger.Logger {
|
||||||
return logger.NewLogger(&logger.Config{
|
return logger.NewLogger(&logger.Config{
|
||||||
Level: conf.Level,
|
Level: conf.Level,
|
||||||
Format: conf.Format,
|
Format: conf.Format,
|
||||||
@@ -41,7 +41,7 @@ func initLogger(conf config.LoggingConfig) logger.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init MongoDB Connection Manager
|
// Init MongoDB Connection Manager
|
||||||
func initMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionManager {
|
func InitMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionManager {
|
||||||
// Convert infra.MongoConfig to mongo.ConnectionConfig
|
// Convert infra.MongoConfig to mongo.ConnectionConfig
|
||||||
connectionConfig := mongo.ConnectionConfig{
|
connectionConfig := mongo.ConnectionConfig{
|
||||||
URI: conf.URI,
|
URI: conf.URI,
|
||||||
@@ -74,7 +74,7 @@ func initMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionMa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init TED scraper
|
// init TED scraper
|
||||||
func initTEDScraper(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger) {
|
func InitTEDScraper(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger) {
|
||||||
// Initialize tender repository
|
// Initialize tender repository
|
||||||
tenderRepo := tender.NewTenderRepository(mongoManager, appLogger)
|
tenderRepo := tender.NewTenderRepository(mongoManager, appLogger)
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
+6
-6
@@ -2,25 +2,25 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
"tm/cmd/scraper/bootstrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Load configuration
|
// Load configuration
|
||||||
config, err := LoadConfig(".")
|
config, err := bootstrap.InitConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load configuration: %v", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize logger
|
// Initialize logger
|
||||||
appLogger := initLogger(config.Logging)
|
appLogger := bootstrap.InitLogger(config.Logging)
|
||||||
appLogger.Info("Starting TED scraper application", map[string]interface{}{
|
appLogger.Info("Starting TED scraper application", map[string]interface{}{
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
})
|
})
|
||||||
|
|
||||||
// Initialize MongoDB connection
|
// Initialize MongoDB connection
|
||||||
mongoManager := initMongoDB(config.Database.MongoDB, appLogger)
|
mongoManager := bootstrap.InitMongoDB(config.Database.MongoDB, appLogger)
|
||||||
defer func() {
|
defer func() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -31,7 +31,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
initTEDScraper(*config, mongoManager, appLogger)
|
bootstrap.InitTEDScraper(*config, mongoManager, appLogger)
|
||||||
|
|
||||||
appLogger.Info("TED scraper application stopped", map[string]interface{}{})
|
appLogger.Info("TED scraper application stopped", map[string]interface{}{})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user