Skip to content

Commit

Permalink
- Tag pushed docker images with release tag
Browse files Browse the repository at this point in the history
- Enable headless functions with env SCRAPE_ENABLE_HEADLESS
  • Loading branch information
efixler committed Apr 6, 2024
1 parent 52f3591 commit 303f699
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
24 changes: 11 additions & 13 deletions Makefile
Expand Up @@ -4,14 +4,8 @@ CWD := $(shell pwd)
BUILD_DIR := build
SCRAPE_PORT ?= 8080
TAG_VERSION ?= v0.0.0
TAG_MESSAGE ?= "Release version $(TAG_VERSION)"
define GITHUB_ORG_USER
$(shell git remote get-url origin | sed -n 's/.*github.com[:/]\([^/]*\)\/.*/\1/p' | tr '[:upper:]' '[:lower:]')
endef
CONTAINER_REGISTRY ?= docker.io
define PUSH_TAG
$(CONTAINER_REGISTRY)/$(GITHUB_ORG_USER)/$(DOCKER_IMAGE_NAME):latest
endef


.DEFAULT_GOAL := build

Expand All @@ -30,8 +24,7 @@ docker-build: ## build a docker image on the current platform, for local use
@echo "Building $(DOCKER_IMAGE_NAME)..."
@docker build -t $(DOCKER_IMAGE_NAME) .

docker-push: ## push an amd64/arm64 docker to Docker Hub or to a registry specified by CONTAINER_REGISTRY
@echo "Pushing '$(PUSH_TAG)'..."
docker-push: push-tag ## push an amd64/arm64 docker to Docker Hub or to a registry specified by CONTAINER_REGISTRY
@read -p "Do you want to push an amd64/arm64 image to '$(PUSH_TAG)'? (y/N) " answer; \
if [ "$$answer" != "y" ]; then \
echo "Aborted."; \
Expand All @@ -41,6 +34,10 @@ docker-push: ## push an amd64/arm64 docker to Docker Hub or to a registry specif
@docker buildx create --use
@docker buildx build --push --platform linux/amd64,linux/arm64 -t $(PUSH_TAG) .

push-tag: latest-release-tag
$(eval GITHUB_ORG := $(shell git remote get-url origin | sed -n 's/.*github.com[:/]\([^/]*\)\/.*/\1/p' | tr '[:upper:]' '[:lower:]'))
$(eval PUSH_TAG=$(CONTAINER_REGISTRY)/$(GITHUB_ORG)/$(DOCKER_IMAGE_NAME):$(RELEASE_TAG))

docker-run: ## run the local docker image, binding to port 8080, or the env value of SCRAPE_PORT
@echo "Running $(DOCKER_IMAGE_NAME)..."
@docker run -d -ti -p 127.0.0.1:$(SCRAPE_PORT):8080 --volume=$(CWD)/docker/data:/scrape_data --rm scrape-bookworm-slim:latest
Expand All @@ -49,8 +46,9 @@ fmt:
@echo "Running go fmt..."
@go fmt ./...

release-tag: latest-tag ## create a release tag with TAG_VERSION and TAG_MESSAGE
@echo "Creating release tag $(TAG_VERSION) with message: $(TAG_MESSAGE) (latest tag: $(TAG))..."
release-tag: latest-release-tag ## create a release tag with TAG_VERSION and TAG_MESSAGE
$(eval TAG_MESSAGE ?= "Release version $(TAG_VERSION)")
@echo "Creating release tag $(TAG_VERSION) with message: $(TAG_MESSAGE) (latest tag: $(RELEASE_TAG))..."
@if [ "$(TAG_VERSION)" = "v0.0.0" ]; then \
echo "Aborted. Release version cannot be 'v0.0.0'."; \
exit 1; \
Expand All @@ -63,8 +61,8 @@ release-tag: latest-tag ## create a release tag with TAG_VERSION and TAG_MESSAGE
@git tag -a $(TAG_VERSION) -m $(TAG_MESSAGE)
@git push origin $(TAG_VERSION)

latest-tag:
$(eval TAG := $(shell git describe --abbrev=0 --tags $(shell git rev-list --tags --max-count=1)))
latest-release-tag:
$(eval RELEASE_TAG := $(shell git describe --abbrev=0 --tags $(shell git rev-list --tags --max-count=1)))

test: ## run the tests
@echo "Running tests..."
Expand Down
9 changes: 5 additions & 4 deletions cmd/scrape-server/main.go
Expand Up @@ -31,7 +31,7 @@ var (
ttl *envflags.Value[time.Duration]
userAgent *envflags.Value[*ua.UserAgent]
dbFlags *cmd.DatabaseFlags
headlessEnabled bool
headlessEnabled *envflags.Value[bool]
profile *envflags.Value[bool]
logWriter io.Writer
)
Expand All @@ -45,7 +45,7 @@ func main() {
normalClient := fetch.MustClient(fetch.WithUserAgent(userAgent.Get().String()))
defaultFetcherFactory := trafilatura.Factory(normalClient)
var headlessFetcher fetch.URLFetcher = nil
if headlessEnabled {
if headlessEnabled.Get() {
headlessClient := headless.MustChromeClient(ctx, userAgent.Get().String(), 6)
headlessFetcher, _ = trafilatura.Factory(headlessClient)()
}
Expand All @@ -69,7 +69,7 @@ func main() {
Addr: fmt.Sprintf(":%d", port.Get()),
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 60 * time.Second, // some feed/batch requests can be slow to complete
WriteTimeout: 120 * time.Second, // some feed/batch requests can be slow to complete
IdleTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 16,
}
Expand All @@ -94,7 +94,8 @@ func init() {
flags.Usage = usage
dbFlags = cmd.AddDatabaseFlags("DB", &flags, false)

flags.BoolVar(&headlessEnabled, "headless", false, "Enable headless browser extraction functionality")
headlessEnabled = envflags.NewBool("ENABLE_HEADLESS", false)
headlessEnabled.AddTo(&flags, "enable-headless", "Enable headless browser extraction functionality")

port = envflags.NewInt("PORT", DefaultPort)
port.AddTo(&flags, "port", "Port to run the server on")
Expand Down

0 comments on commit 303f699

Please sign in to comment.