-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ab9c0a
commit bb0d39e
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"webCrawler/config" | ||
) | ||
|
||
func main() { | ||
// Define command-line flags | ||
urlFlag := flag.String("url", "", "The URL to crawl") | ||
flag.Parse() | ||
|
||
if *urlFlag == "" { | ||
log.Fatal("URL flag is required") | ||
} | ||
|
||
webcrawlerHost, exists := os.LookupEnv("WEBCRAWLER_HOST") | ||
if !exists { | ||
fmt.Println("WEBCRAWLER_HOST is not set") | ||
fmt.Println("Using local host as webcrawler host") | ||
webcrawlerHost = "localhost" | ||
} | ||
webcrawlerPort, exists := os.LookupEnv("WEBCRAWLER_PORT") | ||
if !exists { | ||
fmt.Println("WEBCRAWLER_PORT is not set") | ||
fmt.Println("Using default webcrawler port ", config.Port) | ||
webcrawlerPort = config.Port | ||
} | ||
|
||
// Define the web crawler service endpoint | ||
endpoint := "http://" + webcrawlerHost + ":" + webcrawlerPort + config.WebCrawlerEndpoint | ||
|
||
// Create the request to start crawling | ||
resp, err := http.Get(endpoint + "?url=" + *urlFlag) | ||
if err != nil { | ||
log.Fatalf("Failed to send request: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Read and display the response | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatalf("Failed to read response: %v", err) | ||
} | ||
|
||
fmt.Println("Crawl Result:") | ||
fmt.Println(string(body)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.23-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN go mod download && go build -o webcrawler-client ./cmd/webcrawler-client | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /root/ | ||
|
||
COPY --from=builder /app/webcrawler-client . | ||
|
||
CMD ["./webcrawler-client"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Use the official Golang image to build the web crawler | ||
FROM golang:1.23-alpine AS builder | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the source code into the container | ||
COPY . . | ||
|
||
# Download the Go Modules dependencies | ||
RUN go mod download && go build -o webcrawler ./cmd/webcrawler | ||
|
||
# Start a new stage from scratch | ||
FROM alpine:latest | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /usr | ||
|
||
# Copy the Pre-built binary file from the previous stage | ||
COPY --from=builder /app/webcrawler . | ||
|
||
# Expose port 8080 to the outside world | ||
EXPOSE 8081 | ||
|
||
# Command to run the executable | ||
CMD ["./webcrawler"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: webcrawler | ||
labels: | ||
app: webcrawler | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: webcrawler | ||
template: | ||
metadata: | ||
labels: | ||
app: webcrawler | ||
spec: | ||
containers: | ||
- name: webcrawler | ||
image: ghcr.io/karan56625/webcrawler:1.0 | ||
ports: | ||
- containerPort: 8081 | ||
env: | ||
- name: NUMBER_OF_WORKER | ||
value: "10" | ||
- name: WORKER_QUEUE_LENGTH | ||
value: "20" | ||
livenessProbe: | ||
httpGet: | ||
path: /health | ||
port: 8081 | ||
initialDelaySeconds: 10 | ||
timeoutSeconds: 5 | ||
periodSeconds: 10 | ||
failureThreshold: 3 | ||
readinessProbe: | ||
httpGet: | ||
path: /readiness | ||
port: 8081 | ||
initialDelaySeconds: 10 | ||
timeoutSeconds: 5 | ||
periodSeconds: 10 | ||
failureThreshold: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: webcrawler-service | ||
spec: | ||
selector: | ||
app: webcrawler | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 8081 | ||
type: LoadBalancer |