Skip to content

Commit

Permalink
Feature: Implement Graceful shutdown (#21)
Browse files Browse the repository at this point in the history
* docs: Added more documentation to functions and objects in the project

* fix: Repaired dockerfile and added commands in Makefile to build/push image with specified IMAGE_NAME variable

* feat: Added Taskfile for the owner to compare it with Makefile

* fix: Removed redundant clock package, changed all calls to time.Now()

* Completely removed clock package

* refactor: Adding more descriptive error messages, and renaming vars

* Made visualizer and proxy server ports as flags, to allow user specify different ports

* Handling errors during certificate loading.

* Fix: removed redundant commans at the end of line.

* Handlded error in proxy/main.go

* Implemented graceful shutdown in collector and proxy

* Implemented graceful shutdown in server/server.go

* fix: Fixed CI/CD

* fix: Repaired github action, and building docker image instead of project, since it can be later pushed

* fix: Commented unused code

* Running tests only in internal package instead of ./...

* fix: Running tests in every folder in internal pkg

* fix: Repairing Github Pipeline; Added pcap installation

* fix: Repairing Github Pipeline; Added sudo to pcap install

* Testing everything in waffle folder, since pcap error is resolved.

* changed username in docker image to YOUR_USERNAME

* Removed unused packages from project.

* Repaired taskfile and added description to all tasks

* fix: Building application binary instead of docker, since we should login in registry then

* fixed task name from dockerBuild to build

* fix: Changed output path in build task

* Changed flag name to avoid duplication and added better logging.
  • Loading branch information
werniq authored Oct 30, 2024
1 parent d2fe271 commit 0df4ec6
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 1,989 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ jobs:
with:
go-version: '1.22'

- name: Build
run: go build -v ./...
- name: Install pcap deps
run: sudo apt install -y libpcap-dev

- name: Test
- name: Download go.mod dependencies
run: go mod download

- name: Test waffle WAF
run: go test -v ./...

- name: Install go-task to build docker image
run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin

- name: Build Waffle using Golang
run: task build
21 changes: 17 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
version: '3'

env:
IMAGE_NAME: '{{ .IMAGE_NAME | default "<YOUR-USERNAME>/<IMAGE-NAME>:<IMAGE-TAG>" }}'

tasks:
certs_windows:
desc: "Generate SSL certificates for Windows environment using OpenSSL, including CA and server certificates."
cmds:
- mkdir -p "./cmd/proxy/.cert"
- openssl ecparam -out ./cmd/proxy/.cert/ca.key -name prime256v1 -genkey
Expand All @@ -13,6 +17,7 @@ tasks:
- openssl x509 -in ./cmd/proxy/.cert/server.crt -text -noout

certs:
desc: "Generate SSL certificates for non-Windows environments using OpenSSL, including CA and server certificates."
cmds:
- mkdir -p "./cmd/proxy/.cert"
- openssl ecparam -out ./cmd/proxy/.cert/ca.key -name prime256v1 -genkey
Expand All @@ -24,13 +29,21 @@ tasks:
- openssl x509 -in ./cmd/proxy/.cert/server.crt -text -noout

mocks:
desc: "Generate mock implementations for testing using Mockery."
cmds:
- mockery

docker-build:
build:
desc: "Build a project using Golang"
cmds:
- go build -o ./out/app ./cmd/proxy

dockerBuild:
desc: "Build a Docker image using the specified Dockerfile and tag it with the provided image name."
cmds:
- docker build -t ${IMAGE_NAME} -f .\build\Dockerfile .
- docker build -t {{ .IMAGE_NAME }} -f .\build\Dockerfile .

docker-push:
dockerPush:
desc: "Push the Docker image to the remote registry with the specified image name."
cmds:
- docker push ${IMAGE_NAME}
- docker push {{ .IMAGE_NAME }}
5 changes: 3 additions & 2 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
visualizeServerPort string
proxyServerPort string
)
flag.StringVar(&visualizeServerPort, "p", "8081", "Port for server to listen on")
flag.StringVar(&visualizeServerPort, "vp", "8080", "Port for visualizer server to listen on")
flag.StringVar(&proxyServerPort, "p", "8081", "Port for server to listen on")

quit := make(chan os.Signal)
Expand All @@ -37,7 +37,8 @@ func main() {
}
}()

log.Println("Server started on :8080")
log.Println("Visualizer server started on ", visualizeServerPort)
log.Println("Proxy server started on ", proxyServerPort)

<-quit
log.Println("Shutdown signal received, shutting down gracefully...")
Expand Down
81 changes: 0 additions & 81 deletions internal/rule/compiler.go

This file was deleted.

96 changes: 0 additions & 96 deletions internal/rule/compiler_test.go

This file was deleted.

44 changes: 0 additions & 44 deletions internal/rule/expression_tree.go

This file was deleted.

Loading

0 comments on commit 0df4ec6

Please sign in to comment.